Author: Timm Bäder Date: 2024-06-13T06:55:07+02:00 New Revision: 64c9a1e1266ec7bc4c4896b2df116fa12dbacf15
URL: https://github.com/llvm/llvm-project/commit/64c9a1e1266ec7bc4c4896b2df116fa12dbacf15 DIFF: https://github.com/llvm/llvm-project/commit/64c9a1e1266ec7bc4c4896b2df116fa12dbacf15.diff LOG: [clang][Interp] Also revisit references to const types Neither isConstant() not isConstQualified() return true for these. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/cxx11.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 81a5296012b9a..77a1c64d40189 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -3948,9 +3948,17 @@ bool ByteCodeExprGen<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { // we haven't seen yet. if (Ctx.getLangOpts().CPlusPlus) { if (const auto *VD = dyn_cast<VarDecl>(D)) { + const auto typeShouldBeVisited = [&](QualType T) -> bool { + if (T.isConstant(Ctx.getASTContext())) + return true; + if (const auto *RT = T->getAs<ReferenceType>()) + return RT->getPointeeType().isConstQualified(); + return false; + }; + // Visit local const variables like normal. if ((VD->isLocalVarDecl() || VD->isStaticDataMember()) && - VD->getType().isConstant(Ctx.getASTContext())) { + typeShouldBeVisited(VD->getType())) { if (!this->visitVarDecl(VD)) return false; // Retry. diff --git a/clang/test/AST/Interp/cxx11.cpp b/clang/test/AST/Interp/cxx11.cpp index f06a5dd173cba..82b2727bbadbb 100644 --- a/clang/test/AST/Interp/cxx11.cpp +++ b/clang/test/AST/Interp/cxx11.cpp @@ -46,3 +46,19 @@ constexpr int preInc(int x) { // both-error {{never produces a constant expressi constexpr int postInc(int x) { // both-error {{never produces a constant expression}} return x++; // both-note {{subexpression}} } + + +namespace ReferenceToConst { + template<int n> struct S; // both-note 1{{here}} + struct LiteralType { + constexpr LiteralType(int n) : n(n) {} + int n; + }; + template<int n> struct T { + T() { + static const int ki = 42; + const int &i2 = ki; + typename S<i2>::T check5; // both-error {{undefined template}} + } + }; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits