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

    <tr>
        <th>Summary</th>
        <td>
            `__builtin_constant_p` fails/behaves differently from GCC
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          h-2
      </td>
    </tr>
</table>

<pre>
    ```cpp
#include <type_traits>

#define IS_CONSTEXPR(...) std::integral_constant<bool, __builtin_constant_p((__VA_ARGS__, 0))>::value

struct S
{
    int i = 0;

    constexpr S & assign_int(int j)
    {
        i = j;
        return *this;
    }
};

inline constexpr auto s = S{}.assign_int(3);    // works
static_assert(IS_CONSTEXPR(S{}.assign_int(3))); // fails in clang, passes in GCC
```

The macro `IS_CONSTEXPR` can check whether a wide variety of expressions are well-formed in a const context.  I know that `__builtin_constant_p` is non-standard, but based on the documentation, I assume that clang's implementation is supposed to behave like GCC's. In this case, it does not.

I don't know whether this is just a deficiency of the builtin, or whether this also means clang is less likely to evaluate such expressions at compile time (when not required).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VE2P2zgM_TX2hRjDI0_s5OBDPtoil91FUyx6M2SbjjWjSK4kT3b-_ZJKMp0Uuw2E2BHJ9x6fqLS2f6uTMr-sbpqSfJfk60QUynR67hGSYhveJmyCkyr4pPh0zbjl9Tgog7A_NNs__zh8-_T9r6-JWGZZlogV-NAnxZqWMgGPTuqms8YHaQLBttbqRGyhadpZ6aDMe7CZCIJW0_y9btZfvxyahhNzguRFGiLoq9QzfpTjg5u7AIfrXrW5vAB9SAAoamZHKMXmYxFHIzH-Mzk4QCJKkN6ro2moiFRw6TPzvqffIUf0iPz8jnzbdxhmZwhyHUbl78JJtbvJ3P2iSBnNlv4UJedgwUeOA3NXu-xOYRFd2URY8ZkWnK178TdTZFBdQwXoOP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