[clang] [clang][AST] Handle dependent representation of call to function with explicit object parameter in CallExpr::getBeginLoc() (PR #126868)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 23:28:17 PST 2025


================
@@ -1648,8 +1648,11 @@ SourceLocation CallExpr::getBeginLoc() const {
   if (const auto *Method =
           dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
       Method && Method->isExplicitObjectMemberFunction()) {
-    assert(getNumArgs() > 0 && getArg(0));
-    return getArg(0)->getBeginLoc();
+    if (!isTypeDependent()) {
+      assert(getNumArgs() > 0 && getArg(0));
+      if (getNumArgs() > 0 && getArg(0))
----------------
HighCommander4 wrote:

I agree with these arguments against checking an asserted condition **in general**.

However, I think in this case it might make sense, for two reasons:
 1. My level of confidence that "((callee is an explicit object member function) and (call is not dependent)) implies (call has a first argument)" is in fact an invariant is not very high.
 2. The impact of hiding a bug here is fairly low (slightly inaccurate source range, likely to only affect tools like clangd which perform hit-testing on the AST) compared to a production crash.

I'm happy to remove the check if you feel that's the right tradeoff in spite of these considerations, but I wanted to call them out.

https://github.com/llvm/llvm-project/pull/126868


More information about the cfe-commits mailing list