Skip to content

Commit

Permalink
[clang][Interp] Emit diagnostics if final ltor conversion fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Jul 20, 2024
1 parent d386a55 commit 0d26f65
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/AST/Interp/EvalEmitter.cpp
Original file line number Diff line number Diff line change
@@ -169,7 +169,9 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
return false;
// Never allow reading from a non-const pointer, unless the memory
// has been created in this evaluation.
if (!Ptr.isConst() && Ptr.block()->getEvalID() != Ctx.getEvalID())
if (!Ptr.isZero() && Ptr.isBlockPointer() &&
Ptr.block()->getEvalID() != Ctx.getEvalID() &&
(!CheckLoad(S, OpPC, Ptr, AK_Read) || !Ptr.isConst()))
return false;

if (std::optional<APValue> V =
8 changes: 8 additions & 0 deletions clang/test/AST/Interp/cxx11.cpp
Original file line number Diff line number Diff line change
@@ -152,3 +152,11 @@ void A::f(SortOrder order) {
return;
}
}

namespace FinalLtorDiags {
template<int*> struct A {}; // both-note {{template parameter is declared here}}
int k;
int *q = &k; // both-note {{declared here}}
A<q> c; // both-error {{non-type template argument of type 'int *' is not a constant expression}} \
// both-note {{read of non-constexpr variable 'q' is not allowed in a constant expression}}
}

0 comments on commit 0d26f65

Please sign in to comment.