-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[C++20][Modules] static data members of template classes should be allowed in header units #98309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C++20][Modules] static data members of template classes should be allowed in header units #98309
Conversation
…owed 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 llvm#60079. Test Plan: check-clang Reviewers: @kaimfrai, @ChuanqiXu9 Subscribers: @iains, @EugeneZelenko, @dwblaikie, @Arthapz
@llvm/pr-subscribers-clang-modules @llvm/pr-subscribers-clang Author: Dmitry Polukhin (dmpolukhin) ChangesSummary: Test Plan: check-clang Full diff: https://github.com/llvm/llvm-project/pull/98309.diff 2 Files Affected:
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>();
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…lowed in header units (llvm#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 llvm#60079. Test Plan: check-clang
1. __cpp_lib_modules now is defined. llvm/llvm-project#90091 2. clang-cl supports -x option for all languages. llvm/llvm-project#89772 3. Header units allow non-inline external static members definitions. llvm/llvm-project#98309 4. winsysroot alias to the GNU driver: -Xmicrosoft-windows-sys-root. llvm/llvm-project#94731 5. clang-cl gained options for compiling C++ modules. llvm/llvm-project#98761 6. fix unused argument warning for /std:c++20 when compiling c++ modules. llvm/llvm-project#99300
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