aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorZack Weinberg <zack@wolery.stanford.edu>2001-02-07 18:32:42 +0000
committerZack Weinberg <zack@wolery.stanford.edu>2001-02-07 18:32:42 +0000
commit381f329b6de7dc4c78f0abb87a0a65455cf35064 (patch)
treec4639b8fbbd99fcc0eb642f020f8787aad421122 /gcc
parent49d14742999383df09362ffb692e300553c6ea6d (diff)
* 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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@39523 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/cppexp.c38
-rw-r--r--gcc/cppinit.c4
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/stdbool-if.C33
5 files changed, 77 insertions, 11 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bbfc2fe9b30..2f385b7ccae 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+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
diff --git a/gcc/cppexp.c b/gcc/cppexp.c
index bea20a22ce5..11cde7066e1 100644
--- a/gcc/cppexp.c
+++ b/gcc/cppexp.c
@@ -426,18 +426,36 @@ lex (pfile, skip_evaluation, token)
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:
{
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index 845d35b7fd1..539366660b1 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -203,7 +203,7 @@ append_include_chain (pfile, dir, path, cxx_aware)
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;
@@ -554,6 +554,8 @@ cpp_create_reader (lang)
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__"));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3e77bda33fa..b40f2d5c627 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+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().
diff --git a/gcc/testsuite/g++.dg/stdbool-if.C b/gcc/testsuite/g++.dg/stdbool-if.C
new file mode 100644
index 00000000000..e9800bf160d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/stdbool-if.C
@@ -0,0 +1,33 @@
+/* { 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