Skip to content

Commit 64c9a1e

Browse files
committed
[clang][Interp] Also revisit references to const types
Neither isConstant() not isConstQualified() return true for these.
1 parent f941908 commit 64c9a1e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3948,9 +3948,17 @@ bool ByteCodeExprGen<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
39483948
// we haven't seen yet.
39493949
if (Ctx.getLangOpts().CPlusPlus) {
39503950
if (const auto *VD = dyn_cast<VarDecl>(D)) {
3951+
const auto typeShouldBeVisited = [&](QualType T) -> bool {
3952+
if (T.isConstant(Ctx.getASTContext()))
3953+
return true;
3954+
if (const auto *RT = T->getAs<ReferenceType>())
3955+
return RT->getPointeeType().isConstQualified();
3956+
return false;
3957+
};
3958+
39513959
// Visit local const variables like normal.
39523960
if ((VD->isLocalVarDecl() || VD->isStaticDataMember()) &&
3953-
VD->getType().isConstant(Ctx.getASTContext())) {
3961+
typeShouldBeVisited(VD->getType())) {
39543962
if (!this->visitVarDecl(VD))
39553963
return false;
39563964
// Retry.

clang/test/AST/Interp/cxx11.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,19 @@ constexpr int preInc(int x) { // both-error {{never produces a constant expressi
4646
constexpr int postInc(int x) { // both-error {{never produces a constant expression}}
4747
return x++; // both-note {{subexpression}}
4848
}
49+
50+
51+
namespace ReferenceToConst {
52+
template<int n> struct S; // both-note 1{{here}}
53+
struct LiteralType {
54+
constexpr LiteralType(int n) : n(n) {}
55+
int n;
56+
};
57+
template<int n> struct T {
58+
T() {
59+
static const int ki = 42;
60+
const int &i2 = ki;
61+
typename S<i2>::T check5; // both-error {{undefined template}}
62+
}
63+
};
64+
}

0 commit comments

Comments
 (0)