re PR c/81795 (Stray "originally defined here" when using -Wc++-compat with #pragma...
authorMarek Polacek <polacek@redhat.com>
Fri, 11 Aug 2017 18:02:18 +0000 (18:02 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 11 Aug 2017 18:02:18 +0000 (18:02 +0000)
PR c/81795
* c-decl.c (pushtag): Only print inform if the warning was printed.
(grokdeclarator): Likewise.

* gcc.dg/pr81795.c: New test.

From-SVN: r251056

gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr81795.c [new file with mode: 0644]

index 6e29334..cd0c128 100644 (file)
@@ -1,3 +1,9 @@
+2017-08-11  Marek Polacek  <polacek@redhat.com>
+
+       PR c/81795
+       * c-decl.c (pushtag): Only print inform if the warning was printed.
+       (grokdeclarator): Likewise.
+
 2017-08-10  David Malcolm  <dmalcolm@redhat.com>
 
        * c-parser.c (c_parser_error): Rename to...
index d21fbc5..323d448 100644 (file)
@@ -1557,11 +1557,10 @@ pushtag (location_t loc, tree name, tree type)
          && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl))
              != TYPE_MAIN_VARIANT (type)))
        {
-         warning_at (loc, OPT_Wc___compat,
-                     ("using %qD as both a typedef and a tag is "
-                      "invalid in C++"),
-                     b->decl);
-         if (b->locus != UNKNOWN_LOCATION)
+         if (warning_at (loc, OPT_Wc___compat,
+                         ("using %qD as both a typedef and a tag is "
+                          "invalid in C++"), b->decl)
+             && b->locus != UNKNOWN_LOCATION)
            inform (b->locus, "originally defined here");
        }
     }
@@ -6596,11 +6595,10 @@ grokdeclarator (const struct c_declarator *declarator,
                  || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
              && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
            {
-             warning_at (declarator->id_loc, OPT_Wc___compat,
-                         ("using %qD as both a typedef and a tag is "
-                          "invalid in C++"),
-                         decl);
-             if (b->locus != UNKNOWN_LOCATION)
+             if (warning_at (declarator->id_loc, OPT_Wc___compat,
+                             ("using %qD as both a typedef and a tag is "
+                              "invalid in C++"), decl)
+                 && b->locus != UNKNOWN_LOCATION)
                inform (b->locus, "originally defined here");
            }
        }
index 71b7c62..056953e 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-11  Marek Polacek  <polacek@redhat.com>
+
+       PR c/81795
+       * gcc.dg/pr81795.c: New test.
+
 2017-08-11  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/60355
diff --git a/gcc/testsuite/gcc.dg/pr81795.c b/gcc/testsuite/gcc.dg/pr81795.c
new file mode 100644 (file)
index 0000000..b035bd0
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR c/81795 */
+/* { dg-do compile } */
+/* { dg-options "-Wc++-compat" } */
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++-compat"
+
+struct S { int f; };   /* { dg-bogus "note: originally defined here" } */
+typedef int S;         /* { dg-bogus "invalid in C\[+\]\[+\]" } */
+
+typedef int T;         /* { dg-bogus "note: originally defined here" } */
+struct T { int f; };    /* { dg-bogus "invalid in C\[+\]\[+\]" } */
+
+#pragma GCC diagnostic pop