[PATCH] D101346: [AST] Fix getExprLoc reported for cxxDependentScopeMemberExpr
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 27 01:32:40 PDT 2021
steveire created this revision.
steveire added a reviewer: rsmith.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
All other CallExpr use the location of the member name as the
getExprLoc:
https://godbolt.org/z/jx16G9Gdr
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101346
Files:
clang/include/clang/AST/ExprCXX.h
clang/unittests/AST/SourceLocationTest.cpp
Index: clang/unittests/AST/SourceLocationTest.cpp
===================================================================
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -634,6 +634,39 @@
friendDecl()));
}
+TEST(CXXDependentScopeMemberExpr, ExprLocation) {
+
+ llvm::Annotations Example(R"cpp(
+template<typename T>
+struct MyContainer
+{
+ template <typename U>
+ void pushBack();
+
+ void foo();
+};
+
+template<typename T>
+struct Derived : MyContainer<T>
+{
+ void bar()
+ {
+ MyContainer<T>::template $member_name^pushBack<int>();
+ }
+};
+ )cpp");
+
+ auto AST = tooling::buildASTFromCode(Example.code());
+ SourceManager &SM = AST->getSourceManager();
+ auto &Ctx = AST->getASTContext();
+
+ auto *M = selectFirst<CXXDependentScopeMemberExpr>(
+ "mem", match(cxxDependentScopeMemberExpr().bind("mem"), Ctx));
+ ASSERT_TRUE(M != nullptr);
+
+ ASSERT_EQ(SM.getFileOffset(M->getExprLoc()), Example.point("member_name"));
+}
+
TEST(FriendDecl, FriendTemplateClassRange) {
RangeVerifier<FriendDecl> Verifier;
Verifier.expectRange(2, 1, 3, 14);
Index: clang/include/clang/AST/ExprCXX.h
===================================================================
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -3774,6 +3774,8 @@
return MemberNameInfo.getEndLoc();
}
+ SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
+
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXDependentScopeMemberExprClass;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101346.340755.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210427/6a2a23f1/attachment-0001.bin>
More information about the cfe-commits
mailing list