Skip to content

Commit eaea5f6

Browse files
authoredOct 8, 2024
[clang] Add test for CWG110 "Can template functions and classes be declared in the same scope?" (#111446)
[P1787R6](https://wg21.link/p1787r6): > [CWG110](https://cplusplus.github.io/CWG/issues/110.html) is resolved by reducing the restriction in [temp.pre] to a note (matching the behavior of GCC, Clang, and ICC). Wording: see changes to [temp.pre]/7 I believe the wording for the questions raised in the issue is now the definition of corresponding declarations that is given in [[basic.scope.scope]/4](https://eel.is/c++draft/basic.scope#scope-4): > Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unless > — either is a using-declarator, or > — one declares a type (not a typedef-name) and the other declares a variable, non-static data member other than of an anonymous union ([class.union.anon]), enumerator, function, or function template, or > — each declares a function or function template and they do not declare corresponding overloads. Then it's used as an input for the definition of potentially conflicting declarations given in [[basic.scope.scope]/6](https://eel.is/c++draft/basic.scope#scope-6). Answering the question in the title: yes, having a function template and a type with the same name that has the same target scope is well-formed. A keen eye might spot that the current [[temp.pre]/7](https://eel.is/c++draft/temp.pre#7) note doesn't reflect all of the exceptions from the definition of corresponding declarations in [basic.scope.scope]/4, namely 4.1 and 4.2. I believe the note is defective, and I opened an editorial PR against the draft to fix that: cplusplus/draft#7284.
1 parent 9e954b2 commit eaea5f6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎clang/test/CXX/drs/cwg1xx.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ namespace cwg109 { // cwg109: yes
119119
};
120120
}
121121

122+
namespace cwg110 { // cwg110: 2.8
123+
template <typename T>
124+
void f(T);
125+
126+
class f {};
127+
128+
template <typename T>
129+
void f(T, T);
130+
131+
class f g;
132+
void (*h)(int) = static_cast<void(*)(int)>(f);
133+
void (*i)(int, int) = static_cast<void(*)(int, int)>(f);
134+
} // namespace cwg110
135+
122136
namespace cwg111 { // cwg111: dup 535
123137
struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); };
124138
struct B : A { B(); }; // #cwg111-B

‎clang/www/cxx_dr_status.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
705705
<td><a href="https://cplusplus.github.io/CWG/issues/110.html">110</a></td>
706706
<td>CD6</td>
707707
<td>Can template functions and classes be declared in the same scope?</td>
708-
<td class="unknown" align="center">Unknown</td>
708+
<td class="full" align="center">Clang 2.8</td>
709709
</tr>
710710
<tr id="111">
711711
<td><a href="https://cplusplus.github.io/CWG/issues/111.html">111</a></td>

0 commit comments

Comments
 (0)
Please sign in to comment.