Skip to content

Commit 6437919

Browse files
committed
support void_t SFINAE
#feat fix #748
1 parent 90b69e4 commit 6437919

File tree

5 files changed

+263
-0
lines changed

5 files changed

+263
-0
lines changed

src/lib/AST/ASTVisitor.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,10 @@ ASTVisitor::getSFINAETemplateInfo(QualType T, bool const AllowDependentNames) co
22422242
T = QualType(DNT->getQualifier()->getAsType(), 0);
22432243
MRDOCS_SYMBOL_TRACE(T, context_);
22442244
}
2245+
if (!T.getTypePtrOrNull())
2246+
{
2247+
return std::nullopt;
2248+
}
22452249

22462250
// If the type is a template specialization type, extract the template name
22472251
// and the template arguments

test-files/golden-tests/metadata/sfinae.adoc

+94
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
| <<A-02,`A&lt;T, void&gt;`>>
2626
| Specialization for floating point types
2727

28+
| <<S-02,`S`>>
29+
| SFINAE with std&colon;&colon;void&lowbar;t
30+
31+
| <<S-08,`S&lt;T, std::void&lowbar;t&lt;T::a::b&gt;&gt;`>>
32+
| SFINAE with std&colon;&colon;void&lowbar;t
33+
2834
|===
2935
=== Functions
3036

@@ -136,6 +142,94 @@ class <<A-09,A>>&lt;T, void&gt;;
136142

137143

138144

145+
[#S-02]
146+
== S
147+
148+
149+
SFINAE with std&colon;&colon;void&lowbar;t
150+
151+
=== Synopsis
152+
153+
154+
Declared in `&lt;sfinae&period;cpp&gt;`
155+
156+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
157+
----
158+
template&lt;
159+
class T,
160+
class = void&gt;
161+
struct S;
162+
----
163+
164+
=== Member Functions
165+
166+
[cols=1]
167+
|===
168+
| Name
169+
170+
| <<S-02-store,`store`>>
171+
|===
172+
173+
174+
175+
[#S-02-store]
176+
== <<S-02,S>>::store
177+
178+
179+
=== Synopsis
180+
181+
182+
Declared in `&lt;sfinae&period;cpp&gt;`
183+
184+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
185+
----
186+
void
187+
store(void const*);
188+
----
189+
190+
[#S-08]
191+
== S&lt;T, std::void&lowbar;t&lt;T::a::b&gt;&gt;
192+
193+
194+
SFINAE with std&colon;&colon;void&lowbar;t
195+
196+
=== Synopsis
197+
198+
199+
Declared in `&lt;sfinae&period;cpp&gt;`
200+
201+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
202+
----
203+
template&lt;class T&gt;
204+
struct <<S-02,S>>&lt;T, std::void&lowbar;t&lt;T::a::b&gt;&gt;;
205+
----
206+
207+
=== Member Functions
208+
209+
[cols=1]
210+
|===
211+
| Name
212+
213+
| <<S-08-store,`store`>>
214+
|===
215+
216+
217+
218+
[#S-08-store]
219+
== <<S-08,S>>&lt;T, std::void&lowbar;t&lt;T::a::b&gt;&gt;::store
220+
221+
222+
=== Synopsis
223+
224+
225+
Declared in `&lt;sfinae&period;cpp&gt;`
226+
227+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
228+
----
229+
void
230+
store(void const*);
231+
----
232+
139233
[#f1]
140234
== f1
141235

test-files/golden-tests/metadata/sfinae.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@ class A {};
7171
/// Specialization for floating point types
7272
template<class T>
7373
class A<T, std::enable_if_t<std::is_integral_v<T>>> {};
74+
75+
/// SFINAE with std::void_t
76+
template <class T, class = void>
77+
struct S
78+
{
79+
void store(const void*) {}
80+
};
81+
82+
/// SFINAE with std::void_t
83+
template <class T>
84+
struct S<T, std::void_t<typename T::a::b>>
85+
{
86+
void store(const void*) {}
87+
};

test-files/golden-tests/metadata/sfinae.html

+110
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ <h2>Types</h2>
3535
</td></tr><tr>
3636
<td><a href="#A-02"><code>A&lt;T, void&gt;</code></a> </td><td><span><span>Specialization for floating point types</span></span>
3737

38+
</td></tr><tr>
39+
<td><a href="#S-02"><code>S</code></a> </td><td><span><span>SFINAE with std::void_t</span></span>
40+
41+
</td></tr><tr>
42+
<td><a href="#S-08"><code>S&lt;T, std::void_t&lt;T::a::b&gt;&gt;</code></a> </td><td><span><span>SFINAE with std::void_t</span></span>
43+
3844
</td></tr>
3945
</tbody>
4046
</table>
@@ -161,6 +167,110 @@ <h3>Synopsis</h3>
161167
</div>
162168

163169

170+
</div>
171+
<div>
172+
<div>
173+
<h2 id="S-02">S</h2>
174+
<div>
175+
<span><span>SFINAE with std::void_t</span></span>
176+
177+
178+
</div>
179+
</div>
180+
<div>
181+
<h3>Synopsis</h3>
182+
<div>
183+
Declared in <code>&lt;sfinae.cpp&gt;</code></div>
184+
<pre>
185+
<code class="source-code cpp">
186+
template&lt;
187+
class T,
188+
class = void&gt;
189+
struct S;
190+
</code>
191+
</pre>
192+
</div>
193+
<h2>Member Functions</h2>
194+
<table style="table-layout: fixed; width: 100%;">
195+
<thead>
196+
<tr>
197+
<th>Name</th>
198+
</tr>
199+
</thead>
200+
<tbody>
201+
<tr>
202+
<td><a href="#S-02-store"><code>store</code></a> </td></tr>
203+
</tbody>
204+
</table>
205+
206+
207+
</div>
208+
<div>
209+
<div>
210+
<h2 id="S-02-store"><a href="#S-02">S</a>::store</h2>
211+
</div>
212+
<div>
213+
<h3>Synopsis</h3>
214+
<div>
215+
Declared in <code>&lt;sfinae.cpp&gt;</code></div>
216+
<pre>
217+
<code class="source-code cpp">
218+
void
219+
store(void const*);
220+
</code>
221+
</pre>
222+
</div>
223+
</div>
224+
<div>
225+
<div>
226+
<h2 id="S-08">S&lt;T, std::void_t&lt;T::a::b&gt;&gt;</h2>
227+
<div>
228+
<span><span>SFINAE with std::void_t</span></span>
229+
230+
231+
</div>
232+
</div>
233+
<div>
234+
<h3>Synopsis</h3>
235+
<div>
236+
Declared in <code>&lt;sfinae.cpp&gt;</code></div>
237+
<pre>
238+
<code class="source-code cpp">
239+
template&lt;class T&gt;
240+
struct <a href="#S-02">S</a>&lt;T, std::void_t&lt;T::a::b&gt;&gt;;
241+
</code>
242+
</pre>
243+
</div>
244+
<h2>Member Functions</h2>
245+
<table style="table-layout: fixed; width: 100%;">
246+
<thead>
247+
<tr>
248+
<th>Name</th>
249+
</tr>
250+
</thead>
251+
<tbody>
252+
<tr>
253+
<td><a href="#S-08-store"><code>store</code></a> </td></tr>
254+
</tbody>
255+
</table>
256+
257+
258+
</div>
259+
<div>
260+
<div>
261+
<h2 id="S-08-store"><a href="#S-08">S</a>&lt;T, std::void_t&lt;T::a::b&gt;&gt;::store</h2>
262+
</div>
263+
<div>
264+
<h3>Synopsis</h3>
265+
<div>
266+
Declared in <code>&lt;sfinae.cpp&gt;</code></div>
267+
<pre>
268+
<code class="source-code cpp">
269+
void
270+
store(void const*);
271+
</code>
272+
</pre>
273+
</div>
164274
</div>
165275
<div>
166276
<div>

test-files/golden-tests/metadata/sfinae.xml

+41
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,46 @@
222222
</doc>
223223
</class>
224224
</template>
225+
<template>
226+
<tparam name="T" class="type"/>
227+
<tparam class="type" default="void"/>
228+
<struct name="S" id="IZrmVBMJu1uvsP9zur5JVrwgYmE=">
229+
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="76" class="def"/>
230+
<doc>
231+
<para>
232+
<text>SFINAE with std::void_t</text>
233+
</para>
234+
</doc>
235+
<function name="store" id="KmwKarrWHSv7aalrBX18hjPbEfs=">
236+
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="79" class="def"/>
237+
<param>
238+
<type class="pointer">
239+
<pointee-type name="void" cv-qualifiers="const"/>
240+
</type>
241+
</param>
242+
</function>
243+
</struct>
244+
</template>
245+
<template class="partial" id="IZrmVBMJu1uvsP9zur5JVrwgYmE=">
246+
<tparam name="T" class="type"/>
247+
<targ class="type" type="T"/>
248+
<targ class="type" type="std::void_t&lt;T::a::b&gt;"/>
249+
<struct name="S" id="g0UNZpdodOU5mGCtcpviXd8o6Vk=">
250+
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="84" class="def"/>
251+
<doc>
252+
<para>
253+
<text>SFINAE with std::void_t</text>
254+
</para>
255+
</doc>
256+
<function name="store" id="2KfuSRGlpNo9Lk/lk1bhwZqm/BY=">
257+
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="86" class="def"/>
258+
<param>
259+
<type class="pointer">
260+
<pointee-type name="void" cv-qualifiers="const"/>
261+
</type>
262+
</param>
263+
</function>
264+
</struct>
265+
</template>
225266
</namespace>
226267
</mrdocs>

0 commit comments

Comments
 (0)