diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-08-24 05:27:49 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-08-24 05:27:49 +0000 |
| commit | f0f83699121267571f7bb35f3661cf91de2f329e (patch) | |
| tree | f40d87d579bb6b05f47e7410c646e8d6911f8a78 /clang/lib/Sema/SemaDecl.cpp | |
| parent | 7fd5544bc94791c51b2e460ab66483dc540e7299 (diff) | |
| download | bcm5719-llvm-f0f83699121267571f7bb35f3661cf91de2f329e.tar.gz bcm5719-llvm-f0f83699121267571f7bb35f3661cf91de2f329e.zip | |
Diagnose the presence of multiple initializations of static data
members, from Faisal Vali! Fixes PR6904.
llvm-svn: 111900
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b2c31916b73..0ed93910c7a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4077,6 +4077,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { return; } + + // A definition must end up with a complete type, which means it must be // complete with the restriction that an array type might be completed by the // initializer; note that later code assumes this restriction. @@ -4103,6 +4105,25 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { VDecl->setInvalidDecl(); return; } + + // C++ [class.static.data]p4 + // If a static data member is of const integral or const + // enumeration type, its declaration in the class definition can + // specify a constant-initializer which shall be an integral + // constant expression (5.19). In that case, the member can appear + // in integral constant expressions. The member shall still be + // defined in a namespace scope if it is used in the program and the + // namespace scope definition shall not contain an initializer. + // + // We already performed a redefinition check above, but for static + // data members we also need to check whether there was an in-class + // declaration with an initializer. + const VarDecl* PrevInit = 0; + if (VDecl->isStaticDataMember() && VDecl->getAnyInitializer(PrevInit)) { + Diag(VDecl->getLocation(), diag::err_redefinition) << VDecl->getDeclName(); + Diag(PrevInit->getLocation(), diag::note_previous_definition); + return; + } if (getLangOptions().CPlusPlus && VDecl->hasLocalStorage()) setFunctionHasBranchProtectedScope(); |

