Skip to content

Commit 0d26f65

Browse files
committed
[clang][Interp] Emit diagnostics if final ltor conversion fails
1 parent d386a55 commit 0d26f65

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/AST/Interp/EvalEmitter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
169169
return false;
170170
// Never allow reading from a non-const pointer, unless the memory
171171
// has been created in this evaluation.
172-
if (!Ptr.isConst() && Ptr.block()->getEvalID() != Ctx.getEvalID())
172+
if (!Ptr.isZero() && Ptr.isBlockPointer() &&
173+
Ptr.block()->getEvalID() != Ctx.getEvalID() &&
174+
(!CheckLoad(S, OpPC, Ptr, AK_Read) || !Ptr.isConst()))
173175
return false;
174176

175177
if (std::optional<APValue> V =

clang/test/AST/Interp/cxx11.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,11 @@ void A::f(SortOrder order) {
152152
return;
153153
}
154154
}
155+
156+
namespace FinalLtorDiags {
157+
template<int*> struct A {}; // both-note {{template parameter is declared here}}
158+
int k;
159+
int *q = &k; // both-note {{declared here}}
160+
A<q> c; // both-error {{non-type template argument of type 'int *' is not a constant expression}} \
161+
// both-note {{read of non-constexpr variable 'q' is not allowed in a constant expression}}
162+
}

0 commit comments

Comments
 (0)