
attempt to fix https://github.com/llvm/llvm-project/issues/12361 Consider this example: ```cpp class D { class E{ class F{}; friend void foo(D::E::F& q); }; friend void foo(D::E::F& q); }; void foo(D::E::F& q) {} ``` The first friend declaration of foo is correct. After that, the second friend declaration delayed access checking and set its previous declaration to be the first one. When doing access checking of `F`(which is private filed of `E`), we put its canonical declaration(the first friend declaration) into `EffectiveContext.Functions`. Actually, we are still checking the first one. This is incorrect due to the delayed checking. Creating a new scope to indicate we are parsing a friend declaration and doing access checking in time.
31 lines
797 B
C++
31 lines
797 B
C++
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
|
|
|
|
class D {
|
|
class E{
|
|
class F{}; // expected-note{{implicitly declared private here}}
|
|
friend void foo(D::E::F& q);
|
|
};
|
|
friend void foo(D::E::F& q); // expected-error{{'F' is a private member of 'D::E'}}
|
|
};
|
|
|
|
void foo(D::E::F& q) {}
|
|
|
|
class D1 {
|
|
class E1{
|
|
class F1{}; // expected-note{{implicitly declared private here}}
|
|
friend D1::E1::F1 foo1();
|
|
};
|
|
friend D1::E1::F1 foo1(); // expected-error{{'F1' is a private member of 'D1::E1'}}
|
|
};
|
|
|
|
D1::E1::F1 foo1() { return D1::E1::F1(); }
|
|
|
|
class D2 {
|
|
class E2{
|
|
class F2{};
|
|
friend void foo2();
|
|
};
|
|
friend void foo2(){ D2::E2::F2 c;}
|
|
};
|