[C++20] [Modules] Avoid use-but-not-defined error
See the attached test for example.
This commit is contained in:
parent
a98707e285
commit
ea15e8b16e
@ -330,6 +330,12 @@ namespace clang {
|
||||
}
|
||||
|
||||
bool clang::CanElideDeclDef(const Decl *D) {
|
||||
bool isExternalWithNoLinkageType = false;
|
||||
if (auto *VD = dyn_cast<ValueDecl>(D))
|
||||
if (VD->hasExternalFormalLinkage() &&
|
||||
!isExternalFormalLinkage(VD->getType()->getLinkage()))
|
||||
isExternalWithNoLinkageType = true;
|
||||
|
||||
if (auto *FD = dyn_cast<FunctionDecl>(D)) {
|
||||
if (FD->isInlined() || FD->isConstexpr())
|
||||
return false;
|
||||
@ -339,6 +345,9 @@ bool clang::CanElideDeclDef(const Decl *D) {
|
||||
|
||||
if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
|
||||
return false;
|
||||
|
||||
if (isExternalWithNoLinkageType && !FD->isExternC())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auto *VD = dyn_cast<VarDecl>(D)) {
|
||||
@ -352,6 +361,9 @@ bool clang::CanElideDeclDef(const Decl *D) {
|
||||
|
||||
if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
|
||||
return false;
|
||||
|
||||
if (isExternalWithNoLinkageType && !VD->isExternC())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
27
clang/test/Modules/external-but-not-type-external.cppm
Normal file
27
clang/test/Modules/external-but-not-type-external.cppm
Normal file
@ -0,0 +1,27 @@
|
||||
// RUN: rm -rf %t
|
||||
// RUN: split-file %s %t
|
||||
// RUN: cd %t
|
||||
//
|
||||
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
|
||||
// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
|
||||
|
||||
//--- a.cppm
|
||||
export module a;
|
||||
namespace {
|
||||
struct Local {};
|
||||
}
|
||||
|
||||
export class A {
|
||||
public:
|
||||
void *external_but_not_type_external(Local *) {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
//--- use.cc
|
||||
// expected-no-diagnostics
|
||||
import a;
|
||||
void *use() {
|
||||
A a;
|
||||
return a.external_but_not_type_external(nullptr);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user