summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaDecl.cpp9
-rw-r--r--clang/test/SemaCXX/storage-class.cpp3
2 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5a4df400f3b..59b4f5f2292 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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()) {
diff --git a/clang/test/SemaCXX/storage-class.cpp b/clang/test/SemaCXX/storage-class.cpp
index a2e206323a0..01cfbfc51fa 100644
--- a/clang/test/SemaCXX/storage-class.cpp
+++ b/clang/test/SemaCXX/storage-class.cpp
@@ -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
OpenPOWER on IntegriCloud