<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62351>62351</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] The template argument name looking up logic may have bug.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tangjj11
</td>
</tr>
</table>
<pre>
### Source Code
```
1. template <class T>
2. class A1 {
3. public:
4. A1() {}
5. };
6. class A2 {
7. public:
8. A2() {}
9. };
10. template <class T> class B : T {
11. public:
12. B() : T() {}
13. };
14. template <class T> class C : public B<A1<T>>, public B<A2> {
15. public:
16. C() : B<A1<T>>(), B<A2>() {}
17. };
```
### Compile out put (clang16.0)
```
<source>:16:23: error: 'A2' is a private member of 'A2'
C() : B<A1<T>>(), B<A2>() {}
^
<source>:10:30: note: constrained by implicitly private inheritance here
template <class T> class B : T {
^
<source>:6:7: note: member is declared here
class A2 {
^
1 error generated.
Compiler returned: 1
```
But the gcc12.2 can compile pass.
And I wonder why the B<A2> in line 14 will not report error but the B<A2> in line 16 will report error.
I debug clang frontend and find that:
1. For the second `A2`, the `Sema::LookupQualifiedName()` in the `Sema::CPPLookupName` will find the target (`A2::A2`) in base class body `A2`, and will stop searching. Then the access check will failed because the class `B` inherited class `A2` in private mode, and second `A2` in the class `C` body cannot see the symbol in class `A2` body.
2. For the first `A2`, the `Sema::LookupQualifiedName()` will find nothing, because the expr is out of the class `C` body. And the `Sema::CPPLookupName` will continue searching outer scope and find the public class `A2`. So it is accessible.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVt2OozYUfhrn5mgR2AGSi1wQZiOtVFVb7b6AMSfgHWMj28w0b1_ZMCEzyaitWgkFYp_zfd_5M3DnZKcRDyQ_kvxpwyffG3vwXHe_fmXZpjHt5UAomy_4YSYrEGrTIkmfSFqRIl2u-DdLwOMwKu4RCKuF4s7BT8K-zts0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