[llvm-branch-commits] [clang] release/20.x: [clang][AST] Handle implicit first argument in CallExpr::getBeginLoc() (PR #135927)

Nathan Ridge via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 16 00:49:53 PDT 2025


https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/135927

Backport https://github.com/llvm/llvm-project/commit/289baf1f42c8b5773271b611cd235d4ab94bb4e8

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

>From a9ea5de20db3ff08d691856e7da5b185d438e228 Mon Sep 17 00:00:00 2001
From: Nathan Ridge <zeratul976 at hotmail.com>
Date: Tue, 15 Apr 2025 03:40:37 -0400
Subject: [PATCH] [clang][AST] Handle implicit first argument in
 CallExpr::getBeginLoc()

---
 clang/lib/AST/Expr.cpp                     | 7 +++++--
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 7 +++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 8571b617c70eb..a5b7ef8c4271b 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1665,8 +1665,11 @@ SourceLocation CallExpr::getBeginLoc() const {
         Method && Method->isExplicitObjectMemberFunction()) {
       bool HasFirstArg = getNumArgs() > 0 && getArg(0);
       assert(HasFirstArg);
-      if (HasFirstArg)
-        return getArg(0)->getBeginLoc();
+      if (HasFirstArg) {
+        if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
+          return FirstArgLoc;
+        }
+      }
     }
   }
 
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 6f17ce7275456..7e392213710a4 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1134,3 +1134,10 @@ struct S {
 static_assert((S{} << 11) == a);
 // expected-error at -1 {{use of undeclared identifier 'a'}}
 }
+
+namespace GH135522 {
+struct S {
+  auto f(this auto) -> S;
+  bool g() { return f(); } // expected-error {{no viable conversion from returned value of type 'S' to function return type 'bool'}}
+};
+}



More information about the llvm-branch-commits mailing list