@@ -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");
}
}
@@ -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