]> granicus.if.org Git - clang/commitdiff
Follow-up to r235046: selectany only causes a definition if it's not inherited.
authorNico Weber <nicolasweber@gmx.de>
Fri, 17 Apr 2015 09:50:28 +0000 (09:50 +0000)
committerNico Weber <nicolasweber@gmx.de>
Fri, 17 Apr 2015 09:50:28 +0000 (09:50 +0000)
(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.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235174 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Decl.cpp
test/SemaCXX/attr-selectany.cpp

index 628c9b053ea4cb07ea121074c3c837d020307694..b532d3bb34ea060e87b1447bcf812c2135dda932 100644 (file)
@@ -1915,7 +1915,8 @@ VarDecl::isThisDeclarationADefinition(ASTContext &C) const {
   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
index 7d9cf7aea4e5a1c29f1ad8b2d982b93263eb59be..058f2fcb84ab71b4e054bc118b6df200b3a106b7 100644 (file)
@@ -42,5 +42,9 @@ __declspec(selectany) auto x8 = Internal(); // expected-error {{'selectany' can
 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}}