Skip to content

Commit 4476913

Browse files
committed
[clang][Interp] Don't suppress diagnostics for undefined+external funcs
Calling them should still generate a diagnostic.
1 parent 4f69c4b commit 4476913

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
485485
// Don't emit anything if the function isn't defined and we're checking
486486
// for a constant expression. It might be defined at the point we're
487487
// actually calling it.
488-
if (!DiagDecl->isDefined() && S.checkingPotentialConstantExpression())
488+
bool IsExtern = DiagDecl->getStorageClass() == SC_Extern;
489+
if (!DiagDecl->isDefined() && !IsExtern &&
490+
S.checkingPotentialConstantExpression())
489491
return false;
490492

491493
// If the declaration is defined _and_ declared 'constexpr', the below

clang/test/AST/Interp/records.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,3 +1238,9 @@ namespace InvalidCtorInitializer {
12381238
// no crash on evaluating the constexpr ctor.
12391239
constexpr int Z = X().Y; // both-error {{constexpr variable 'Z' must be initialized by a constant expression}}
12401240
}
1241+
1242+
extern int f(); // both-note {{here}}
1243+
struct HasNonConstExprMemInit {
1244+
int x = f(); // both-note {{non-constexpr function}}
1245+
constexpr HasNonConstExprMemInit() {} // both-error {{never produces a constant expression}}
1246+
};

0 commit comments

Comments
 (0)