Author: Chuanqi Xu Date: 2023-01-17T17:48:09+08:00 New Revision: b3eb004ca78f522c91c0d83bafeab2ee753417c8
URL: https://github.com/llvm/llvm-project/commit/b3eb004ca78f522c91c0d83bafeab2ee753417c8 DIFF: https://github.com/llvm/llvm-project/commit/b3eb004ca78f522c91c0d83bafeab2ee753417c8.diff LOG: [C++20] [Modules] Only diagnose the non-inline external variable definitions in header units Address part of https://github.com/llvm/llvm-project/issues/60079. Since the the declaration of a non-inline static data member in its class definition is not a definition. The following form: ``` class A { public: static const int value = 43; }; ``` should be fine to appear in a header unit. From the perspective of implementation, it looks like we simply forgot to check if the variable is a definition... Reviewed By: iains Differential Revision: https://reviews.llvm.org/D141905 Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/CXX/module/module.import/p6.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e3fd4045e8bb1..baadaf3210ee4 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -13088,6 +13088,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { // 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 index 25c195038eb63..7d8632786d9ee 100644 --- a/clang/test/CXX/module/module.import/p6.cpp +++ b/clang/test/CXX/module/module.import/p6.cpp @@ -22,3 +22,9 @@ int ok_var_decl; 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; +}; + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits