Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if attributes}}[[{{join ", " attributes}}]]
{{#if attributes}}{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
{{/if}}
{{#if isMutable}}mutable
{{/if~}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{/if~}}
{{#if isFriend}}friend
{{/if~}}
{{#if attributes}}{{#unless isFriend}}[[{{join ", " attributes}}]]
{{#if attributes}}{{#unless isFriend}}{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
{{/unless}}{{/if~}}
{{#if constexprKind}}{{constexprKind}}
{{/if~}}
Expand Down
44 changes: 24 additions & 20 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ populate(
{
populate(I.Requires, TRC);
}
else
else if (I.Requires.Written.empty())
{
// Return type SFINAE constraints
if (I.ReturnType &&
Expand Down Expand Up @@ -1200,33 +1200,37 @@ populate(
}

// Extract requires clause from SFINAE context
for (auto it = Template.Args.begin(); it != Template.Args.end();)
if (Template.Requires.Written.empty())
{
auto& arg = *it;
if (!arg)
{
++it;
continue;
}
if (auto* T = dynamic_cast<TypeTArg*>(arg.operator->());
T &&
T->Type &&
!T->Type->Constraints.empty())
for (auto it = Template.Args.begin(); it != Template.Args.end();)
{
for (ExprInfo const& constraint: T->Type->Constraints)
auto& arg = *it;
if (!arg)
{
++it;
continue;
}
if (auto* T = dynamic_cast<TypeTArg*>(arg.operator->());
T &&
T->Type &&
!T->Type->Constraints.empty())
{
if (!Template.Requires.Written.empty())
for (ExprInfo const& constraint: T->Type->Constraints)
{
Template.Requires.Written += " && ";
if (!Template.Requires.Written.empty())
{
Template.Requires.Written += " && ";
}
Template.Requires.Written += constraint.Written;
}
Template.Requires.Written += constraint.Written;
it = Template.Args.erase(it);
continue;
}
it = Template.Args.erase(it);
continue;
++it;
}
++it;
}


// Extract the template parameters if this is a partial specialization
if (auto* CTPSD = dyn_cast<ClassTemplatePartialSpecializationDecl>(CTSD))
{
Expand Down Expand Up @@ -1468,7 +1472,7 @@ populate(
{
populate(TI.Requires, RC);
}
else
else if (TI.Requires.Written.empty())
{
// If there's no requires clause, check if the template
// parameter types we extracted have constraints
Expand Down
20 changes: 7 additions & 13 deletions src/lib/Metadata/Finalizers/ReferenceFinalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,14 @@ finalize(doc::Node& node)

if constexpr(std::derived_from<NodeTy, doc::Reference>)
{
if (!resolveReference(N))
if (!resolveReference(N) &&
!warned_.contains({N.string, current_->Name}))
{
// The warning shouldn't be triggered if the symbol name
// has been explicitly marked excluded in mrdocs.yml.
// Finalizer needs to be updated to handle this case.
// When tagfile support is implemented, we can't
// report an error if the reference exists in the tagfile.
// if constexpr (false)
// {
// report::warn(
// "Failed to resolve reference to '{}' from '{}'",
// N.string,
// current_->Name);
// }
report::warn(
"Failed to resolve reference to '{}' from '{}'",
N.string,
current_->Name);
warned_.insert({N.string, current_->Name});
}
}
});
Expand Down
3 changes: 3 additions & 0 deletions src/lib/Metadata/Finalizers/ReferenceFinalizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "lib/Lib/Info.hpp"
#include "lib/Lib/Lookup.hpp"
#include <set>
#include <utility>

namespace clang::mrdocs {

Expand All @@ -30,6 +32,7 @@ class ReferenceFinalizer
InfoSet& info_;
SymbolLookup& lookup_;
Info* current_ = nullptr;
std::set<std::pair<std::string, std::string>> warned_;

bool
resolveReference(doc::Reference& ref) const;
Expand Down
2 changes: 2 additions & 0 deletions src/test/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ handleDir(
auto const& subdir = entry.path();
Config::Settings subdirSettings = dirSettings;
subdirSettings.sourceRoot = subdir;
subdirSettings.input = {subdir};
std::string const& configPath = files::appendPath(subdir, "mrdocs.yml");
if (files::exists(configPath))
{
Expand Down Expand Up @@ -340,6 +341,7 @@ checkPath(
testArgs.apply(dirSettings, dirs_, argv);
dirSettings.multipage = false;
dirSettings.sourceRoot = inputDir;
dirSettings.input = {inputDir};
std::string const& configPath = files::appendPath(inputDir, "mrdocs.yml");

if (files::exists(configPath))
Expand Down
36 changes: 36 additions & 0 deletions test-files/golden-tests/config/sfinae/redeclare.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
= Reference
:mrdocs:

[#index]
== Global namespace


=== Functions

[cols=1]
|===
| Name

| <<f,`f`>>
|===

[#f]
== f


=== Synopsis


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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;typename T&gt;
void
f(void)
requires std&colon;&colon;is&lowbar;class&lowbar;v&lt;T&gt;;
----



[.small]#Created with https://www.mrdocs.com[MrDocs]#
14 changes: 14 additions & 0 deletions test-files/golden-tests/config/sfinae/redeclare.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// issue #850

#include <type_traits>

template <typename T>
void f(std::enable_if_t<std::is_class_v<T>>);

template <typename T>
void f(std::enable_if_t<std::is_class_v<T>>);

template <typename T>
void f(std::enable_if_t<std::is_class_v<T>>)
{
}
49 changes: 49 additions & 0 deletions test-files/golden-tests/config/sfinae/redeclare.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<html lang="en">
<head>
<title>Reference</title>
</head>
<body>
<div>
<h1>Reference</h1>
<div>
<div>
<h2 id="index">Global namespace</h2>
</div>
<h2>Functions</h2>
<table style="table-layout: fixed; width: 100%;">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#f"><code>f</code></a> </td></tr>
</tbody>
</table>
</div>
<div>
<div>
<h2 id="f">f</h2>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;redeclare.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
template&lt;typename T&gt;
void
f(void)
requires std::is_class_v&lt;T&gt;;
</code>
</pre>
</div>
</div>

</div>
<div>
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions test-files/golden-tests/config/sfinae/redeclare.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
<namespace id="//////////////////////////8=">
<template>
<tparam name="T" class="type"/>
<function name="f" requires="std::is_class_v&lt;T&gt;" id="BLN6H1yQLtKanicO0huYQpQPbnk=">
<file short-path="redeclare.cpp" source-path="redeclare.cpp" line="11" class="def"/>
<file short-path="redeclare.cpp" source-path="redeclare.cpp" line="5"/>
<file short-path="redeclare.cpp" source-path="redeclare.cpp" line="8"/>
<param>
<type name="void"/>
</param>
</function>
</template>
</namespace>
</mrdocs>
36 changes: 36 additions & 0 deletions test-files/golden-tests/config/sfinae/return-based.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
= Reference
:mrdocs:

[#index]
== Global namespace


=== Functions

[cols=1]
|===
| Name

| <<f,`f`>>
|===

[#f]
== f


=== Synopsis


Declared in `&lt;return&hyphen;based&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;typename T&gt;
int
f()
requires std&colon;&colon;is&lowbar;class&lowbar;v&lt;T&gt;;
----



[.small]#Created with https://www.mrdocs.com[MrDocs]#
6 changes: 6 additions & 0 deletions test-files/golden-tests/config/sfinae/return-based.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// issue #849

#include <type_traits>

template <typename T>
std::enable_if_t<std::is_class_v<T>, int> f();
49 changes: 49 additions & 0 deletions test-files/golden-tests/config/sfinae/return-based.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<html lang="en">
<head>
<title>Reference</title>
</head>
<body>
<div>
<h1>Reference</h1>
<div>
<div>
<h2 id="index">Global namespace</h2>
</div>
<h2>Functions</h2>
<table style="table-layout: fixed; width: 100%;">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#f"><code>f</code></a> </td></tr>
</tbody>
</table>
</div>
<div>
<div>
<h2 id="f">f</h2>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;return-based.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
template&lt;typename T&gt;
int
f()
requires std::is_class_v&lt;T&gt;;
</code>
</pre>
</div>
</div>

</div>
<div>
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4>
</div>
</body>
</html>
15 changes: 15 additions & 0 deletions test-files/golden-tests/config/sfinae/return-based.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
<namespace id="//////////////////////////8=">
<template>
<tparam name="T" class="type"/>
<function name="f" requires="std::is_class_v&lt;T&gt;" id="+zl/sg3GXOLbrJGwRx2qkepftDY=">
<file short-path="return-based.cpp" source-path="return-based.cpp" line="5"/>
<return>
<type name="int"/>
</return>
</function>
</template>
</namespace>
</mrdocs>
3 changes: 0 additions & 3 deletions test-files/golden-tests/core/libcxx.yml

This file was deleted.

Loading