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

    <tr>
        <th>Summary</th>
        <td>
            Calling `nullptr` function pointer in a constexpr function results in poor diagnostic
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:frontend,
            clang:diagnostics
      </td>
    </tr>

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

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

<pre>
    See: https://godbolt.org/z/EY7f6M5bE

```c++
constexpr int foo(int (*bla)(void)) {
  return bla();
}

static_assert(foo(nullptr) == 1);
```

Output:
```console
<source>:5:15: error: static assertion expression is not an integral constant expression
static_assert(foo(nullptr) == 1);
 ^~~~~~~~~~~~~~~~~
<source>:2:10: note: subexpression not valid in a constant expression
  return bla();
         ^
<source>:5:15: note: in call to 'foo(nullptr)'
static_assert(foo(nullptr) == 1);
 ^
1 error generated.
```

"subexpression not valid in a constant expression" is a pretty poor diagnostic for this case. When passing a non-constexpr function to `foo()`, clang manages to print a proper diagnostic:

```console
<source>:9:15: error: static assertion expression is not an integral constant expression
static_assert(foo(f) == 1);
              ^~~~~~~~~~~
<source>:6:10: note: non-constexpr function 'f' cannot be used in a constant expression
  return bla();
 ^
<source>:9:15: note: in call to 'foo(&f)'
static_assert(foo(f) == 1);
              ^
<source>:2:5: note: declared here
int f() { return 1; }
    ^
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU2P4zYM_TX0hZhApuOvgw-ZSXIreuih6KmQbdpRoUiGJA-6PfS3F3KS5qOb3SkGWMFwCFMRHx8fKem9Gg1zA_kr5NtEzuFgXRNayT07l7S2_9L8wgzZBg8hTB6yDdAeaD_avrU6rKwbgfZ_Ae13v5VD8VPe7kBsQWzO70Kcng7oNT7L184aH_jPyaEyAQdrgapoAVVAm1ZLoBqoereqX6waoTz_FdFxmJ3BZVcV3dnZBeX2NrQPMqjud-k9uwBUncKYWespuOXMbAvZFtO7My54b0_6eQ7THGLqDzlZ463m89fszdvZdQzZDrJNDtkmjS9k56yLxgkQngApazAywN5HU3k0NqA0kREendS4kCRNuNn2icQQ8t3fD-urwCkCFxGvsWEpvJ_bG6QR5rvUqkdlUD5H-Y1C4WVBvvsOeRcMymAntcZgEah8zBio_CQ1Jys9FQtHNuxk4H71DVUA0f9mhihWWuLkOIQvOFnrsFdyNNZHaQzWYTgoj530vMJfD2xwij1qRpRorHm5ds4wm25RUaSkEKdMY1qFAHrDTksz4lEaObKPeyYXOyyGthPfRr3q-uPqrn-0uoenxbtbdyL_KvLiP_J-QmuUGVCJnTQRe8s4e_6M6J-Jvf6Q2IGK4ftK_zhNT3v_DknPnZaOezywOythmdin3OJUviScQvaK_07g-yAXRSV9k_V1VsuEm7Qos1QURZ4mh6YsBa3bYujTsh0GWZeFqAfqRdm39TpPOVENCcpEKso0z0WerlhwLaTo8rKqBK0rWAs-SqVXWr8f46WUKO9nbvK6KinRsmXtl0uOaIidAdlmcNYENj0QAb0BUXd2XFvDR1--TVwTj31p59HDWmjlg78GCipobt6k1rFNoRCXcVOIq5omG5XvbuRzrzbHftbBR__DUEhmp5uHu1eFw9yuOnsE2kcc55-Xydk_uAtA-yV7D7RfCPgnAAD__63cY4U">