Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/20.x
Choose a base branch
from

Conversation

HighCommander4
Copy link
Collaborator

Backport 289baf1

Fixes #135922

@HighCommander4 HighCommander4 added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Apr 16, 2025
@HighCommander4 HighCommander4 added this to the LLVM 20.X Release milestone Apr 16, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Apr 16, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 16, 2025
@HighCommander4 HighCommander4 requested a review from zyn0217 April 16, 2025 07:50
@llvmbot
Copy link
Member

llvmbot commented Apr 16, 2025

@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)

Changes

Backport 289baf1

Fixes #135922


Full diff: https://github.com/llvm/llvm-project/pull/135927.diff

2 Files Affected:

  • (modified) clang/lib/AST/Expr.cpp (+5-2)
  • (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+7)
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@-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'}}
+};
+}

@HighCommander4 HighCommander4 requested a review from cor3ntin April 16, 2025 07:50
@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Apr 16, 2025
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
Status: Needs Merge
Development

Successfully merging this pull request may close these issues.

4 participants