Skip to content

Commit 3777824

Browse files
committed
sfinae constraints are not repopulated
#fix fix #850
1 parent 375d913 commit 3777824

File tree

5 files changed

+140
-20
lines changed

5 files changed

+140
-20
lines changed

src/lib/AST/ASTVisitor.cpp

+24-20
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ populate(
811811
{
812812
populate(I.Requires, TRC);
813813
}
814-
else
814+
else if (I.Requires.Written.empty())
815815
{
816816
// Return type SFINAE constraints
817817
if (I.ReturnType &&
@@ -1200,33 +1200,37 @@ populate(
12001200
}
12011201

12021202
// Extract requires clause from SFINAE context
1203-
for (auto it = Template.Args.begin(); it != Template.Args.end();)
1203+
if (Template.Requires.Written.empty())
12041204
{
1205-
auto& arg = *it;
1206-
if (!arg)
1207-
{
1208-
++it;
1209-
continue;
1210-
}
1211-
if (auto* T = dynamic_cast<TypeTArg*>(arg.operator->());
1212-
T &&
1213-
T->Type &&
1214-
!T->Type->Constraints.empty())
1205+
for (auto it = Template.Args.begin(); it != Template.Args.end();)
12151206
{
1216-
for (ExprInfo const& constraint: T->Type->Constraints)
1207+
auto& arg = *it;
1208+
if (!arg)
1209+
{
1210+
++it;
1211+
continue;
1212+
}
1213+
if (auto* T = dynamic_cast<TypeTArg*>(arg.operator->());
1214+
T &&
1215+
T->Type &&
1216+
!T->Type->Constraints.empty())
12171217
{
1218-
if (!Template.Requires.Written.empty())
1218+
for (ExprInfo const& constraint: T->Type->Constraints)
12191219
{
1220-
Template.Requires.Written += " && ";
1220+
if (!Template.Requires.Written.empty())
1221+
{
1222+
Template.Requires.Written += " && ";
1223+
}
1224+
Template.Requires.Written += constraint.Written;
12211225
}
1222-
Template.Requires.Written += constraint.Written;
1226+
it = Template.Args.erase(it);
1227+
continue;
12231228
}
1224-
it = Template.Args.erase(it);
1225-
continue;
1229+
++it;
12261230
}
1227-
++it;
12281231
}
12291232

1233+
12301234
// Extract the template parameters if this is a partial specialization
12311235
if (auto* CTPSD = dyn_cast<ClassTemplatePartialSpecializationDecl>(CTSD))
12321236
{
@@ -1468,7 +1472,7 @@ populate(
14681472
{
14691473
populate(TI.Requires, RC);
14701474
}
1471-
else
1475+
else if (TI.Requires.Written.empty())
14721476
{
14731477
// If there's no requires clause, check if the template
14741478
// parameter types we extracted have constraints
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
8+
=== Functions
9+
10+
[cols=1]
11+
|===
12+
| Name
13+
14+
| <<f,`f`>>
15+
|===
16+
17+
[#f]
18+
== f
19+
20+
21+
=== Synopsis
22+
23+
24+
Declared in `&lt;redeclare&period;cpp&gt;`
25+
26+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
27+
----
28+
template&lt;typename T&gt;
29+
void
30+
f(void)
31+
requires std&colon;&colon;is&lowbar;class&lowbar;v&lt;T&gt;;
32+
----
33+
34+
35+
36+
[.small]#Created with https://www.mrdocs.com[MrDocs]#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// issue #850
2+
3+
#include <type_traits>
4+
5+
template <typename T>
6+
void f(std::enable_if_t<std::is_class_v<T>>);
7+
8+
template <typename T>
9+
void f(std::enable_if_t<std::is_class_v<T>>);
10+
11+
template <typename T>
12+
void f(std::enable_if_t<std::is_class_v<T>>)
13+
{
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<html lang="en">
2+
<head>
3+
<title>Reference</title>
4+
</head>
5+
<body>
6+
<div>
7+
<h1>Reference</h1>
8+
<div>
9+
<div>
10+
<h2 id="index">Global namespace</h2>
11+
</div>
12+
<h2>Functions</h2>
13+
<table style="table-layout: fixed; width: 100%;">
14+
<thead>
15+
<tr>
16+
<th>Name</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr>
21+
<td><a href="#f"><code>f</code></a> </td></tr>
22+
</tbody>
23+
</table>
24+
</div>
25+
<div>
26+
<div>
27+
<h2 id="f">f</h2>
28+
</div>
29+
<div>
30+
<h3>Synopsis</h3>
31+
<div>
32+
Declared in <code>&lt;redeclare.cpp&gt;</code></div>
33+
<pre>
34+
<code class="source-code cpp">
35+
template&lt;typename T&gt;
36+
void
37+
f(void)
38+
requires std::is_class_v&lt;T&gt;;
39+
</code>
40+
</pre>
41+
</div>
42+
</div>
43+
44+
</div>
45+
<div>
46+
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4>
47+
</div>
48+
</body>
49+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
4+
<namespace id="//////////////////////////8=">
5+
<template>
6+
<tparam name="T" class="type"/>
7+
<function name="f" requires="std::is_class_v&lt;T&gt;" id="BLN6H1yQLtKanicO0huYQpQPbnk=">
8+
<file short-path="redeclare.cpp" source-path="redeclare.cpp" line="11" class="def"/>
9+
<file short-path="redeclare.cpp" source-path="redeclare.cpp" line="5"/>
10+
<file short-path="redeclare.cpp" source-path="redeclare.cpp" line="8"/>
11+
<param>
12+
<type name="void"/>
13+
</param>
14+
</function>
15+
</template>
16+
</namespace>
17+
</mrdocs>

0 commit comments

Comments
 (0)