]> granicus.if.org Git - clang/commitdiff
Don't warn about the 'extern' in 'extern "C"' on a tag decl. This is
authorJohn McCall <rjmccall@apple.com>
Sat, 26 Mar 2011 02:09:52 +0000 (02:09 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 26 Mar 2011 02:09:52 +0000 (02:09 +0000)
usually useless, but not always.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128326 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/storage-class.cpp

index 5a4df400f3b3b6bea9da468ef8c516b496e7278b..59b4f5f2292f388faf1b5f42826114268fbad3a3 100644 (file)
@@ -1870,9 +1870,14 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
   if (emittedWarning || (TagD && TagD->isInvalidDecl()))
     return TagD;
 
+  // Note that a linkage-specification sets a storage class, but
+  // 'extern "C" struct foo;' is actually valid and not theoretically
+  // useless.
   if (DeclSpec::SCS scs = DS.getStorageClassSpec())
-    Diag(DS.getStorageClassSpecLoc(), diag::warn_standalone_specifier)
-      << DeclSpec::getSpecifierName(scs);
+    if (!DS.isExternInLinkageSpec())
+      Diag(DS.getStorageClassSpecLoc(), diag::warn_standalone_specifier)
+        << DeclSpec::getSpecifierName(scs);
+
   if (DS.isThreadSpecified())
     Diag(DS.getThreadSpecLoc(), diag::warn_standalone_specifier) << "__thread";
   if (DS.getTypeQualifiers()) {
index a2e206323a0741c2e3a4eba3db7b44768830c5ea..01cfbfc51faaa753b0ceb0324464ff1d3da4688c 100644 (file)
@@ -2,3 +2,6 @@
 extern const int PR6495a = 42;
 extern int PR6495b = 42; // expected-warning{{'extern' variable has an initializer}}
 extern const int PR6495c[] = {42,43,44};
+
+extern struct Test1 {}; // expected-warning {{'extern' ignored on this declaration}}
+extern "C" struct Test0 {}; // no warning