[clang] [Clang] Back out the source location workaround for CXXConstructExpr (PR #145260)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 22 21:41:25 PDT 2025


https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/145260

This removes the workaround introduced in 3e1a9cf3b8 and 1ba7dc38d.

The issues should have been already resolved elsewhere, at least removing these lines doesn't break any existing tests.

The workaround overwrote the right parenthesis location of the sub expression, which could be wrong when a CXXTemporaryObjectExpr occurs within a nested expression, e.g. `A(A(1, 2))`.

Fixes https://github.com/llvm/llvm-project/issues/143711

>From d1d0993ceb5de1c60d2e0b1fae85c511914d112d Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Mon, 23 Jun 2025 12:31:39 +0800
Subject: [PATCH] [Clang] Back out the source location workaround for
 CXXConstructExpr

This removes the workaround introduced in 3e1a9cf3b8 and 1ba7dc38d.

The issues should have been already resolved elsewhere, at least removing
these lines doesn't break any existing tests.

The workaround overwrote the right parenthesis location of the sub
expression, which could be wrong when a CXXTemporaryObjectExpr occurs
within a nested expression, e.g. `A(A(1, 2))`.
---
 clang/docs/ReleaseNotes.rst      |  1 +
 clang/lib/Sema/SemaCast.cpp      |  6 ------
 clang/test/AST/ast-dump-expr.cpp | 10 ++++++++++
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 96477ef6ddc9a..7822a9a6c3cc6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -877,6 +877,7 @@ Bug Fixes to AST Handling
 - Fixed a malformed printout of ``CXXParenListInitExpr`` in certain contexts.
 - Fixed a malformed printout of certain calling convention function attributes. (#GH143160)
 - Fixed dependency calculation for TypedefTypes (#GH89774)
+- Fixed the right parenthesis source location of ``CXXTemporaryObjectExpr``. (#GH143711)
 
 Miscellaneous Bug Fixes
 ^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index e15a43c116516..625843b0b9a48 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -3451,12 +3451,6 @@ ExprResult Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo,
 
   Op.checkQualifiedDestType();
 
-  auto *SubExpr = Op.SrcExpr.get();
-  if (auto *BindExpr = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
-    SubExpr = BindExpr->getSubExpr();
-  if (auto *ConstructExpr = dyn_cast<CXXConstructExpr>(SubExpr))
-    ConstructExpr->setParenOrBraceRange(SourceRange(LPLoc, RPLoc));
-
   // -Wcast-qual
   DiagnoseCastQual(Op.Self, Op.SrcExpr, Op.DestType);
 
diff --git a/clang/test/AST/ast-dump-expr.cpp b/clang/test/AST/ast-dump-expr.cpp
index 2efd0b5e8ac21..8ccb39f8f3165 100644
--- a/clang/test/AST/ast-dump-expr.cpp
+++ b/clang/test/AST/ast-dump-expr.cpp
@@ -589,3 +589,13 @@ void leakNewFn() { new struct Sock; }
 // CHECK: CXXNewExpr {{.*}} <col:20, col:31> 'struct Sock *'
 }
 
+namespace GH143711 {
+struct S {
+  S(int, int);
+};
+
+void f() {
+  S(S(0, 1));
+}
+// CHECK: CXXTemporaryObjectExpr {{.*}} <col:5, col:11> 'S':'GH143711::S' 'void (int, int)'
+}



More information about the cfe-commits mailing list