Skip to content

Commit d36edf8

Browse files
committed
[clang][Interp] Bail out on value dependent variable initializers
1 parent f0bd705 commit d36edf8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/AST/Interp/Compiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,6 +3683,9 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, bool Topleve
36833683
const Expr *Init = VD->getInit();
36843684
std::optional<PrimType> VarT = classify(VD->getType());
36853685

3686+
if (Init && Init->isValueDependent())
3687+
return false;
3688+
36863689
if (Context::shouldBeGloballyIndexed(VD)) {
36873690
auto checkDecl = [&]() -> bool {
36883691
bool NeedsOp = !Toplevel && VD->isLocalVarDecl() && VD->isStaticLocal();

clang/test/AST/Interp/literals.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,3 +1307,15 @@ namespace VolatileReads {
13071307
static_assert(b, ""); // both-error {{not an integral constant expression}} \
13081308
// both-note {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}}
13091309
}
1310+
#if __cplusplus >= 201703L
1311+
namespace {
1312+
struct C {
1313+
int x;
1314+
};
1315+
1316+
template <const C *p> void f() {
1317+
const auto &[c] = *p;
1318+
&c; // both-warning {{expression result unused}}
1319+
}
1320+
}
1321+
#endif

0 commit comments

Comments
 (0)