https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/206456

Also fix this test to not have absolute line numbers

>From 6cb41c3afa74e1c43c79e6530c5702979e13d0b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Mon, 29 Jun 2026 12:46:41 +0200
Subject: [PATCH] [clang][ExprConst] Add a source range to invalid cast
 diagnostics

Also fix this test to not have absolute line numbers
---
 clang/lib/AST/ExprConstant.cpp              |  2 +-
 clang/test/Misc/constexpr-source-ranges.cpp | 22 ++++++++++++++-------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 1d359339b9104..69ce0c712db67 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9299,7 +9299,7 @@ class LValueExprEvaluator
     case CK_LValueBitCast:
       this->CCEDiag(E, diag::note_constexpr_invalid_cast)
           << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
-          << Info.Ctx.getLangOpts().CPlusPlus;
+          << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
       if (!Visit(E->getSubExpr()))
         return false;
       Result.Designator.setInvalid();
diff --git a/clang/test/Misc/constexpr-source-ranges.cpp 
b/clang/test/Misc/constexpr-source-ranges.cpp
index fde05b5c75aa4..44674b16885e4 100644
--- a/clang/test/Misc/constexpr-source-ranges.cpp
+++ b/clang/test/Misc/constexpr-source-ranges.cpp
@@ -5,14 +5,12 @@ constexpr int f() {
   throw 1;
   return 0;
 }
-
-// CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}
-
+// CHECK: :[[@LINE-3]]:3:{[[@LINE-3]]:3-[[@LINE-3]]:10}
 
 constexpr int I = 12;
 constexpr const int *P = &I;
 constexpr long L = (long)P;
-// CHECK: constexpr-source-ranges.cpp:14:20:{14:20-14:27}
+// CHECK: :[[@LINE-1]]:20:{[[@LINE-1]]:20-[[@LINE-1]]:27}
 
 constexpr int zero() {
   return 0;
@@ -23,8 +21,8 @@ constexpr int divByZero() {
 static_assert(divByZero() == 0, "");
 /// We see this twice. Once from sema and once when
 /// evaluating the static_assert above.
-// CHECK: constexpr-source-ranges.cpp:23:15:{23:15-23:31}
-// CHECK: constexpr-source-ranges.cpp:21:12:{21:14-21:20}
+// CHECK: :[[@LINE-5]]:12:{[[@LINE-5]]:14-[[@LINE-5]]:20}
+// CHECK: :[[@LINE-4]]:15:{[[@LINE-4]]:15-[[@LINE-4]]:31}
 
 constexpr int div(bool a, bool b) {
   return 1 / (int)b;
@@ -33,7 +31,7 @@ constexpr int ints(int a, int b, int c, int d) {
   return 1;
 }
 static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, "");
-// CHECK: constexpr-source-ranges.cpp:35:23:{35:23-35:39}
+// CHECK: :[[@LINE-1]]:23:{[[@LINE-1]]:23-[[@LINE-1]]:39}
 
 namespace overflow {
 // CHECK:      :{[[@LINE+1]]:9-[[@LINE+1]]:29}:
@@ -53,3 +51,13 @@ static_assert(uninit() == 0, "");
 
 constexpr void neverValid() { throw; }
 // CHECK: :{[[@LINE-1]]:16-[[@LINE-1]]:26}:
+
+struct B1  {};
+struct C  {};
+constexpr C c;
+// CHECK: :[[@LINE+1]]:15:{[[@LINE+1]]:15-[[@LINE+1]]:18}
+constexpr int foo() {
+  auto p = (B1&)c;
+  return 1;
+}
+// CHECK: :[[@LINE-3]]:12:{[[@LINE-3]]:12-[[@LINE-3]]:18}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to