<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60936>60936</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Aggregate construction of an lvalue class object not considered constant expression
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          danakj
      </td>
    </tr>
</table>

<pre>
    Construction as an rvalue works, but not as an lvalue.

https://godbolt.org/z/r3d17jMjM

```cpp
struct S {
    // Clang cant constexpr construct this as an lvalue without the constructor.
    // constexpr S(int i) : i(i) {}

    int i;
 int *p = &i;
    constexpr const int* ptr() const { return &i; }
};

// Not constant expression in GCC.
static_assert(S{2}.ptr() != nullptr);
static_assert(S{2}.p != nullptr);

// Is a constant expression.
static_assert(*S{2}.ptr() == 2);
static_assert(*S{2}.p == 2);

static_assert([]() constexpr {
    // Not a constant expression in Clang without a user-defined constructor.
    auto r = S{2};

 // Is a constant expression.
    return r.ptr() != nullptr && r.p != nullptr;
}());
```

Generates a compiler error that the lambda is not a constant expression.

Uncommenting the constructor in S makes the example compile. GCC and MSVC accept this without the constructor.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMlE9v6zYMwD8NfSFq2HJqJQcf0gR52KG7BNt1kC3WUStLhiS_vu3TD7KS5s-SYkAi2-K_n0iKwnvVG6IGnl_geZuJKRysa6Qw4uM9a638u9lY44ObuqCsQeFRGHQ_hZ4IP6378MA22E4BjQ1HqZ6lORRbKNZpPYQweqjWwHbAdr2VrdUht64HtvsH2M5VsuTvr--vl0ZQF-nXjWPaSRy4R-AvaQcRMTnFjRamx06YgF1Epl-jS2-zUTgofwWInyoc7BQldNazLv-P57O7PbClMgEVsBVCtY4vy_TBX4BvL_Gjg6RbnWDjJ7D1iFBtEVh9IUK8pY7awNY4BgdsGWOkbeAv6ChMzpxc4Dky3365PK7pCL_bY1ZiemIM8j7WUxn8sdnkp_SKoLq_hPfkArDlHvgLA77NzwjAyshuJq3nzdVXuMfG3xhdMf7mUdyDfEAHbH0PsNrGWOw7tCvLuxYP7OY7clmMuVr3mjHm--5hYsZTp57aT-DkyT1JelOG5INOFFOw6Oa-OaHfwOL_y2J0duwe97CusbGA1VHjtnhfQfkxEVdpO93YS7AfZMiJQIlrGJUmh-ScdRgOIl0_LYZWClQ-jZFv-NP6h-nsMJAJyvS39zdmeI-D-CA_i-iXGEZNp9h5bHgURuLr_s8Niq6j8TgdHg2ETDaVXFUrkVFT1pyX5fJ5xbNDw0tRlJKvqFqJqiNZt7V8ZrVcyEJUbx3LVMMKVhUs_su64jlfyAWVi66gxXLBZQmLggahdK71zyEOxEx5P1FTF6uqzrRoSft5NjNm6BNnITAWR7Vros1TO_UeFoVWPvizl6CCpmbd9456ES6OE1vQvl1MwU4L79G279SlIR5VlSR36sXrMmST083NOFfhMLV5Zwdgu0hwfDyNzkavwHYztwe2m8_1bwAAAP__lrz4ow">