Index: clang/include/clang/Basic/LangOptions.def =================================================================== --- clang/include/clang/Basic/LangOptions.def +++ clang/include/clang/Basic/LangOptions.def @@ -175,6 +175,7 @@ COMPATIBLE_LANGOPT(CPlusPlusModules, 1, 0, "C++ modules syntax") BENIGN_ENUM_LANGOPT(CompilingModule, CompilingModuleKind, 3, CMK_None, "compiling a module interface") +COMPATIBLE_LANGOPT(AllowNonInlineExternalDefInHU, 1, 0, "allow non inline external definitions in header units") BENIGN_LANGOPT(CompilingPCH, 1, 0, "building a pch") BENIGN_LANGOPT(BuildingPCHWithObjectFile, 1, 0, "building a pch which has a corresponding object file") BENIGN_LANGOPT(CacheGeneratedPCH, 1, 0, "cache generated PCH files in memory") Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ 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); Index: clang/test/CXX/module/module.import/p6.cpp =================================================================== --- clang/test/CXX/module/module.import/p6.cpp +++ 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; +}; +