[clang][AST] Improve diagnostic for `nullptr` constexpr function pointer call
authorTakuya Shimizu <shimizu2486@gmail.com>
Mon, 13 Mar 2023 16:53:12 +0000 (12:53 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 13 Mar 2023 16:53:12 +0000 (12:53 -0400)
commit6b48d202ef497f4d512c382fe0db8c5ad3a72faa
treed763be3b880f9730da611f78d9e470322545f23d
parentacab6a70fb40cc7d363bee047ef0a250416b77ad
[clang][AST] Improve diagnostic for `nullptr` constexpr function pointer call

This patch improves diagnostic for clang constexpr evaluator by adding
a check for nullptr in function pointer call evaluations.

ex.
```
constexpr int foo(int (*bla)(void)) {
  return bla();
}

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

BEFORE this patch, clang generates the following diagnostic for the
code above:

```
<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.
```

AFTER this patch, subexpression not valid in a constant expression note
is replaced with 'bla' evaluates to a null function pointer.

Fixes https://github.com/llvm/llvm-project/issues/59872
Differential Revision: https://reviews.llvm.org/D145793
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp