Author: Timm Bäder Date: 2024-07-24T12:11:06+02:00 New Revision: d36edf8146cfea9f0407e2fb26283297eb6a6ac4
URL: https://github.com/llvm/llvm-project/commit/d36edf8146cfea9f0407e2fb26283297eb6a6ac4 DIFF: https://github.com/llvm/llvm-project/commit/d36edf8146cfea9f0407e2fb26283297eb6a6ac4.diff LOG: [clang][Interp] Bail out on value dependent variable initializers Added: Modified: clang/lib/AST/Interp/Compiler.cpp clang/test/AST/Interp/literals.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index dbd2686b17f09..0455eec3f0145 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -3683,6 +3683,9 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, bool Topleve const Expr *Init = VD->getInit(); std::optional<PrimType> VarT = classify(VD->getType()); + if (Init && Init->isValueDependent()) + return false; + if (Context::shouldBeGloballyIndexed(VD)) { auto checkDecl = [&]() -> bool { bool NeedsOp = !Toplevel && VD->isLocalVarDecl() && VD->isStaticLocal(); diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index 2b8abf665b20d..815fb67b9bbfc 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -1307,3 +1307,15 @@ namespace VolatileReads { static_assert(b, ""); // both-error {{not an integral constant expression}} \ // both-note {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}} } +#if __cplusplus >= 201703L +namespace { + struct C { + int x; + }; + + template <const C *p> void f() { + const auto &[c] = *p; + &c; // both-warning {{expression result unused}} + } +} +#endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits