From 3b4f3d0d46dd278fbe4ffa68b1b6e14e3ea3b17f Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Thu, 17 Mar 2022 22:26:19 +0100 Subject: [PATCH] build: Reject C++ compilers in the preprocessor --- .cirrus.yml | 7 +++---- src/secp256k1.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 271cbe5f..94d1811b 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -312,10 +312,9 @@ task: name: "C++ -fpermissive" << : *LINUX_CONTAINER env: - # ./configure correctly errors out when given CC=g++. - # We hack around this by passing CC=g++ only to make. - CC: gcc - MAKEFLAGS: -j4 CC=g++ CFLAGS=-fpermissive\ -g + CC: g++ + CFLAGS: -fpermissive -g + CPPFLAGS: -DSECP256K1_CPLUSPLUS_TEST_OVERRIDE WERROR_CFLAGS: EXPERIMENTAL: yes ECDH: yes diff --git a/src/secp256k1.c b/src/secp256k1.c index 8f34c352..96102d36 100644 --- a/src/secp256k1.c +++ b/src/secp256k1.c @@ -4,6 +4,17 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ +/* This is a C project. It should not be compiled with a C++ compiler, + * and we error out if we detect one. + * + * We still want to be able to test the project with a C++ compiler + * because it is still good to know if this will lead to real trouble, so + * there is a possibility to override the check. But be warned that + * compiling with a C++ compiler is not supported. */ +#if defined(__cplusplus) && !defined(SECP256K1_CPLUSPLUS_TEST_OVERRIDE) +#error Trying to compile a C project with a C++ compiler. +#endif + #define SECP256K1_BUILD #include "../include/secp256k1.h"