From c5d2f11e2e94a5439cb5e7f788e5e55f43c77e65 Mon Sep 17 00:00:00 2001 From: Virgile Prevosto <virgile.prevosto@m4x.org> Date: Fri, 5 Mar 2021 16:42:49 +0100 Subject: [PATCH] [libc] ensure bool, true and false are not macros when in C++ mode --- share/libc/stdbool.h | 3 +++ tests/libc/oracle/stdbool_as_cpp.res.oracle | 10 ++++++++++ tests/libc/stdbool_as_cpp.c | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/libc/oracle/stdbool_as_cpp.res.oracle create mode 100644 tests/libc/stdbool_as_cpp.c diff --git a/share/libc/stdbool.h b/share/libc/stdbool.h index c7eee3eeab2..3ff8ac91166 100644 --- a/share/libc/stdbool.h +++ b/share/libc/stdbool.h @@ -22,8 +22,11 @@ #ifndef __FC_STDBOOL #define __FC_STDBOOL +// In C++, bool, true and false are native values +#ifndef __cplusplus #define bool _Bool #define true 1 #define false 0 +#endif #define __bool_true_false_are_defined 1 #endif diff --git a/tests/libc/oracle/stdbool_as_cpp.res.oracle b/tests/libc/oracle/stdbool_as_cpp.res.oracle new file mode 100644 index 00000000000..52caed50261 --- /dev/null +++ b/tests/libc/oracle/stdbool_as_cpp.res.oracle @@ -0,0 +1,10 @@ +[kernel] Parsing tests/libc/stdbool_as_cpp.c (with preprocessing) +/* Generated by Frama-C */ +int main(void) +{ + int __retres; + __retres = 0; + return __retres; +} + + diff --git a/tests/libc/stdbool_as_cpp.c b/tests/libc/stdbool_as_cpp.c new file mode 100644 index 00000000000..13e7bd6f68b --- /dev/null +++ b/tests/libc/stdbool_as_cpp.c @@ -0,0 +1,16 @@ +/* run.config* +OPT: -print +*/ +// announce that we are a non-conforming C++ compiler +#define __cplusplus 1L +#include <stdbool.h> +#ifdef bool +#error bool should not be defined in C++ mode +#endif +#ifdef true +#error true should not be defined in C++ mode +#endif +#ifdef false +#error false should not be defined in C++ mode +#endif +int main() { return 0; } -- GitLab