aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
diff options
context:
space:
mode:
authorKrystian Stasiowski <sdkrystian@gmail.com>2024-05-20 13:55:01 -0400
committerGitHub <noreply@github.com>2024-05-20 13:55:01 -0400
commitfd87d765c0455265aea4595a3741a96b4c078fbc (patch)
treea26953f1f68c4e55dd5e2e750e0e097f809b8fde /clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
parente24610532b87eaae06dedec8f7c90764cd9ba19c (diff)
downloadllvm-fd87d765c0455265aea4595a3741a96b4c078fbc.zip
llvm-fd87d765c0455265aea4595a3741a96b4c078fbc.tar.gz
llvm-fd87d765c0455265aea4595a3741a96b4c078fbc.tar.bz2
[Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (#92318)
According to [expr.prim.id.general] p2: > If an _id-expression_ `E` denotes a non-static non-type member of some class `C` at a point where the current class is `X` and > - `E` is potentially evaluated or `C` is `X` or a base class of `X`, and > - `E` is not the _id-expression_ of a class member access expression, and > - if `E` is a _qualified-id_, `E` is not the un-parenthesized operand of the unary `&` operator, > > the _id-expression_ is transformed into a class member access expression using `(*this)` as the object expression. Consider the following: ``` struct A { void f0(); template<typename T> void f1(); }; template<typename T> struct B : T { auto g0() -> decltype(T::f0()); // ok auto g1() -> decltype(T::template f1<int>()); // error: call to non-static member function without an object argument }; template struct B<A>; ``` Clang incorrectly rejects the call to `f1` in the _trailing-return-type_ of `g1`. Furthermore, the following snippet results in a crash during codegen: ``` struct A { void f(); }; template<typename T> struct B : T { template<typename U> static void g(); template<> void g<int>() { return T::f(); // crash here } }; template struct B<A>; ``` This happens because we unconditionally build a `CXXDependentScopeMemberExpr` (with an implicit object expression) for `T::f` when parsing the template definition, even though we don't know whether `g` is an implicit object member function yet. This patch fixes these issues by instead building `DependentScopeDeclRefExpr`s for such expressions, and only transforming them into implicit class member access expressions during instantiation. Since we implemented the MS "unqualified lookup into dependent bases" extension by building an implicit class member access (and relying on the first component name of the _nested-name-specifier_ to be looked up in the context of the object expression during instantiation), we instead pre-append a fake _nested-name-specifier_ that refers to the injected-class-name of the enclosing class. This patch also refactors `Sema::BuildQualifiedDeclarationNameExpr` and `Sema::BuildQualifiedTemplateIdExpr`, streamlining their implementation and removing any redundant checks.
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp')
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 65df513..2e42b85 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -614,8 +614,10 @@ TEST_P(ASTMatchersTest, MemberExpr_MatchesVariable) {
EXPECT_TRUE(matches("template <class T>"
"class X : T { void f() { this->T::v; } };",
cxxDependentScopeMemberExpr()));
- EXPECT_TRUE(matches("template <class T> class X : T { void f() { T::v; } };",
- cxxDependentScopeMemberExpr()));
+ // FIXME: Add a matcher for DependentScopeDeclRefExpr.
+ EXPECT_TRUE(
+ notMatches("template <class T> class X : T { void f() { T::v; } };",
+ cxxDependentScopeMemberExpr()));
EXPECT_TRUE(matches("template <class T> void x() { T t; t.v; }",
cxxDependentScopeMemberExpr()));
}