r235174 - Follow-up to r235046: selectany only causes a definition if it's not inherited.
Nico Weber
nicolasweber at gmx.de
Fri Apr 17 02:50:28 PDT 2015
Author: nico
Date: Fri Apr 17 04:50:28 2015
New Revision: 235174
URL: http://llvm.org/viewvc/llvm-project?rev=235174&view=rev
Log:
Follow-up to r235046: selectany only causes a definition if it's not inherited.
(For example needed to parse system header inputscope.h, which first has
an extern "C" selectany IID and then later an extern "C" declaration of that
same IID.)
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/SemaCXX/attr-selectany.cpp
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=235174&r1=235173&r2=235174&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Apr 17 04:50:28 2015
@@ -1915,7 +1915,8 @@ VarDecl::isThisDeclarationADefinition(AS
if (hasInit())
return Definition;
- if (hasAttr<AliasAttr>() || hasAttr<SelectAnyAttr>())
+ if (hasAttr<AliasAttr>() ||
+ (hasAttr<SelectAnyAttr>() && !getAttr<SelectAnyAttr>()->isInherited()))
return Definition;
// A variable template specialization (other than a static data member
Modified: cfe/trunk/test/SemaCXX/attr-selectany.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-selectany.cpp?rev=235174&r1=235173&r2=235174&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-selectany.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-selectany.cpp Fri Apr 17 04:50:28 2015
@@ -42,5 +42,9 @@ __declspec(selectany) auto x8 = Internal
struct SomeStruct {};
extern const __declspec(selectany) SomeStruct some_struct; // expected-warning {{default initialization of an object of const type 'const SomeStruct' without a user-provided default constructor is a Microsoft extension}}
+// It should be possible to redeclare variables that were defined
+// __declspec(selectany) previously.
+extern const SomeStruct some_struct;
+
// Without selectany, this should stay an error.
const SomeStruct some_struct2; // expected-error {{default initialization of an object of const type 'const SomeStruct' without a user-provided default constructor}}
More information about the cfe-commits
mailing list