diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -13088,6 +13088,7 @@ // C++ [module.import/6] external definitions are not permitted in header // units. if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() && + VDecl->isThisDeclarationADefinition() && VDecl->getFormalLinkage() == Linkage::ExternalLinkage && !VDecl->isInline()) { Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit); diff --git a/clang/test/CXX/module/module.import/p6.cpp b/clang/test/CXX/module/module.import/p6.cpp --- a/clang/test/CXX/module/module.import/p6.cpp +++ b/clang/test/CXX/module/module.import/p6.cpp @@ -22,3 +22,9 @@ int bad_var_definition = 3; // expected-error {{non-inline external definitions are not permitted in C++ header units}} +class A { +public: + // This is a declaration instead of definition. + static const int value = 43; +}; +