<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/155907>155907</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unqualified lookup for `friend elaborated-type-specifier` in local classes escapes the nearest enclosing block scope
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ckwastra
</td>
</tr>
</table>
<pre>
**Test code ([CE](https://godbolt.org/z/4E7vP6vKj)):**
```cpp
struct A {
template <class T> using type = typename T::type;
};
void f() {
class B {
friend class A;
using type = void;
};
struct A {
// Clang/MSVC: error ❌
// GCC/EDG: OK ✅
using type = B::type;
};
// Clang/MSVC: OK ❌
// GCC/EDG: error ✅
using type = ::A::type<B>;
}
```
According to [[dcl.type.elab]/4](https://eel.is/c++draft/dcl.type.elab#4):
> Any unqualified lookup for the *identifier* (in the first case) does not consider scopes that contain the nearest enclosing namespace or block scope; [...]
Therefore, in the declaration `friend class A` above, `::A` (in global scope) should **not** be found. The friendship of `B` should instead be granted to the local class `A` declared inside `f`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VE9v47YT_TTjyyCCQv2xddBBku09LH74FWjaO0WObG4YUSUpL9JPX4ykJk6aBQiY1vA9vpl5QxmCuYxENRQtFMednOPV-Vo9_5QhernrnX6tQTQgmicKEZXThCAOULTdCYojiMM1xilA1oA4gzhfnO6djYnzFxDnv0Gc89P-9lt5-_4DRMWLTy4rXVaZrktNE6RNiH5WERuEfQtpgxjpZbIyEkLWKStDwCfITjgHM14wvk4cOC6bUb4QBxvIGv4PGTPA_rhubs5oHFi6qN7YV8b27T_i4A2Negs0K5S_f7qQ2f4Nvl2B-B_5iGtZsLNy5Ir87_c_O8gaJO-dRzgJqI5w6D4eRsRvXQfifDp-48P__74E-XAHh-JrSe3n1D8o-4WMO-Y3Gb8Qcaf4TcQnCauC5l5I10J2em_FXcPX_jdKOa8XFoeLCVutbMLghKzsF4-d86-sRmQTE0CcFYgWRKu9HCKI80e8yPLNdavfshM24yvO41-ztGYwpNE69zxPODiP8cr2boymMXLQg2jY72ZcQoPxPAQyELtIOwo4Op6KMRhNHoNyEwWMV7l8jHLDjSQ9jw-NyrqlZuzWMElF6Dz21qnnFQxZy2VIkoRTXiQ_XcnT4DyB6HAj1KSs9DIaNyKU6SfXlinK3t0WAFd6a0uZbqlcrOul3S4UFYarm63GdS5HF9cN9oSDm0ed4BPnvtwRrmZCNzBty4Qb1IwhktQMuXg5RtLcT1ZqnZJ2Uwbl0v9NPS0www9KmQ5QpslO15muskruqH7cF2WeVoe02F3rvsyLgcRBpVqnShR5QTpXw1CUh32RK7EztUhFkR7E4bHKyrxIDqqoFFWZopz6PNWQp_QijU2svb3w67QzIcxUPxZFle53VvZkw_IKCjHST1yiIAQ_ir5m0EM_XwLkqTUhhneaaKKl-o-v7fTeGvai8zKSfmBvPoSJ1GqwMuWm3pWJAlJQcjXSV965s8tu9rb-9AKbeJ37RLkXEGeWuf08TN79IMUTsiTHk7Nlf6vFPwEAAP__iQfNRg">