Author: Timm Baeder Date: 2025-01-17T12:58:15+01:00 New Revision: 7075eee6bd0d445aa3f58ace314f7d12756c3e38
URL: https://github.com/llvm/llvm-project/commit/7075eee6bd0d445aa3f58ace314f7d12756c3e38 DIFF: https://github.com/llvm/llvm-project/commit/7075eee6bd0d445aa3f58ace314f7d12756c3e38.diff LOG: [clang][bytecode] Add InitLinkScope for toplevel Expr temporary (#123319) Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/test/AST/ByteCode/cxx20.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 4bfb80589620c1..6677119d092119 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4247,6 +4247,7 @@ bool Compiler<Emitter>::visitExpr(const Expr *E, bool DestroyToplevelScope) { // For us, that means everything we don't // have a PrimType for. if (std::optional<unsigned> LocalOffset = this->allocateLocal(E)) { + InitLinkScope<Emitter> ILS(this, InitLink::Temp(*LocalOffset)); if (!this->emitGetPtrLocal(*LocalOffset, E)) return false; diff --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp index 268362ceff635b..268226a7c143ed 100644 --- a/clang/test/AST/ByteCode/cxx20.cpp +++ b/clang/test/AST/ByteCode/cxx20.cpp @@ -893,3 +893,18 @@ namespace VirtDtor { static_assert(test('C', 'B')); } + +namespace TemporaryInNTTP { + template<auto n> struct B { /* ... */ }; + struct J1 { + J1 *self=this; + }; + /// FIXME: The bytecode interpreter emits a diff erent diagnostic here. + /// The current interpreter creates a fake MaterializeTemporaryExpr (see EvaluateAsConstantExpr) + /// which is later used as the LValueBase of the created APValue. + B<J1{}> j1; // ref-error {{pointer to temporary object is not allowed in a template argument}} \ + // expected-error {{non-type template argument is not a constant expression}} \ + // expected-note {{pointer to temporary is not a constant expression}} \ + // expected-note {{created here}} + B<2> j2; /// Ok. +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits