[all-commits] [llvm/llvm-project] f4f725: [clang][bytecode] Give a discarded composite prval...

Yihan Wang via All-commits all-commits at lists.llvm.org
Thu Sep 17 04:41:31 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f4f7257be543b02dd786d0d2be7b18cce4d266db
      https://github.com/llvm/llvm-project/commit/f4f7257be543b02dd786d0d2be7b18cce4d266db
  Author: Yihan Wang <yronglin777 at gmail.com>
  Date:   2026-09-17 (Thu, 17 Sep 2026)

  Changed paths:
    M clang/lib/AST/ByteCode/Compiler.cpp
    M clang/test/AST/ByteCode/records.cpp

  Log Message:
  -----------
  [clang][bytecode] Give a discarded composite prvalue a result object (#219952)

A default member initializer can refer to previously initialized
subobjects, so `this` has to denote something while it is evaluated. A
discarded composite prvalue had no result object, so the interpreter
rejected code the legacy evaluator accepts:

```cpp
struct A { int &x; constexpr ~A() { x = 0; } };
struct B { int &x; const A &a = A{x}; };
constexpr int f() { int x = 1; B{x}; return x; }
constexpr int r = f(); // error: implicit use of 'this' pointer
static_assert(r == 0); // FXIME: 'r' shouble be 0, it's a bug in clang, see https://github.com/llvm/llvm-project/issues/85601.

```

https://godbolt.org/z/rb993Ef9d

This patch materialize a result object for a discarded composite prvalue
and initialize into it. A discarded list of primitive type keeps
discarding its initializers, as there is no object to establish there.

Also let an explicit initializer nested in a default member initializer
see the surrounding initializer's `this` reconstruction.

Signed-off-by: yronglin <yronglin777 at gmail.com>
Co-authored-by: Timm Bäder <tbaeder at redhat.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list