Skip to content

support void_t SFINAE #815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
@@ -2242,6 +2242,10 @@ ASTVisitor::getSFINAETemplateInfo(QualType T, bool const AllowDependentNames) co
T = QualType(DNT->getQualifier()->getAsType(), 0);
MRDOCS_SYMBOL_TRACE(T, context_);
}
if (!T.getTypePtrOrNull())
{
return std::nullopt;
}

// If the type is a template specialization type, extract the template name
// and the template arguments
94 changes: 94 additions & 0 deletions test-files/golden-tests/metadata/sfinae.adoc
Original file line number Diff line number Diff line change
@@ -25,6 +25,12 @@
| <<A-02,`A&lt;T, void&gt;`>>
| Specialization for floating point types

| <<S-02,`S`>>
| SFINAE with std&colon;&colon;void&lowbar;t

| <<S-08,`S&lt;T, std::void&lowbar;t&lt;T::a::b&gt;&gt;`>>
| SFINAE with std&colon;&colon;void&lowbar;t

|===
=== Functions

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



[#S-02]
== S


SFINAE with std&colon;&colon;void&lowbar;t

=== Synopsis


Declared in `&lt;sfinae&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
class T,
class = void&gt;
struct S;
----

=== Member Functions

[cols=1]
|===
| Name

| <<S-02-store,`store`>>
|===



[#S-02-store]
== <<S-02,S>>::store


=== Synopsis


Declared in `&lt;sfinae&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
store(void const*);
----

[#S-08]
== S&lt;T, std::void&lowbar;t&lt;T::a::b&gt;&gt;


SFINAE with std&colon;&colon;void&lowbar;t

=== Synopsis


Declared in `&lt;sfinae&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class T&gt;
struct <<S-02,S>>&lt;T, std::void&lowbar;t&lt;T::a::b&gt;&gt;;
----

=== Member Functions

[cols=1]
|===
| Name

| <<S-08-store,`store`>>
|===



[#S-08-store]
== <<S-08,S>>&lt;T, std::void&lowbar;t&lt;T::a::b&gt;&gt;::store


=== Synopsis


Declared in `&lt;sfinae&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
store(void const*);
----

[#f1]
== f1

14 changes: 14 additions & 0 deletions test-files/golden-tests/metadata/sfinae.cpp
Original file line number Diff line number Diff line change
@@ -71,3 +71,17 @@ class A {};
/// Specialization for floating point types
template<class T>
class A<T, std::enable_if_t<std::is_integral_v<T>>> {};

/// SFINAE with std::void_t
template <class T, class = void>
struct S
{
void store(const void*) {}
};

/// SFINAE with std::void_t
template <class T>
struct S<T, std::void_t<typename T::a::b>>
{
void store(const void*) {}
};
110 changes: 110 additions & 0 deletions test-files/golden-tests/metadata/sfinae.html
Original file line number Diff line number Diff line change
@@ -35,6 +35,12 @@ <h2>Types</h2>
</td></tr><tr>
<td><a href="#A-02"><code>A&lt;T, void&gt;</code></a> </td><td><span><span>Specialization for floating point types</span></span>

</td></tr><tr>
<td><a href="#S-02"><code>S</code></a> </td><td><span><span>SFINAE with std::void_t</span></span>

</td></tr><tr>
<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>

</td></tr>
</tbody>
</table>
@@ -161,6 +167,110 @@ <h3>Synopsis</h3>
</div>


</div>
<div>
<div>
<h2 id="S-02">S</h2>
<div>
<span><span>SFINAE with std::void_t</span></span>


</div>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;sfinae.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
template&lt;
class T,
class = void&gt;
struct S;
</code>
</pre>
</div>
<h2>Member Functions</h2>
<table style="table-layout: fixed; width: 100%;">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#S-02-store"><code>store</code></a> </td></tr>
</tbody>
</table>


</div>
<div>
<div>
<h2 id="S-02-store"><a href="#S-02">S</a>::store</h2>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;sfinae.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
void
store(void const*);
</code>
</pre>
</div>
</div>
<div>
<div>
<h2 id="S-08">S&lt;T, std::void_t&lt;T::a::b&gt;&gt;</h2>
<div>
<span><span>SFINAE with std::void_t</span></span>


</div>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;sfinae.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
template&lt;class T&gt;
struct <a href="#S-02">S</a>&lt;T, std::void_t&lt;T::a::b&gt;&gt;;
</code>
</pre>
</div>
<h2>Member Functions</h2>
<table style="table-layout: fixed; width: 100%;">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#S-08-store"><code>store</code></a> </td></tr>
</tbody>
</table>


</div>
<div>
<div>
<h2 id="S-08-store"><a href="#S-08">S</a>&lt;T, std::void_t&lt;T::a::b&gt;&gt;::store</h2>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;sfinae.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
void
store(void const*);
</code>
</pre>
</div>
</div>
<div>
<div>
41 changes: 41 additions & 0 deletions test-files/golden-tests/metadata/sfinae.xml
Original file line number Diff line number Diff line change
@@ -222,5 +222,46 @@
</doc>
</class>
</template>
<template>
<tparam name="T" class="type"/>
<tparam class="type" default="void"/>
<struct name="S" id="IZrmVBMJu1uvsP9zur5JVrwgYmE=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="76" class="def"/>
<doc>
<para>
<text>SFINAE with std::void_t</text>
</para>
</doc>
<function name="store" id="KmwKarrWHSv7aalrBX18hjPbEfs=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="79" class="def"/>
<param>
<type class="pointer">
<pointee-type name="void" cv-qualifiers="const"/>
</type>
</param>
</function>
</struct>
</template>
<template class="partial" id="IZrmVBMJu1uvsP9zur5JVrwgYmE=">
<tparam name="T" class="type"/>
<targ class="type" type="T"/>
<targ class="type" type="std::void_t&lt;T::a::b&gt;"/>
<struct name="S" id="g0UNZpdodOU5mGCtcpviXd8o6Vk=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="84" class="def"/>
<doc>
<para>
<text>SFINAE with std::void_t</text>
</para>
</doc>
<function name="store" id="2KfuSRGlpNo9Lk/lk1bhwZqm/BY=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="86" class="def"/>
<param>
<type class="pointer">
<pointee-type name="void" cv-qualifiers="const"/>
</type>
</param>
</function>
</struct>
</template>
</namespace>
</mrdocs>

Unchanged files with check annotations Beta

// When adding a function to the tranche, we have to
// check if the function isn't already overriden by
// a function with the same name and signature.
if (Tranche* tranche = trancheFor(access))

Check warning on line 108 in src/lib/Metadata/Interface.cpp

GitHub Actions / GCC 14: C++20

Build Warning - g++-14 - [-Wunused-variable]

g++-14 - unused variable 'tranche' ([-Wunused-variable])

Check warning on line 108 in src/lib/Metadata/Interface.cpp

GitHub Actions / GCC 14: C++20 (Coverage)

Build Warning - g++-14 - [-Wunused-variable]

g++-14 - unused variable 'tranche' ([-Wunused-variable])
{
if (buildingFromBase_)
{