[clang] [clang-tools-extra] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 8 06:32:23 PDT 2024


erichkeane wrote:

> @erichkeane PR updated.
> 
> When we encounter a class member access expression with a nested-name-specifier that is invalid, should we simply ignore it and instead use the type of the object expression as the lookup context? This is the current behavior, but it leads to lots of duplicate diagnostics. For example:
> 
> ```c++
> struct A
> {
>     using I = int;
> };
> 
> void f(A* x)
> {
>     x->I::z; // error: 'A::I' (aka 'int') is not a class, namespace, or enumeration
>                // error: no member named 'z' in 'A'
> }
> ```
> 
> IMO we should just return `ExprError` from `BuildMemberReferenceExpr` and thus not emit the second error.

Sorry, I'm not really getting the question here.  Obviously that 2nd error is invalid and we shouldn't be emitting it, and doing the `::z` lookup inside of `A` seems wrong to me.  But I'm not sure I get the issue.

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


More information about the cfe-commits mailing list