]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-parser.c (c_parser_postfix_expression): Add pedwarn.
authorMarek Polacek <polacek@redhat.com>
Tue, 12 Aug 2014 18:53:33 +0000 (18:53 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 12 Aug 2014 18:53:33 +0000 (18:53 +0000)
* c-parser.c (c_parser_postfix_expression) <case RID_FUNCTION_NAME>:
Add pedwarn.
(c_parser_postfix_expression) <case RID_PRETTY_FUNCTION_NAME>:
Likewise.
(c_parser_postfix_expression) <case RID_C99_FUNCTION_NAME>: Likewise.

* gcc.dg/concat.c: Add dg-options.
* gcc.dg/func-outside-2.c: Add __extension__.
* gcc.dg/pr19967.c: Use -std=c99.
* gcc.dg/pr22458-1.c: Add dg-options.
* gcc.dg/pr33676.c: Add dg-options.
* gcc.dg/gnu-predef-1.c: New test.
* gcc.dg/c90-func-1.c: New test.
* gcc.dg/c90-func-2.c: New test.
* gcc.dg/c90-func-2.h: New test.

From-SVN: r213875

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c90-func-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c90-func-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c90-func-2.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/concat.c
gcc/testsuite/gcc.dg/func-outside-2.c
gcc/testsuite/gcc.dg/pr19967.c
gcc/testsuite/gcc.dg/pr22458-1.c
gcc/testsuite/gcc.dg/pr33676.c

index 154768b2a49e12025973b2023f16ab9dff34077e..1d553099e9c3d908fed7029c11110f5c18df0f40 100644 (file)
@@ -1,3 +1,11 @@
+2014-08-12  Marek Polacek  <polacek@redhat.com>
+
+       * c-parser.c (c_parser_postfix_expression) <case RID_FUNCTION_NAME>:
+       Add pedwarn.
+       (c_parser_postfix_expression) <case RID_PRETTY_FUNCTION_NAME>:
+       Likewise.
+       (c_parser_postfix_expression) <case RID_C99_FUNCTION_NAME>: Likewise.
+
 2014-08-10 Marek Polacek  <polacek@redhat.com>
 
        PR c/51849
index ca8577cd63a11d0bbd9c153c0683ce80184f8826..5f23379df8f06265cc85e9123edd4a10f2072bcd 100644 (file)
@@ -7136,8 +7136,24 @@ c_parser_postfix_expression (c_parser *parser)
       switch (c_parser_peek_token (parser)->keyword)
        {
        case RID_FUNCTION_NAME:
+         pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
+                  "%<__FUNCTION__%> predefined identifier");
+         expr.value = fname_decl (loc,
+                                  c_parser_peek_token (parser)->keyword,
+                                  c_parser_peek_token (parser)->value);
+         c_parser_consume_token (parser);
+         break;
        case RID_PRETTY_FUNCTION_NAME:
+         pedwarn (loc, OPT_Wpedantic,  "ISO C does not support "
+                  "%<__PRETTY_FUNCTION__%> predefined identifier");
+         expr.value = fname_decl (loc,
+                                  c_parser_peek_token (parser)->keyword,
+                                  c_parser_peek_token (parser)->value);
+         c_parser_consume_token (parser);
+         break;
        case RID_C99_FUNCTION_NAME:
+         pedwarn_c90 (loc, OPT_Wpedantic,  "ISO C90 does not support "
+                  "%<__func__%> predefined identifier");
          expr.value = fname_decl (loc,
                                   c_parser_peek_token (parser)->keyword,
                                   c_parser_peek_token (parser)->value);
index 52fdcb5f50ebe4932bc30b6e47e9d01c6b36e535..536485a5f69063fbddac5f5478d325ae7ce38e40 100644 (file)
@@ -1,3 +1,15 @@
+2014-08-12  Marek Polacek  <polacek@redhat.com>
+
+       * gcc.dg/concat.c: Add dg-options.
+       * gcc.dg/func-outside-2.c: Add __extension__.
+       * gcc.dg/pr19967.c: Use -std=c99.
+       * gcc.dg/pr22458-1.c: Add dg-options.
+       * gcc.dg/pr33676.c: Add dg-options.
+       * gcc.dg/gnu-predef-1.c: New test.
+       * gcc.dg/c90-func-1.c: New test.
+       * gcc.dg/c90-func-2.c: New test.
+       * gcc.dg/c90-func-2.h: New test.
+
 2014-08-12  Janis Johnson  <janisjo@codesourcery.com>
 
        * lib/target/supports.exp
diff --git a/gcc/testsuite/gcc.dg/c90-func-1.c b/gcc/testsuite/gcc.dg/c90-func-1.c
new file mode 100644 (file)
index 0000000..5f171d3
--- /dev/null
@@ -0,0 +1,10 @@
+/* Test that we diagnose the __func__ predefined identifier in
+   C90 pedantic mode.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
+
+void
+foo (void)
+{
+  const char *s = __func__; /* { dg-error " ISO C90 does not support .__func__. predefined identifier" } */
+}
diff --git a/gcc/testsuite/gcc.dg/c90-func-2.c b/gcc/testsuite/gcc.dg/c90-func-2.c
new file mode 100644 (file)
index 0000000..5185e35
--- /dev/null
@@ -0,0 +1,12 @@
+/* Test that we don't pedwarn about __func__ predefined identifier in
+   a system header in C90 pedantic mode.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
+
+#include "c90-func-2.h"
+
+void
+foo (void)
+{
+  const char *s = FN;
+}
diff --git a/gcc/testsuite/gcc.dg/c90-func-2.h b/gcc/testsuite/gcc.dg/c90-func-2.h
new file mode 100644 (file)
index 0000000..2bad1bd
--- /dev/null
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+#define FN __func__
index 0b9d6f6a7c4d4d275fd8d96db71f9cb04626d34c..e3bfd4632409a6676298045a894efa9e7a3bf8f7 100644 (file)
@@ -1,6 +1,7 @@
 /* Copyright (C) 2001 Free Software Foundation, Inc.  */
 
 /* { dg-do compile } */
+/* { dg-options "" } */
 
 /* Test we output an error for concatenation of artificial strings.
 
index be3b0999e787c18a09faa8ea515159c7b2789b4d..28ef6bced7cd27bbebaf609af7432dc14d35c96b 100644 (file)
@@ -4,6 +4,6 @@
 /* { dg-do compile } */
 /* { dg-options "-pedantic-errors" } */
 
-const char *a = __func__; /* { dg-error "'__func__' is not defined outside of function scope" "undef" } */
-const char *b = __FUNCTION__;
-const char *c = __PRETTY_FUNCTION__;
+__extension__ const char *a = __func__; /* { dg-error "'__func__' is not defined outside of function scope" "undef" } */
+__extension__ const char *b = __FUNCTION__;
+__extension__ const char *c = __PRETTY_FUNCTION__;
index 85afeafe2858aee5f5cbd74832849eab0fbcca24..68c7e1cb99c9929a16b757d9337ddd94844141c7 100644 (file)
@@ -4,7 +4,7 @@
    be const char *.  */
 
 /* { dg-do compile } */
-/* { dg-options "-pedantic" } */
+/* { dg-options "-pedantic -std=c99" } */
 
 char *strchr(const char *, int);
 char *strrchr(const char *, int);
index 8b8032c410a6e1eb451833d295cc44736627a383..023fb210c6a0d2fb2915460761781d9bc74a7a51 100644 (file)
@@ -1,4 +1,6 @@
 /* { dg-error "expected declaration or statement" "" { target *-*-* } 0 } */
+/* { dg-options "" } */
+
 void foo()
 {
      __PRETTY_FUNCTION__;
index 79c830eabfb216ec544cc2e19212ba073c4d4f60..c2344708c4dc32e4d6d9e48367a38095de354179 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-do run } */
+/* { dg-options "" } */
 /* { dg-options "-O0 -mtune=i386 -fomit-frame-pointer" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
 
 __attribute__((noreturn,noinline)) void abrt (const char *fi, const char *fu)