cpphash.h (struct spec_nodes): Add n_true and n_false.

* 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
This commit is contained in:
Zack Weinberg 2001-02-07 18:32:42 +00:00 committed by Zack Weinberg
parent 7acfb19e40
commit 7d4918a2d9
5 changed files with 76 additions and 10 deletions

View File

@ -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

View File

@ -426,6 +426,24 @@ lex (pfile, skip_evaluation, token)
return parse_defined (pfile);
}
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;
@ -436,8 +454,8 @@ lex (pfile, skip_evaluation, token)
if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation)
cpp_warning (pfile, "\"%s\" is not defined", token->val.node->name);
return op;
}
case CPP_HASH:
{

View File

@ -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__"));

View File

@ -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().

View File

@ -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