[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:18 PDT 2024
================
@@ -1369,6 +1369,75 @@ namespace cwg385 { // cwg385: 2.8
// expected-note@#cwg385-n {{member is declared here}}
}
+namespace cwg386 { // cwg386: no
+namespace example1 {
+namespace N1 {
+// Binds name 'f' in N1. Target scope is N1.
+template<typename T> void f( T* x ) {
+ // ... other stuff ...
+ delete x;
+}
+}
+
+namespace N2 {
+// Bind name 'f' in N2. When a single search find this declaration,
+// it's replaced with N1::f declaration.
+using N1::f;
+
+// `f<int>` is not a qualified-id, so its target scope is N2.
+// `f<int>` is a template-id, so 'f' undergoes (unqualified) lookup.
+// Search performed by unqualified lookup finds N1::f via using-declaration,
+// but this result is not considered, because it's not nominable in N2,
+// which is because its target scope is N1.
+// So unqualified lookup doesn't find anything, making this declaration ill-formed.
+template<> void f<int>( int* );
+// expected-error at -1 {{no function template matches function template specialization 'f'}}
+
+class Test {
+ ~Test() { }
+ // `f<>` is a template-id and not a template declaration,
+ // so its terminal name 'f' undergoes (unqualified) lookup.
+ // Search in N2 performed by unqualified lookup finds
+ // (single) N1::f declaration via using-declaration.
+ // N1::f is replaced with N1::f<> specialization after deduction,
+ // and this is the result of the unqualified lookup.
+ // This friend declaration correspond to the result of the lookup.
+ // All lookup results target the same scope, which is N1,
+ // so target scope of this friend declaration is also N1.
+ // FIXME: This is well-formed.
+ friend void f<>( Test* x );
+ // expected-error at -1 {{no function template matches function template specialization 'f'}}
----------------
cor3ntin wrote:
Interestingly, it's confused by the namespaces - or more likely, the using declarations
https://compiler-explorer.com/z/oP6Er4e4j
https://github.com/llvm/llvm-project/pull/106117
More information about the cfe-commits
mailing list