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
// 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);
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;
+};
+