From 63d7500569483951597d95d6cf477e4526114013 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Mon, 5 Nov 2001 22:26:13 +0000 Subject: cppexp.c (lex, [...]): Update warning about defined. * cppexp.c (lex, parse_defined): Update warning about defined. * gcc.dg/cpp/defined.c: Update. From-SVN: r46794 --- gcc/ChangeLog | 4 ++++ gcc/cppexp.c | 11 +++++------ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/cpp/defined.c | 25 +++++++++++++++++++++---- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 06d0542..a1018aa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2001-11-05 Neil Booth + + * cppexp.c (lex, parse_defined): Update warning about defined. + 2001-11-05 Geoffrey Keating * config/rs6000/rs6000.c (rs6000_select_section): Handle diff --git a/gcc/cppexp.c b/gcc/cppexp.c index c7a00da..ac222ee 100644 --- a/gcc/cppexp.c +++ b/gcc/cppexp.c @@ -219,6 +219,7 @@ parse_defined (pfile) cpp_hashnode *node = 0; const cpp_token *token; struct op op; + cpp_context *initial_context = pfile->context; /* Don't expand macros. */ pfile->state.prevent_expansion++; @@ -259,6 +260,9 @@ parse_defined (pfile) op.op = CPP_ERROR; else { + if (pfile->context != initial_context) + cpp_warning (pfile, "this use of \"defined\" may not be portable"); + op.value = node->type == NT_MACRO; op.unsignedp = 0; op.op = CPP_NUMBER; @@ -314,12 +318,7 @@ lex (pfile, skip_evaluation) case CPP_NAME: if (token->val.node == pfile->spec_nodes.n_defined) - { - if (pfile->context->prev && CPP_PEDANTIC (pfile)) - cpp_pedwarn (pfile, "\"defined\" operator appears during macro expansion"); - - return parse_defined (pfile); - } + 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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 985326e..2badf85 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-11-05 Neil Booth + + * gcc.dg/cpp/defined.c: Update. + 2001-11-04 Neil Booth * gcc.c-torture/execute/anon-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/cpp/defined.c b/gcc/testsuite/gcc.dg/cpp/defined.c index de1ef29..864ef1d 100644 --- a/gcc/testsuite/gcc.dg/cpp/defined.c +++ b/gcc/testsuite/gcc.dg/cpp/defined.c @@ -21,7 +21,7 @@ /* The behaviour of "defined" when it comes from a macro expansion is now documented. */ -#if is_Z_defined /* { dg-warning "macro expansion" } */ +#if is_Z_defined #error Macro expanding into defined operator test 1 #endif @@ -31,7 +31,7 @@ #error Z is defined #endif -#if !is_Z_defined /* { dg-warning "macro expansion" } */ +#if !is_Z_defined #error Macro expanding into defined operator test 2 #endif @@ -53,7 +53,7 @@ /* The behaviour of "defined" when it comes from a macro expansion is now documented. */ -#if is_Z_defined /* { dg-warning "macro expansion" } */ +#if is_Z_defined #error Macro expanding into defined operator test 1 #endif @@ -63,6 +63,23 @@ #error Z is defined #endif -#if !is_Z_defined /* { dg-warning "macro expansion" } */ +#if !is_Z_defined #error Macro expanding into defined operator test 2 #endif + +/* Use of defined in different contexts. */ + +#define bad1 defined +#if !bad1 Z /* { dg-warning "may not be portable" } */ +#error Z is defined +#endif + +#if !bad1 (Z) /* { dg-warning "may not be portable" } */ +#error Z is defined +#endif + +#define bad2 defined (Z +#if !bad2) /* { dg-warning "may not be portable" } */ +#error Z is defined +#endif + -- cgit v1.1