@@ -1049,7 +1049,14 @@ eval_token (cpp_reader *pfile, const cpp_token *token,
case CPP_NAME:
if (token->val.node.node == pfile->spec_nodes.n_defined)
- return parse_defined (pfile);
+ {
+ if (pfile->context->prev && CPP_PEDANTIC (pfile))
+ cpp_error_with_line (pfile, CPP_DL_WARNING, virtual_location, 0,
+ "this use of \"defined\" may not be portable");
+
+ return parse_defined (pfile);
+ }
+
else if (token->val.node.node == pfile->spec_nodes.n__has_include__)
return parse_has_include (pfile, IT_INCLUDE);
else if (token->val.node.node == pfile->spec_nodes.n__has_include_next__)
@@ -1,6 +1,7 @@
/* Copyright (C) 2000 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
+/* { dg-additional-options "-ftrack-macro-expansion=2" } */
/* Tests behavior of the defined operator. */
@@ -13,15 +14,15 @@
#error defined is defined!
#endif
-#define is_Z_defined defined Z
+#define is_Z_defined defined Z /* { dg-warning "may not be portable" } */
#if defined Z
#error Z is not defined
#endif
-/* The behavior of "defined" when it comes from a macro expansion is
- now documented. */
-#if is_Z_defined
+/* The behavior of "defined" when it comes from a macro expansion is documented
+ by gcc, but still undefined according to the specification. */
+#if is_Z_defined /* { dg-message "is_Z_defined" } */
#error Macro expanding into defined operator test 1
#endif
@@ -31,7 +32,7 @@
#error Z is defined
#endif
-#if !is_Z_defined
+#if !is_Z_defined /* { dg-message "is_Z_defined" } */
#error Macro expanding into defined operator test 2
#endif
@@ -45,15 +46,15 @@
#error defined is defined!
#endif
-#define is_Z_defined defined ( Z )
+#define is_Z_defined defined ( Z ) /* { dg-warning "may not be portable" } */
#if defined(Z)
#error Z is not defined
#endif
-/* The behavior of "defined" when it comes from a macro expansion is
- now documented. */
-#if is_Z_defined
+/* The behavior of "defined" when it comes from a macro expansion is documented
+ by gcc, but still undefined according to the specification. */
+#if is_Z_defined /* { dg-message "is_Z_defined" } */
#error Macro expanding into defined operator test 1
#endif
@@ -63,14 +64,15 @@
#error Z is defined
#endif
-#if !is_Z_defined
+#if !is_Z_defined /* { dg-message "is_Z_defined" } */
#error Macro expanding into defined operator test 2
#endif
/* Use of defined in different contexts. */
-#define bad1 defined
+#define bad1 defined /* { dg-warning "may not be portable" } */
#if !bad1 Z /* { dg-warning "may not be portable" } */
+ /* { dg-message "bad1" "note" { target *-*-* } 74 } */
#error Z is defined
#endif
@@ -78,8 +80,9 @@
#error Z is defined
#endif
-#define bad2 defined (Z
+#define bad2 defined (Z /* { dg-warning "may not be portable" } */
#if !bad2) /* { dg-warning "may not be portable" } */
+ /* { dg-message "bad2" "note" { target *-*-* } 84 } */
#error Z is defined
#endif