Skip to content

Commit 3b4f3d0

Browse files
build: Reject C++ compilers in the preprocessor
1 parent 1cc0941 commit 3b4f3d0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.cirrus.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,9 @@ task:
312312
name: "C++ -fpermissive"
313313
<< : *LINUX_CONTAINER
314314
env:
315-
# ./configure correctly errors out when given CC=g++.
316-
# We hack around this by passing CC=g++ only to make.
317-
CC: gcc
318-
MAKEFLAGS: -j4 CC=g++ CFLAGS=-fpermissive\ -g
315+
CC: g++
316+
CFLAGS: -fpermissive -g
317+
CPPFLAGS: -DSECP256K1_CPLUSPLUS_TEST_OVERRIDE
319318
WERROR_CFLAGS:
320319
EXPERIMENTAL: yes
321320
ECDH: yes

src/secp256k1.c

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
66

7+
/* This is a C project. It should not be compiled with a C++ compiler,
8+
* and we error out if we detect one.
9+
*
10+
* We still want to be able to test the project with a C++ compiler
11+
* because it is still good to know if this will lead to real trouble, so
12+
* there is a possibility to override the check. But be warned that
13+
* compiling with a C++ compiler is not supported. */
14+
#if defined(__cplusplus) && !defined(SECP256K1_CPLUSPLUS_TEST_OVERRIDE)
15+
#error Trying to compile a C project with a C++ compiler.
16+
#endif
17+
718
#define SECP256K1_BUILD
819

920
#include "../include/secp256k1.h"

0 commit comments

Comments
 (0)