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

    <tr>
        <th>Summary</th>
        <td>
            Clang complains about non-constant expressions in static constinit initialization when such code is not executed
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Sorry about the title I'm not really sure how to describe this.

Testcase:

```
class Inner {
   public:
 constexpr bool is_constant_evaluated() const {
 if(__builtin_is_constant_evaluated()) {
            return true;
 } else {
            volatile int x = 0;
            return (x == 1);
         }
      }

      constexpr Inner() {}
};

class Outer {
   public:
      static const constexpr auto A = Inner();

      // If constexpr, no warning
      // If constinit, warns
      static const constinit bool A_is_constant_evaluated = A.is_constant_evaluated();
};

static_assert(Outer::A_is_constant_evaluated == true);
```

Compiling this with `-Wpedantic -std=c++20`, clang 17.0.6 complains

```
eval.cpp:9:21: warning: in-class initializer for static data member is not a constant expression; folding it to a constant is a GNU extension [-Wgnu-folding-constant]
    9 |             return (x == 1);
```

GCC and MSVC both accept this without any warnings.

This warning makes no sense because first this code is in a `else` block where the `if` is guarded by `__builtin_is_constant_evaluated`. (`std::is_constant_evaluated` and `if constexpr` seem to have the same result.) Secondly it doesn't make sense since *if* Clang was invoking the code with the `else` block then `A_is_constant_evaluated` would be false. But the `static_assert` succeeds.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVcuO4jgU_RqzuSIKDhBYZBFA1erFzCxqZnqJHPuGeMqxkR9FMV8_shMg3VVdrUGllOKc-zjnPsyckyeNWJHVjqwOMxZ8Z2xlmRamb6SfNUZcq2dj7RVYY4IH3yF46RXCV0LLHrTxYJEpdQUXLEJnLuANCHTcygbBd9JlJD-QvB6ef6LznDkkRT09Jut8_EuvXDHn4KvWaIGUu-EQA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