Skip to content

Commit 92fe391

Browse files
committed
[clang][Interp] Reject non-pointer typed dummies
This happens a lot for NonTypeTemplateParm decls.
1 parent 77d2283 commit 92fe391

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

clang/lib/AST/Interp/Compiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5094,9 +5094,10 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
50945094
if (E->getType()->isVoidType())
50955095
return true;
50965096
// Convert the dummy pointer to another pointer type if we have to.
5097-
if (PrimType PT = classifyPrim(E); PT != PT_Ptr && isPtrType(PT)) {
5098-
if (!this->emitDecayPtr(PT_Ptr, PT, E))
5099-
return false;
5097+
if (PrimType PT = classifyPrim(E); PT != PT_Ptr) {
5098+
if (isPtrType(PT))
5099+
return this->emitDecayPtr(PT_Ptr, PT, E);
5100+
return false;
51005101
}
51015102
return true;
51025103
}

clang/test/AST/Interp/literals.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,3 +1276,17 @@ namespace ComparisonAgainstOnePastEnd {
12761276

12771277
static_assert(&a + 1 == &b + 1, ""); // both-error {{static assertion failed}}
12781278
};
1279+
1280+
namespace NTTP {
1281+
template <typename _Tp, unsigned _Nm>
1282+
constexpr unsigned
1283+
size(const _Tp (&)[_Nm]) noexcept
1284+
{ return _Nm; }
1285+
1286+
template <char C>
1287+
static int write_padding() {
1288+
static const char Chars[] = {C};
1289+
1290+
return size(Chars);
1291+
}
1292+
}

0 commit comments

Comments
 (0)