From 1b2d986f8a66b32523465fe606c7f2b12b3cfd83 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 17 Apr 2015 09:50:28 +0000 Subject: [PATCH] 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.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235174 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Decl.cpp | 3 ++- test/SemaCXX/attr-selectany.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 628c9b053e..b532d3bb34 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1915,7 +1915,8 @@ VarDecl::isThisDeclarationADefinition(ASTContext &C) const { if (hasInit()) return Definition; - if (hasAttr() || hasAttr()) + if (hasAttr() || + (hasAttr() && !getAttr()->isInherited())) return Definition; // A variable template specialization (other than a static data member diff --git a/test/SemaCXX/attr-selectany.cpp b/test/SemaCXX/attr-selectany.cpp index 7d9cf7aea4..058f2fcb84 100644 --- a/test/SemaCXX/attr-selectany.cpp +++ b/test/SemaCXX/attr-selectany.cpp @@ -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}} -- 2.40.0