diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d1c7b9d5ae5070..66eeaa8e6f7777 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -13313,7 +13313,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(VDecl)) { + !VDecl->isTemplated() && !isa(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 0ed8b5958dffe7..cb2d799e5b5658 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 struct S2 { static int v; }; +template int S2::v = 10; + +template bool b() { + bool b1 = S2::v == 10; + return b1 && true; +} + +inline bool B = b();