[clang] [clang][Diagnostics] Provide source range to constexpr function diags (PR #69721)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 20 06:17:48 PDT 2023
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/69721
Before:
```console
./array.cpp:290:16: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
290 | constexpr void neverValid() {
| ^
./array.cpp:291:3: note: subexpression not valid in a constant expression
291 | throw;
| ^~~~~
```
After:
```console
./array.cpp:290:16: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
290 | constexpr void neverValid() {
| ^~~~~~~~~~
./array.cpp:291:3: note: subexpression not valid in a constant expression
291 | throw;
| ^~~~~
```
>From d1ec520893fae9667dd0691ae40609d1bc0bc8ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 20 Oct 2023 15:14:06 +0200
Subject: [PATCH] [clang][Diagnostics] Provide source range to constexpr
function diags
Before:
./array.cpp:290:16: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
290 | constexpr void neverValid() {
| ^
./array.cpp:291:3: note: subexpression not valid in a constant expression
291 | throw;
| ^~~~~
After:
./array.cpp:290:16: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
290 | constexpr void neverValid() {
| ^~~~~~~~~~
./array.cpp:291:3: note: subexpression not valid in a constant expression
291 | throw;
| ^~~~~
---
clang/lib/Sema/SemaDeclCXX.cpp | 3 ++-
clang/test/Misc/constexpr-source-ranges.cpp | 4 ++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0193e476b3a781b..1d24609d99718ab 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2457,7 +2457,8 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl,
!Expr::isPotentialConstantExpr(Dcl, Diags)) {
SemaRef.Diag(Dcl->getLocation(),
diag::ext_constexpr_function_never_constant_expr)
- << isa<CXXConstructorDecl>(Dcl) << Dcl->isConsteval();
+ << isa<CXXConstructorDecl>(Dcl) << Dcl->isConsteval()
+ << Dcl->getNameInfo().getSourceRange();
for (size_t I = 0, N = Diags.size(); I != N; ++I)
SemaRef.Diag(Diags[I].first, Diags[I].second);
// Don't return false here: we allow this for compatibility in
diff --git a/clang/test/Misc/constexpr-source-ranges.cpp b/clang/test/Misc/constexpr-source-ranges.cpp
index 7f5c522ae305b54..fde05b5c75aa46a 100644
--- a/clang/test/Misc/constexpr-source-ranges.cpp
+++ b/clang/test/Misc/constexpr-source-ranges.cpp
@@ -49,3 +49,7 @@ constexpr int uninit() {
return aaa;
}
static_assert(uninit() == 0, "");
+
+
+constexpr void neverValid() { throw; }
+// CHECK: :{[[@LINE-1]]:16-[[@LINE-1]]:26}:
More information about the cfe-commits
mailing list