diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-03-19 22:01:50 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-03-19 22:01:50 +0000 |
commit | 3731162adec6b606083160a6ebd7f4c13f89e388 (patch) | |
tree | 7743aaa57027d6ea96a278af6dcd45de6348f9cf /clang/lib/Sema/SemaDecl.cpp | |
parent | 1361cbbb0ba022b3496d30e00aa06990826a4ee3 (diff) | |
download | bcm5719-llvm-3731162adec6b606083160a6ebd7f4c13f89e388.tar.gz bcm5719-llvm-3731162adec6b606083160a6ebd7f4c13f89e388.zip |
Variables marked as "extern" can actually have internal linkage if
there is a previous declaration marked "static". This fixes PR3645.
llvm-svn: 67336
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 99ea7077606..7c80fa553e1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -832,9 +832,20 @@ bool Sema::MergeVarDecl(VarDecl *New, Decl *OldD) { Diag(Old->getLocation(), diag::note_previous_definition); return true; } - // C99 6.2.2p4: Check if we have a non-static decl followed by a static. - if (New->getStorageClass() != VarDecl::Static && - Old->getStorageClass() == VarDecl::Static) { + // C99 6.2.2p4: + // For an identifier declared with the storage-class specifier + // extern in a scope in which a prior declaration of that + // identifier is visible,23) if the prior declaration specifies + // internal or external linkage, the linkage of the identifier at + // the later declaration is the same as the linkage specified at + // the prior declaration. If no prior declaration is visible, or + // if the prior declaration specifies no linkage, then the + // identifier has external linkage. + if ((New->hasExternalStorage() || New->getStorageClass() == VarDecl::None) && + Old->hasLinkage()) + /* Okay */; + else if (New->getStorageClass() != VarDecl::Static && + Old->getStorageClass() == VarDecl::Static) { Diag(New->getLocation(), diag::err_non_static_static) << New->getDeclName(); Diag(Old->getLocation(), diag::note_previous_definition); return true; |