[clang] [clang] Add tests for CWG issues about friend declaration matching (PR #106117)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 26 13:32:17 PDT 2024


================
@@ -568,6 +568,80 @@ namespace cwg137 { // cwg137: yes
   const volatile int *cvqcv = static_cast<const volatile int*>(cvp);
 }
 
+namespace cwg138 { // cwg138: partial
+namespace example1 {
+void foo(); // #cwg138-ex1-foo
+namespace A {
+  using example1::foo; // #cwg138-ex1-using
+  class X {
+    static const int i = 10;
+    // This friend declaration is using neither qualified-id nor template-id,
+    // so name 'foo' is not looked up, which means the using-declaration has no effect.
+    // Target scope of this declaration is A, so this is grating friendship to
+    // (hypothetical) A::foo instead of 'example1::foo' using declaration refers to.
+    // A::foo corresponds to example1::foo named by the using declaration,
+    // and since A::foo is a different entity, they potentially conflict.
+    // FIXME: This is ill-formed, but not for the reason diagnostic says.
+    friend void foo();
+    // expected-error at -1 {{cannot befriend target of using declaration}}
+    //   expected-note@#cwg138-ex1-foo {{target of using declaration}}
+    //   expected-note@#cwg138-ex1-using {{using declaration}}
----------------
cor3ntin wrote:

Do you want to try to fix this one?

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


More information about the cfe-commits mailing list