Skip to content

Commit 6f9bd07

Browse files
committed
SFINAE return type constraints
#feat
1 parent b885e2e commit 6f9bd07

File tree

10 files changed

+44
-18
lines changed

10 files changed

+44
-18
lines changed

src/lib/AST/ASTVisitor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,20 @@ populate(
872872
}
873873
else
874874
{
875+
// Return type SFINAE constraints
876+
if (I.ReturnType &&
877+
!I.ReturnType->Constraints.empty())
878+
{
879+
for (ExprInfo const& constraint: I.ReturnType->Constraints)
880+
{
881+
if (!I.Requires.Written.empty())
882+
{
883+
I.Requires.Written += " && ";
884+
}
885+
I.Requires.Written += constraint.Written;
886+
}
887+
}
888+
875889
// Iterate I.Params to find trailing requires clauses
876890
for (auto it = I.Params.begin(); it != I.Params.end(); )
877891
{

test-files/golden-tests/core/libcxx.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Declared in `<libcxx.cpp>`
3131
----
3232
template<typename T>
3333
T
34-
sqrt(T value);
34+
sqrt(T value)
35+
requires std::is_integral_v<T>;
3536
----
3637

3738
=== Description

test-files/golden-tests/core/libcxx.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ <h3>Synopsis</h3>
4141
<code class="source-code cpp">
4242
template&lt;typename T&gt;
4343
T
44-
sqrt(T value);
44+
sqrt(T value)
45+
requires std::is_integral_v&lt;T&gt;;
4546
</code>
4647
</pre>
4748
</div>

test-files/golden-tests/core/libcxx.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<namespace id="//////////////////////////8=">
55
<template>
66
<tparam name="T" class="type"/>
7-
<function name="sqrt" id="ulFDUE1svTCX8fV/h8EIp4NNbWs=">
7+
<function name="sqrt" requires="std::is_integral_v&lt;T&gt;" id="ulFDUE1svTCX8fV/h8EIp4NNbWs=">
88
<file short-path="libcxx.cpp" source-path="libcxx.cpp" line="149"/>
99
<return>
1010
<type name="T"/>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ Declared in `&lt;sfinae&period;cpp&gt;`
246246
----
247247
template&lt;class T&gt;
248248
T
249-
f1(T value);
249+
f1(T value)
250+
requires std&colon;&colon;is&lowbar;integral&lowbar;v&lt;T&gt;;
250251
----
251252

252253
[#f10]
@@ -294,7 +295,8 @@ Declared in `&lt;sfinae&period;cpp&gt;`
294295
----
295296
template&lt;class T&gt;
296297
int
297-
f2(T value);
298+
f2(T value)
299+
requires std&colon;&colon;is&lowbar;integral&lowbar;v&lt;T&gt;;
298300
----
299301

300302
[#f3]
@@ -312,7 +314,8 @@ Declared in `&lt;sfinae&period;cpp&gt;`
312314
----
313315
template&lt;class T&gt;
314316
<<B,B>>::<<B-C,C>>
315-
f3(T value);
317+
f3(T value)
318+
requires std&colon;&colon;is&lowbar;integral&lowbar;v&lt;T&gt;;
316319
----
317320

318321
[#f4]
@@ -330,7 +333,8 @@ Declared in `&lt;sfinae&period;cpp&gt;`
330333
----
331334
template&lt;class T&gt;
332335
T
333-
f4(T value);
336+
f4(T value)
337+
requires std&colon;&colon;is&lowbar;integral&lowbar;v&lt;T&gt;;
334338
----
335339

336340
[#f5]

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ <h3>Synopsis</h3>
290290
<code class="source-code cpp">
291291
template&lt;class T&gt;
292292
T
293-
f1(T value);
293+
f1(T value)
294+
requires std::is_integral_v&lt;T&gt;;
294295
</code>
295296
</pre>
296297
</div>
@@ -343,7 +344,8 @@ <h3>Synopsis</h3>
343344
<code class="source-code cpp">
344345
template&lt;class T&gt;
345346
int
346-
f2(T value);
347+
f2(T value)
348+
requires std::is_integral_v&lt;T&gt;;
347349
</code>
348350
</pre>
349351
</div>
@@ -365,7 +367,8 @@ <h3>Synopsis</h3>
365367
<code class="source-code cpp">
366368
template&lt;class T&gt;
367369
<a href="#B">B</a>::<a href="#B-C">C</a>
368-
f3(T value);
370+
f3(T value)
371+
requires std::is_integral_v&lt;T&gt;;
369372
</code>
370373
</pre>
371374
</div>
@@ -387,7 +390,8 @@ <h3>Synopsis</h3>
387390
<code class="source-code cpp">
388391
template&lt;class T&gt;
389392
T
390-
f4(T value);
393+
f4(T value)
394+
requires std::is_integral_v&lt;T&gt;;
391395
</code>
392396
</pre>
393397
</div>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<namespace id="//////////////////////////8=">
55
<template>
66
<tparam name="T" class="type"/>
7-
<function name="f1" id="Bs19YS1cqZhrsbv149xgnjRFUAk=">
7+
<function name="f1" requires="std::is_integral_v&lt;T&gt;" id="Bs19YS1cqZhrsbv149xgnjRFUAk=">
88
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="5"/>
99
<return>
1010
<type name="T"/>
@@ -21,7 +21,7 @@
2121
</template>
2222
<template>
2323
<tparam name="T" class="type"/>
24-
<function name="f2" id="uckUKgu5WdbIitoodkl2kXQ7RWI=">
24+
<function name="f2" requires="std::is_integral_v&lt;T&gt;" id="uckUKgu5WdbIitoodkl2kXQ7RWI=">
2525
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="10"/>
2626
<return>
2727
<type name="int"/>
@@ -43,7 +43,7 @@
4343
</namespace>
4444
<template>
4545
<tparam name="T" class="type"/>
46-
<function name="f3" id="HIZ4NeNKvHJFhj0tJIjpjaLL30U=">
46+
<function name="f3" requires="std::is_integral_v&lt;T&gt;" id="HIZ4NeNKvHJFhj0tJIjpjaLL30U=">
4747
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="19"/>
4848
<return>
4949
<type id="r/5vKTgl4cXSK5TnuZ/+P7qmkJ0=" name="B::C"/>
@@ -60,7 +60,7 @@
6060
</template>
6161
<template>
6262
<tparam name="T" class="type"/>
63-
<function name="f4" id="45LJB0/nCsN3KRlVtnRqNrJG818=">
63+
<function name="f4" requires="std::is_integral_v&lt;T&gt;" id="45LJB0/nCsN3KRlVtnRqNrJG818=">
6464
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="24"/>
6565
<return>
6666
<type name="T"/>

test-files/golden-tests/snippets/sqrt.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Declared in `&lt;sqrt&period;cpp&gt;`
3131
----
3232
template&lt;typename T&gt;
3333
T
34-
sqrt(T value);
34+
sqrt(T value)
35+
requires std&colon;&colon;is&lowbar;integral&lowbar;v&lt;T&gt;;
3536
----
3637

3738
=== Description

test-files/golden-tests/snippets/sqrt.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ <h3>Synopsis</h3>
4141
<code class="source-code cpp">
4242
template&lt;typename T&gt;
4343
T
44-
sqrt(T value);
44+
sqrt(T value)
45+
requires std::is_integral_v&lt;T&gt;;
4546
</code>
4647
</pre>
4748
</div>

test-files/golden-tests/snippets/sqrt.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<namespace id="//////////////////////////8=">
55
<template>
66
<tparam name="T" class="type"/>
7-
<function name="sqrt" id="ulFDUE1svTCX8fV/h8EIp4NNbWs=">
7+
<function name="sqrt" requires="std::is_integral_v&lt;T&gt;" id="ulFDUE1svTCX8fV/h8EIp4NNbWs=">
88
<file short-path="sqrt.cpp" source-path="sqrt.cpp" line="15" class="def"/>
99
<return>
1010
<type name="T"/>

0 commit comments

Comments
 (0)