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

    <tr>
        <th>Summary</th>
        <td>
            __builtin_constant_p not correctly diagnosing compile time constants for constexpr char[] values
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            c++
      </td>
    </tr>

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

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

<pre>
    `__builtin_constant_p()` returns false on constexpr char arrays, i.e.:

```
const char* constant_string;
const char* dynamic_string;

int constant_int;
int dynamic_int;

inline void AcceptString(const char* s) {
    dynamic_string = s;
}
inline void AcceptString(const char* s) 
  __attribute__((enable_if(__builtin_constant_p(s) && s[0], ""))) {
    constant_string = s;
}

constexpr const char* foo1 = "Hello world";
constexpr const char foo2[] = "Hello world";

void Foo0() { AcceptString("Hello world"); }
void Foo1() { AcceptString(foo1); }
void Foo2() { AcceptString(foo2); }
```

In the above code, `Foo2()` returns 0. IMHO all of the above should return 1 as both the value of `s` as well as it contents (and lifetime) are all well known at compile time.

Context: building a function that fully expands inline / optimizes for compile time known string values with indefinite lifetime
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVM2OozgQfhpzKU0EBSFw4NDpKJo5rPawD4AMlINnHTuyTbqzT7-yIZ2f6d6VRrKMjOv7yl_9cefkQRM1bL1l613CJz8a2xy59fKnPpNySWeGS8PKtG27SSovddsb7TzXvj0xrBjWrEzBkp-sdiC4cgRGQzSi95OFfuQWuLX84hi-glzRiuUvLN2x9LqX6bLiMUIjjOELfHhz3kp9YPn2M6vhovlR9s9G8y61v9FI7T-uw8UVef__equkJjgbOcBL39PJ_zWzY_Xo3DGsgW0WMAA8PQdYvgN3Y9_sfsvBwt623Hsru8lT28YMVKR5p6iVgmH1RZ5mCiwZluDYepuy9S6kgyHGVc_rUcZT7L_ScZeQOeMPjxfGZBHJEL-TUgbejFVD8PqQyydowOFclv-DnvcYxb0x6VyUQchzUH-lwJrlW_gQcuXIvuYQ8fZzGP4n7BdvT2U_7z80-JGAd-ZM0JuBYpLK9EZ_327pCn788f1P4EqBEXdIN5pJDYsdZMAddMaP0eLM1UTBnJWpC2zcwRspFb4ydoon7R0wrLgeQElBXh4pKOOWoq9o_rc2bxp4QBxPUhEEq9W9mNdA9e5Z_gKhKIdQQxzEpHsvTRDKPYhJqQvQ-4nrwcHSEgz3YE5eHuU_5EAY--Bj8bwUZZTj4E36EaQeSEgtPX08OxmafKjzmifUZGWFeVEhbpKxqYdaVDllVdVV66LPSGR5T0JwIZDTpkpkgynmaYFFVqw36WaVZf2mGDaFKCnri65mRUpHLtVKqfNxZewhkc5N1JSY52mieEfKxcmK2Cse6gAZvoYTw21cGIaubQL-WzcdHCtSJZ13N0YvvaLms6YGbULoraXeqwsMkh-0cSEiD7G6Aq5hvB_LS3vNEUwmq5rR-5ML4xn3DPcH6cepW_XmyHAfnrR8vp2s-Um9Z7iPih3DfRT9bwAAAP__4RH5-g">