llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> They aren't valid, but we leave them successful here and CheckLValueConstantExpression will diagnose them later. --- Full diff: https://github.com/llvm/llvm-project/pull/151980.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+8) - (modified) clang/test/AST/ByteCode/cxx11.cpp (+7) ``````````diff diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index fd7f3423c0f9b..408688c21fc5b 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -233,6 +233,14 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) { return false; } } else { + // If this is pointing to a local variable, just return + // the result, even if the pointer is dead. + // This will later be diagnosed by CheckLValueConstantExpression. + if (Ptr.isBlockPointer() && !Ptr.block()->isStatic()) { + EvalResult.setValue(Ptr.toAPValue(Ctx.getASTContext())); + return true; + } + if (!Ptr.isLive() && !Ptr.isTemporary()) return false; diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 8a125a497c649..f5a2abbbe7813 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -301,4 +301,11 @@ namespace NonConstLocal { } } +#define ATTR __attribute__((require_constant_initialization)) +int somefunc() { + const int non_global = 42; // both-note {{declared here}} + ATTR static const int &local_init = non_global; // both-error {{variable does not have a constant initializer}} \ + // both-note {{required by}} \ + // both-note {{reference to 'non_global' is not a constant expression}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/151980 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits