diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/Decl.h | 1 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 17 | ||||
| -rw-r--r-- | clang/test/Sema/tentative-decls.c | 2 | ||||
| -rw-r--r-- | clang/test/Sema/var-redecl.c | 5 |
4 files changed, 21 insertions, 4 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index d4d22060c83..e4a40c6caaf 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -258,6 +258,7 @@ public: virtual void Destroy(ASTContext& C); StorageClass getStorageClass() const { return (StorageClass)SClass; } + void setStorageClass(StorageClass SC) { SClass = SC; } SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; } 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; diff --git a/clang/test/Sema/tentative-decls.c b/clang/test/Sema/tentative-decls.c index 23297f3a220..fc0d50086ea 100644 --- a/clang/test/Sema/tentative-decls.c +++ b/clang/test/Sema/tentative-decls.c @@ -27,7 +27,7 @@ extern int i1; // expected-note {{previous definition is here}} static int i1; // expected-error{{static declaration of 'i1' follows non-static declaration}} static int i2 = 5; // expected-note 1 {{previous definition is here}} -int i2 = 3; // expected-error{{non-static declaration of 'i2' follows static declaration}} +int i2 = 3; // expected-error{{redefinition of 'i2'}} __private_extern__ int pExtern; int pExtern = 0; diff --git a/clang/test/Sema/var-redecl.c b/clang/test/Sema/var-redecl.c index 82ce58bcb9c..037a8f136d8 100644 --- a/clang/test/Sema/var-redecl.c +++ b/clang/test/Sema/var-redecl.c @@ -54,3 +54,8 @@ void g18(void) { extern int g19; } int *p=&g19; // expected-error{{use of undeclared identifier 'g19'}} + +// PR3645 +static int a; +extern int a; +int a; |

