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 6e293345e9961c7166093b3c53a06bffdf65fafe..cd0c128edc82c79c300498942e7f9d955ec21aac 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 d21fbc5883e087ea755b82774c6fa542b981c9b7..323d448060905445f9cff8bbe40080e4308e673e 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 71b7c6269802e7c66e43df20409a049a4f1c73cd..056953e77930ee57d1e4177d6e7450e243ce8d29 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