Issue 184622
Summary [clang]Clang accepts invalid use of local nested class name without qualification
Labels clang
Assignees
Reporter Attacker23
    
Since **Clang 16.0.0**, Clang accepts the following code, while **GCC / MSVC / EDG** all reject it:

```cpp
template<class T>
struct Wrapper { Wrapper(T) {} };

void f() {
  class A { class B; };
  class A::B {};
  Wrapper wB = Wrapper{B{}};
}

int main() { f(); }
```

https://godbolt.org/z/Me7K5bfed

Here `B` is a nested class of `A`, so its full name is `A::B`. It is not declared in the outer scope of `f()`. On this line:

```cpp
Wrapper wB = Wrapper{B{}};
```
an **unqualified** name lookup for `B` is performed in the current scope, but there is no type named `B` there (nor in any enclosing namespace scope). According to the standard, this should be an “`B` is undeclared” error. The correct, conforming usage would be:

```cpp
Wrapper wB = Wrapper{A::B{}};
```
or introduce an alias:

```cpp
using B = A::B;
Wrapper wB = Wrapper{B{}};
```

GCC, MSVC, and EDG reject the original code for this reason; only Clang accepts it.

> Reference: [basic.lookup.unqual]/2–3  
> https://eel.is/c++draft/basic.lookup.unqual#2  
> https://eel.is/c++draft/basic.lookup.unqual#3
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to