Skip to content

Commit

Permalink
[clang] Add test for CWG2370
Browse files Browse the repository at this point in the history
[[https://wg21.link/p1787 | P1787]]: CWG2370 is resolved by performing a search in (only) the immediate scope of any friend, per the [[ http://wiki.edg.com/bin/view/Wg21sandiego2018/CoreWorkingGroup#Core_issue_2370_friend_declarati | CWG opinion from San Diego ]].
Wording: In a friend declaration declarator whose declarator-id is a qualified-id whose lookup context is a class or namespace S, lookup for an unqualified name that appears after the declarator-id performs a search in the scope associated with S. If that lookup finds nothing, it undergoes unqualified name lookup. ([basic.lookup.unqual]/6).

Clarification for P1787 description: when applied to the test in this patch, "immediate scope" refers to `N`, and "(only)" refers to the fact that `type` is not searched in parent scope of `N`. See example after the wording if additional clarification is needed. The most relevant line there is `friend void A::f(F);  // OK`.

Reviewed By: #clang-language-wg, shafik

Differential Revision: https://reviews.llvm.org/D147848
  • Loading branch information
Endilll committed Apr 11, 2023
1 parent 64d29e8 commit feb93d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion clang/test/CXX/drs/dr23xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s


#if __cplusplus >= 201103L
namespace dr2338 { // dr2338: 12
Expand Down Expand Up @@ -169,6 +171,20 @@ void g() {
} //namespace dr2303
#endif

namespace dr2370 { // dr2370: no
namespace N {
typedef int type;
void g(type);
void h(type);
} // namespace N
class C {
typedef N::type N_type;
// FIXME: `type` should be searched for in N
// friend void N::g(type);
friend void N::h(N_type);
};
} // namespace dr2370

// dr2385: na

namespace dr2394 { // dr2394: 15
Expand Down
2 changes: 1 addition & 1 deletion clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -14027,7 +14027,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://wg21.link/cwg2370">2370</a></td>
<td>CD6</td>
<td><TT>friend</TT> declarations of namespace-scope functions</td>
<td class="none" align="center">Unknown</td>
<td class="none" align="center">No</td>
</tr>
<tr id="2371">
<td><a href="https://wg21.link/cwg2371">2371</a></td>
Expand Down

0 comments on commit feb93d2

Please sign in to comment.