[clang] [C++20][Modules] static data members of template classes should be allowed in header units (PR #98309)
Dmitry Polukhin via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 10 05:30:26 PDT 2024
https://github.com/dmpolukhin created https://github.com/llvm/llvm-project/pull/98309
Summary:
These is no sense to report this cases as an error or add `inline` explicitly in this cases. If it is not required in normal headers. Similar to #60079.
Test Plan: check-clang
>From 7fd31fea6d4a3003ca5c05be722bf42390ac5eb9 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin <dmitry.polukhin at gmail.com>
Date: Wed, 10 Jul 2024 05:13:09 -0700
Subject: [PATCH] [C++20][Modules] static data mebers of template classes
should be allowed in header units
Summary:
These is no sense to report this cases as an error or add `inline`
explicitly in this cases. If it is not required in normal headers.
Similar to #60079.
Test Plan: check-clang
Reviewers: @kaimfrai, @ChuanqiXu9
Subscribers: @iains, @EugeneZelenko, @dwblaikie, @Arthapz
---
clang/lib/Sema/SemaDecl.cpp | 3 ++-
clang/test/CXX/module/module.import/p6.cpp | 10 ++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b3bfdacb01790..7d810b895f9e8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13305,7 +13305,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
!VDecl->isInvalidDecl() && VDecl->isThisDeclarationADefinition() &&
VDecl->getFormalLinkage() == Linkage::External && !VDecl->isInline() &&
- !VDecl->isTemplated() && !isa<VarTemplateSpecializationDecl>(VDecl)) {
+ !VDecl->isTemplated() && !isa<VarTemplateSpecializationDecl>(VDecl) &&
+ !VDecl->getInstantiatedFromStaticDataMember()) {
Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit);
VDecl->setInvalidDecl();
}
diff --git a/clang/test/CXX/module/module.import/p6.cpp b/clang/test/CXX/module/module.import/p6.cpp
index 0ed8b5958dffe..cb2d799e5b565 100644
--- a/clang/test/CXX/module/module.import/p6.cpp
+++ b/clang/test/CXX/module/module.import/p6.cpp
@@ -67,3 +67,13 @@ void* tmpl_fn_ok
inline int foo (int a) {
return tmpl_OK (a);
}
+
+template <typename T> struct S2 { static int v; };
+template <typename T> int S2<T>::v = 10;
+
+template <typename T> bool b() {
+ bool b1 = S2<T>::v == 10;
+ return b1 && true;
+}
+
+inline bool B = b<int>();
More information about the cfe-commits
mailing list