[all-commits] [llvm/llvm-project] 6b48d2: [clang][AST] Improve diagnostic for `nullptr` cons...

Takuya Shimizu via All-commits all-commits at lists.llvm.org
Mon Mar 13 09:55:08 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6b48d202ef497f4d512c382fe0db8c5ad3a72faa
      https://github.com/llvm/llvm-project/commit/6b48d202ef497f4d512c382fe0db8c5ad3a72faa
  Author: Takuya Shimizu <shimizu2486 at gmail.com>
  Date:   2023-03-13 (Mon, 13 Mar 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/DiagnosticASTKinds.td
    M clang/lib/AST/ExprConstant.cpp
    M clang/test/SemaCXX/constant-expression-cxx11.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list