[all-commits] [llvm/llvm-project] 3cdb30: [Clang][Sema] Use the correct lookup context when ...
Krystian Stasiowski via All-commits
all-commits at lists.llvm.org
Mon Sep 9 09:07:06 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 3cdb30ebbc18fa894d3bd67aebcff76ce7c741ac
https://github.com/llvm/llvm-project/commit/3cdb30ebbc18fa894d3bd67aebcff76ce7c741ac
Author: Krystian Stasiowski <sdkrystian at gmail.com>
Date: 2024-09-09 (Mon, 09 Sep 2024)
Changed paths:
M clang/include/clang/Sema/Sema.h
M clang/lib/Sema/SemaExprCXX.cpp
M clang/lib/Sema/SemaOverload.cpp
M clang/lib/Sema/TreeTransform.h
M clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
Log Message:
-----------
[Clang][Sema] Use the correct lookup context when building overloaded 'operator->' in the current instantiation (#104458)
Currently, clang erroneously rejects the following:
```
struct A
{
template<typename T>
void f();
};
template<typename T>
struct B
{
void g()
{
(*this)->template f<int>(); // error: no member named 'f' in 'B<T>'
}
A* operator->();
};
```
This happens because `Sema::ActOnStartCXXMemberReference` does not adjust the `ObjectType` parameter when `ObjectType` is a dependent type (except when the type is a `PointerType` and the class member access is the `->` form). Since the (possibly adjusted) `ObjectType` parameter (`B<T>` in the above example) is passed to `Parser::ParseOptionalCXXScopeSpecifier`, we end up looking up `f` in `B` rather than `A`.
This patch fixes the issue by identifying cases where the type of the object expression `T` is a dependent, non-pointer type and:
- `T` is the current instantiation and lookup for `operator->` finds a member of the current instantiation, or
- `T` has at least one dependent base case, and `operator->` is not found in the current instantiation
and using `ASTContext::DependentTy` as the type of the object expression when the optional _nested-name-specifier_ is parsed.
Fixes #104268.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list