Skip to content

Commit

Permalink
[clang][Interp] Don't suppress diagnostics for undefined+external funcs
Browse files Browse the repository at this point in the history
Calling them should still generate a diagnostic.
  • Loading branch information
tbaederr committed Mar 15, 2024
1 parent 4f69c4b commit 4476913
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/AST/Interp/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
// Don't emit anything if the function isn't defined and we're checking
// for a constant expression. It might be defined at the point we're
// actually calling it.
if (!DiagDecl->isDefined() && S.checkingPotentialConstantExpression())
bool IsExtern = DiagDecl->getStorageClass() == SC_Extern;
if (!DiagDecl->isDefined() && !IsExtern &&
S.checkingPotentialConstantExpression())
return false;

// If the declaration is defined _and_ declared 'constexpr', the below
Expand Down
6 changes: 6 additions & 0 deletions clang/test/AST/Interp/records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,3 +1238,9 @@ namespace InvalidCtorInitializer {
// no crash on evaluating the constexpr ctor.
constexpr int Z = X().Y; // both-error {{constexpr variable 'Z' must be initialized by a constant expression}}
}

extern int f(); // both-note {{here}}
struct HasNonConstExprMemInit {
int x = f(); // both-note {{non-constexpr function}}
constexpr HasNonConstExprMemInit() {} // both-error {{never produces a constant expression}}
};

0 comments on commit 4476913

Please sign in to comment.