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

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 03:57:05 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}}
----------------
Endilll wrote:

It has that good first issue feel, so I'll refrain for now. But I'll get to all name lookup issues when I'm done with writing tests for P1787R6.

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


More information about the cfe-commits mailing list