llvm-project/clang/test/AST/static-compound-literals.cpp
kadir çetinkaya f72e53f350
[clang][CompundLiteralExpr] Don't defer evaluation for CLEs (#137163)
Previously we would defer evaluation of CLEs until LValue to RValue
conversions, which would result in creating values within wrong scope
and triggering use-after-frees.

This patch instead eagerly evaluates CLEs, within the scope requiring
them. This requires storing an extra pointer for CLE expressions with
static storage.

Fixes https://github.com/llvm/llvm-project/issues/137165
2025-07-08 16:00:40 +02:00

13 lines
305 B
C++

// Test that we can successfully compile this code, especially under ASAN.
// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
// expected-no-diagnostics
struct Foo {
Foo* f;
operator bool() const { return true; }
};
constexpr Foo f((Foo[]){});
int foo() {
if (Foo(*f.f)) return 1;
return 0;
}