Skip to content

Commit eb389b1

Browse files
ChuanqiXu9tstellar
authored andcommitted
[C++20] [Modules] handling selectAny attribute for vardecl
Close llvm#127963 The root cause of the problem seems to be that we didn't realize it simply. (cherry picked from commit 24c06a1)
1 parent 0bc2eb7 commit eb389b1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4803,7 +4803,8 @@ bool Sema::checkVarDeclRedefinition(VarDecl *Old, VarDecl *New) {
48034803
(New->getFormalLinkage() == Linkage::Internal || New->isInline() ||
48044804
isa<VarTemplateSpecializationDecl>(New) ||
48054805
New->getDescribedVarTemplate() || New->getNumTemplateParameterLists() ||
4806-
New->getDeclContext()->isDependentContext())) {
4806+
New->getDeclContext()->isDependentContext() ||
4807+
New->hasAttr<SelectAnyAttr>())) {
48074808
// The previous definition is hidden, and multiple definitions are
48084809
// permitted (in separate TUs). Demote this to a declaration.
48094810
New->demoteThisDefinitionToDeclaration();

clang/test/Modules/pr127943.cppm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/repro.cppm -fdeclspec -emit-module-interface -o %t/repro.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/source.cpp -fdeclspec -fsyntax-only -verify -fprebuilt-module-path=%t
7+
8+
//--- repro_decl.hpp
9+
#pragma once
10+
11+
extern "C"
12+
{
13+
__declspec(selectany) int foo = 0;
14+
}
15+
16+
//--- repro.cppm
17+
module;
18+
#include "repro_decl.hpp"
19+
20+
export module repro;
21+
22+
export inline int func()
23+
{
24+
return foo;
25+
}
26+
27+
//--- source.cpp
28+
// expected-no-diagnostics
29+
import repro;
30+
31+
#include "repro_decl.hpp"

0 commit comments

Comments
 (0)