Skip to content

Commit 00fd188

Browse files
authored
[C++20][Modules] static data members of template classes should be allowed in header units (#98309)
Summary: There is no sense to report these cases as an error or add `inline` explicitly in these cases, if it is not required in normal headers. Similar to #60079. Test Plan: check-clang
1 parent a18f45f commit 00fd188

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13313,7 +13313,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
1331313313
if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
1331413314
!VDecl->isInvalidDecl() && VDecl->isThisDeclarationADefinition() &&
1331513315
VDecl->getFormalLinkage() == Linkage::External && !VDecl->isInline() &&
13316-
!VDecl->isTemplated() && !isa<VarTemplateSpecializationDecl>(VDecl)) {
13316+
!VDecl->isTemplated() && !isa<VarTemplateSpecializationDecl>(VDecl) &&
13317+
!VDecl->getInstantiatedFromStaticDataMember()) {
1331713318
Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit);
1331813319
VDecl->setInvalidDecl();
1331913320
}

clang/test/CXX/module/module.import/p6.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,13 @@ void* tmpl_fn_ok
6767
inline int foo (int a) {
6868
return tmpl_OK (a);
6969
}
70+
71+
template <typename T> struct S2 { static int v; };
72+
template <typename T> int S2<T>::v = 10;
73+
74+
template <typename T> bool b() {
75+
bool b1 = S2<T>::v == 10;
76+
return b1 && true;
77+
}
78+
79+
inline bool B = b<int>();

0 commit comments

Comments
 (0)