[cfe-dev] [libcxx]: a testsuite bug involving boolean type and values

Jordan Rose jordan_rose at apple.com
Wed Oct 10 09:26:40 PDT 2012


Hello, Xiongpang. Notice that this particular test case is compiled as C++. In C++, <stdbool.h> does not actually have to do anything. From C++11 [support.runtime]p8: "The header <cstdbool> and the header <stdbool.h> shall not define macros named bool, true, or false."

For C, of course, the header must define the four macros.

Best,
Jordan


On Oct 9, 2012, at 22:53 , ZhangXiongpang <zhangxiongpang at gmail.com> wrote:

> I saw the code in
>    test/depr/depr.c.headers/stdbool_h.pass.cpp
> as follows:
> --------------------------------------------------
> #include <stdbool.h>
> 
> #ifndef __bool_true_false_are_defined
> #error __bool_true_false_are_defined not defined
> #endif
> 
> #ifdef bool // why bool should not be defined?
> #error bool should not be defined
> #endif
> 
> #ifdef true // idem
> #error true should not be defined
> #endif
> 
> #ifdef false // idem
> #error false should not be defined
> #endif
> --------------------------------------------------
> 
> Why bool/true/false should not be defined?
> Is it a bug of the stdbool_h.pass.cpp?
> I think it should be:
> --------------------------------------------------
> #ifndef bool
> #error bool should not defined
> #endif
> 
> #ifndef true
> #error true should not defined
> #endif
> 
> #ifndef false
> #error false should not defined
> #endif
> --------------------------------------------------
> 
> Because the section 7.18 of  n1548.pdf
> <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf>   says:
> --------------------------------------------------
> 7.18 Boolean type and values <stdbool.h>
> 1 The header <stdbool.h> defines four macros.
> 2 The macro bool expands to _Bool.
> 3 The remaining three macros are suitable for use in #if preprocessing
> directives. They are true which expands to the integer constant 1, false
> which expands to the integer constant 0, and _bool_true_false_are_defined
> which expands to the integer constant 1.
> --------------------------------------------------
> 
> 
> 
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/libcxx-a-testsuite-bug-involving-boolean-type-and-values-tp4027262.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list