* cpphash.h (struct spec_nodes): Add n_true and n_false.
* cppinit.c (cpp_create_reader): Initialize them.
(append_include_chain): cxx_aware arg might be unused.
* cppexp.c (lex): In C++ mode, recognize 'true' and 'false'
keywords and give them their phase 7 meaning. Pedwarn about
this unless '__bool_true_false_are_defined' is defined.
* g++.dg/stdbool-if.C: New test.
From-SVN: r39523
+2001-02-07 Zack Weinberg <zack@wolery.stanford.edu>
+
+ * cpphash.h (struct spec_nodes): Add n_true and n_false.
+ * cppinit.c (cpp_create_reader): Initialize them.
+ (append_include_chain): cxx_aware arg might be unused.
+ * cppexp.c (lex): In C++ mode, recognize 'true' and 'false'
+ keywords and give them their phase 7 meaning. Pedwarn about
+ this unless '__bool_true_false_are_defined' is defined.
+
2001-02-07 Alexandre Oliva <aoliva@redhat.com>
* lcm.c (optimize_mode_switching): Emit mode_set before the
return parse_defined (pfile);
}
- /* Controlling #if expressions cannot contain identifiers (they
- could become macros in the future). */
- pfile->mi_state = MI_FAILED;
-
- op.op = CPP_INT;
- op.unsignedp = 0;
- op.value = 0;
+ else if (CPP_OPTION (pfile, cplusplus)
+ && (token->val.node == pfile->spec_nodes.n_true
+ || token->val.node == pfile->spec_nodes.n_false))
+ {
+ op.op = CPP_INT;
+ op.unsignedp = 0;
+ op.value = (token->val.node == pfile->spec_nodes.n_true);
+
+ /* Warn about use of true or false in #if when pedantic
+ and stdbool.h has not been included. */
+ if (CPP_PEDANTIC (pfile)
+ && ! cpp_defined (pfile, DSC("__bool_true_false_are_defined")))
+ cpp_pedwarn (pfile, "ISO C++ does not permit \"%s\" in #if",
+ token->val.node->name);
+ return op;
+ }
+ else
+ {
+ /* Controlling #if expressions cannot contain identifiers (they
+ could become macros in the future). */
+ pfile->mi_state = MI_FAILED;
- if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation)
- cpp_warning (pfile, "\"%s\" is not defined", token->val.node->name);
+ op.op = CPP_INT;
+ op.unsignedp = 0;
+ op.value = 0;
- return op;
+ if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation)
+ cpp_warning (pfile, "\"%s\" is not defined", token->val.node->name);
+ return op;
+ }
case CPP_HASH:
{
cpp_reader *pfile;
char *dir;
int path;
- int cxx_aware;
+ int cxx_aware ATTRIBUTE_UNUSED;
{
struct cpp_pending *pend = CPP_OPTION (pfile, pending);
struct file_name_list *new;
s = &pfile->spec_nodes;
s->n_L = cpp_lookup (pfile, DSC("L"));
s->n_defined = cpp_lookup (pfile, DSC("defined"));
+ s->n_true = cpp_lookup (pfile, DSC("true"));
+ s->n_false = cpp_lookup (pfile, DSC("false"));
s->n__Pragma = cpp_lookup (pfile, DSC("_Pragma"));
s->n__STRICT_ANSI__ = cpp_lookup (pfile, DSC("__STRICT_ANSI__"));
s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__"));
+2001-02-07 Zack Weinberg <zack@wolery.stanford.edu>
+
+ * g++.dg/stdbool-if.C: New test.
+
Wed Feb 7 09:54:47 2001 Ovidiu Predescu <ovidiu@cup.hp.com>
* objc/execute/fdecl.m: Added main().
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options -pedantic } */
+
+/* test of 'true' and 'false' in #if. this is accepted with a pedwarn
+ before stdbool.h is included, silently afterward. */
+
+/* Make sure they're viable keywords. */
+bool a = true;
+bool b = false;
+
+#if true /* { dg-warning "true" "true in #if pedwarn" } */
+#else
+#error true is false /* { dg-bogus "true" "true is false" } */
+#endif
+
+#if false /* { dg-warning "false" "false in #if pedwarn" } */
+#error false is true /* { dg-bogus "false" "false is true" } */
+#endif
+
+#include <stdbool.h>
+
+/* Must still be viable keywords. */
+bool c = true;
+bool d = false;
+
+#if true /* { dg-bogus "true" "true in #if with stdbool.h" } */
+#else
+#error true is false /* { dg-bogus "true" "true is false" } */
+#endif
+
+#if false /* { dg-bogus "false" "false in #if with stdbool.h" } */
+#error false is true /* { dg-bogus "false" "false is true" } */
+#endif