Skip to content
Draft
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
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ jobs:
uses: seanmiddleditch/gha-setup-ninja@v5
if: ${{ runner.os == 'Windows' }}

- name: Setup C++
uses: alandefreitas/cpp-actions/setup-cpp@v1.8.10
id: setup-cpp
with:
compiler: ${{ matrix.compiler }}
version: ${{ matrix.version }}

- name: Download MrDocs package
uses: actions/download-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ if (WIN32)
mrdocs-core
PUBLIC
/permissive- # strict C++
/Zc:__cplusplus # report C++ standard support
/W4 # enable all warnings
/MP # multi-processor compilation
/EHs # C++ Exception handling
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ It's also common for libraries to depend on the C++ standard library, the C stan

That means unless `-nostdinc` is defined, all systems include paths are included. This is what allows the user to also use headers like `<Windows.h>` or `<linux/version.h>` without explicitly including anything else, even though they are not part of the C standard library. This is often seen as a convenience but can lead to portability issues.

In this context, MrDocs provides the `use-system-stdlib` and `use-system-libc` options. Both are set as `false` by default, meaning MrDocs will compile the code as if the `-nostdinc&plus;&plus; -nostdlib&plus;&plus;` and `-nostdinc` flags were passed to Clang. Additionally:
In this context, MrDocs provides the `use-system-stdlib` and `use-system-libc` options. Both are set as `true` by default; setting both to `false` results in MrDocs compiling the code as if the `-nostdinc&plus;&plus; -nostdlib&plus;&plus;` and `-nostdinc` flags were passed to Clang. Additionally:

- When `use-system-stdlib` is `false`, MrDocs will use the bundled libc&plus;&plus; headers available in `<mrdocs-root>/share/mrdocs/headers/libcxx` and `<mrdocs-root>/share/mrdocs/headers/clang`. These paths can be adjusted with the `stdlib-includes` option.
- When `use-system-libc` is `false`, MrDocs will use the bundled libc stubs available in `<mrdocs-root>/share/mrdocs/headers/libc-stubs`. This path can be adjusted with the `libc-includes` option.
Expand Down
4 changes: 2 additions & 2 deletions docs/mrdocs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@
"type": "string"
},
"use-system-libc": {
"default": false,
"default": true,
"description": "To achieve reproducible results, MrDocs bundles the LibC headers with its definitions. To use the C standard library available in the system instead, set this option to true.",
"enum": [
true,
Expand All @@ -557,7 +557,7 @@
"type": "boolean"
},
"use-system-stdlib": {
"default": false,
"default": true,
"description": "To achieve reproducible results, MrDocs bundles the LibC++ headers. To use the C++ standard library available in the system instead, set this option to true.",
"enum": [
true,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,7 @@ extractSFINAEInfo(QualType const T)
Result.Type = resultType->getAsType();
for (std::size_t I = 0; I < Args.size(); ++I)
{
if (SFINAEControl->ControllingParams[I])
if (I < SFINAEControl->ControllingParams.size() && SFINAEControl->ControllingParams[I])
{
MRDOCS_SYMBOL_TRACE(Args[I], context_);
TemplateArgument ArgsI = Args[I];
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ConfigOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@
"brief": "Use the system C++ standard library",
"details": "To achieve reproducible results, MrDocs bundles the LibC++ headers. To use the C++ standard library available in the system instead, set this option to true.",
"type": "bool",
"default": false
"default": true
},
{
"name": "stdlib-includes",
Expand All @@ -506,7 +506,7 @@
"brief": "Use the system C standard library",
"details": "To achieve reproducible results, MrDocs bundles the LibC headers with its definitions. To use the C standard library available in the system instead, set this option to true.",
"type": "bool",
"default": false
"default": true
},
{
"name": "libc-includes",
Expand Down
7 changes: 4 additions & 3 deletions src/lib/MrDocsSettingsDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "MrDocsSettingsDB.hpp"
#include <mrdocs/Support/Path.hpp>
#include <llvm/Support/Program.h>

namespace clang {
namespace mrdocs {
Expand Down Expand Up @@ -59,18 +60,18 @@ MrDocsSettingsDB::MrDocsSettingsDB(ConfigImpl const& config)
return {};
});
}

llvm::ErrorOr<std::string> clangPath = llvm::sys::findProgramByName("clang");

for (auto const& pathName: sourceFiles)
{
// auto fileName = files::getFileName(pathName);
auto parentDir = files::getParentDir(pathName);

std::vector<std::string> cmds;
cmds.emplace_back("clang");
cmds.emplace_back(clangPath ? *clangPath : "clang");
cmds.emplace_back("-fsyntax-only");
cmds.emplace_back("-std=c++23");
cmds.emplace_back("-pedantic-errors");
cmds.emplace_back("-Werror");
cmds.emplace_back("-x");
cmds.emplace_back("c++");
cmds.emplace_back(pathName);
Expand Down
5 changes: 4 additions & 1 deletion src/test/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ handleFile(

// Create an adjusted MrDocsDatabase
auto parentDir = files::getParentDir(filePath);
std::unordered_map<std::string, std::vector<std::string>> defaultIncludePaths;
std::unordered_map<std::string, std::vector<std::string>> defaultIncludePaths = {
{"clang", {MRDOCS_TEST_FILES_DIR "/include"}},
{"clang-cl", {MRDOCS_TEST_FILES_DIR "/include"}},
};
MrDocsCompilationDatabase compilations(
llvm::StringRef(parentDir), SingleFileDB(filePath), config, defaultIncludePaths);

Expand Down
2 changes: 1 addition & 1 deletion test-files/golden-tests/config/sfinae/redeclare.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// issue #850

#include <type_traits>
#include <std.hpp>

template <typename T>
void f(std::enable_if_t<std::is_class_v<T>>);
Expand Down
2 changes: 2 additions & 0 deletions test-files/golden-tests/config/sfinae/redeclare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
warn-if-doc-error: false
warn-no-paramdoc: false
2 changes: 1 addition & 1 deletion test-files/golden-tests/config/sfinae/return-based.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// issue #849

#include <type_traits>
#include <std.hpp>

template <typename T>
std::enable_if_t<std::is_class_v<T>, int> f();
2 changes: 2 additions & 0 deletions test-files/golden-tests/config/sfinae/return-based.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
warn-if-doc-error: false
warn-no-paramdoc: false
2 changes: 2 additions & 0 deletions test-files/golden-tests/core/libcxx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use-system-stdlib: false
use-system-libc: false
3 changes: 1 addition & 2 deletions test-files/golden-tests/snippets/sqrt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <type_traits>
#include <stdexcept>
#include <std.hpp>

/** Computes the square root of an integral value.

Expand Down
2 changes: 1 addition & 1 deletion test-files/golden-tests/snippets/sqrt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<template>
<tparam name="T" class="type"/>
<function name="sqrt" requires="std::is_integral_v&lt;T&gt;" id="Ys2WHtLDVIke+oa2xBB2ekE+xds=">
<file short-path="sqrt.cpp" source-path="sqrt.cpp" line="15" class="def"/>
<file short-path="sqrt.cpp" source-path="sqrt.cpp" line="14" class="def"/>
<return>
<type name="T"/>
</return>
Expand Down
2 changes: 2 additions & 0 deletions test-files/golden-tests/snippets/sqrt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
warn-if-doc-error: false
warn-no-paramdoc: false
3 changes: 1 addition & 2 deletions test-files/golden-tests/symbols/function/sfinae.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <type_traits>
#include <stdexcept>
#include <std.hpp>

/// Enabled via return type
template <class T>
Expand Down
34 changes: 17 additions & 17 deletions test-files/golden-tests/symbols/function/sfinae.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<namespace id="//////////////////////////8=">
<namespace name="B" id="kPgq2AM8TvyGDGm5jEWfqYlOPmY=">
<struct name="C" id="r/5vKTgl4cXSK5TnuZ/+P7qmkJ0=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="15" class="def"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="14" class="def"/>
<doc>
<related>
<reference id="OiYqKxV5vNAeh0jqRKIygSwyW4o=">::f3</reference>
Expand All @@ -16,7 +16,7 @@
<tparam name="T" class="type"/>
<tparam name="Enable" class="type" default="void"/>
<class name="A" id="m/JW900ik2XLYvUdA4MCuWZQd80=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="68" class="def"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="67" class="def"/>
<doc>
<brief>
<text>The partial specialization of A is enabled via a template parameter</text>
Expand All @@ -28,7 +28,7 @@
<tparam name="T" class="type"/>
<targ class="type" type="T"/>
<class name="A" id="f80OzcD5UlgQ2KOvUj+MvoJcAFE=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="73" class="def"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="72" class="def"/>
<doc>
<brief>
<text>Specialization for integral types</text>
Expand All @@ -40,14 +40,14 @@
<tparam name="T" class="type"/>
<tparam name="Enable" class="type" default="void"/>
<struct name="S" id="IZrmVBMJu1uvsP9zur5JVrwgYmE=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="76" class="def"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="75" class="def"/>
<doc>
<brief>
<text>SFINAE with std::void_t</text>
</brief>
</doc>
<function name="store" id="KmwKarrWHSv7aalrBX18hjPbEfs=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="79" class="def"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="78" class="def"/>
<param>
<type class="pointer">
<pointee-type name="void" cv-qualifiers="const"/>
Expand All @@ -61,14 +61,14 @@
<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"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="83" class="def"/>
<doc>
<brief>
<text>SFINAE with std::void_t</text>
</brief>
</doc>
<function name="store" id="2KfuSRGlpNo9Lk/lk1bhwZqm/BY=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="86" class="def"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="85" class="def"/>
<param>
<type class="pointer">
<pointee-type name="void" cv-qualifiers="const"/>
Expand All @@ -80,7 +80,7 @@
<template>
<tparam name="T" class="type"/>
<function name="f1" requires="std::is_integral_v&lt;T&gt;" id="1VN+nmJkLcjg6wK0C6XNq8dG1Ro=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="5"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="4"/>
<return>
<type name="T"/>
</return>
Expand All @@ -97,7 +97,7 @@
<template requires="std::is_integral_v&lt;T&gt;">
<tparam name="T" class="type"/>
<function name="f10" id="MX3B1GMAk3D0sirBOV2sk9C49uw=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="64"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="63"/>
<param name="value">
<type name="T"/>
</param>
Expand All @@ -120,7 +120,7 @@
<template>
<tparam name="T" class="type"/>
<function name="f2" requires="std::is_integral_v&lt;T&gt;" id="7RxfINQ5PQyMFT7lVKhcQZiocmU=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="10"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="9"/>
<return>
<type name="int"/>
</return>
Expand All @@ -137,7 +137,7 @@
<template>
<tparam name="T" class="type"/>
<function name="f3" requires="std::is_integral_v&lt;T&gt;" id="OiYqKxV5vNAeh0jqRKIygSwyW4o=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="19"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="18"/>
<return>
<type id="r/5vKTgl4cXSK5TnuZ/+P7qmkJ0=" name="B::C"/>
</return>
Expand All @@ -157,7 +157,7 @@
<template>
<tparam name="T" class="type"/>
<function name="f4" requires="std::is_integral_v&lt;T&gt;" id="oQV00j0v7EfuVl9bWFumA28DNZM=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="24"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="23"/>
<return>
<type name="T"/>
</return>
Expand All @@ -174,7 +174,7 @@
<template requires="std::is_integral_v&lt;T&gt;">
<tparam name="T" class="type"/>
<function name="f5" id="4Z8f2LwbeJzKuu95VpPC5b3UKZQ=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="29"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="28"/>
<return>
<type name="T"/>
</return>
Expand All @@ -191,7 +191,7 @@
<template requires="std::is_integral_v&lt;T&gt;">
<tparam name="T" class="type"/>
<function name="f6" id="QQ+RfmlXmyvRCoT+N6iLEixOE3w=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="34"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="33"/>
<return>
<type name="T"/>
</return>
Expand All @@ -208,7 +208,7 @@
<template requires="std::is_integral_v&lt;T&gt;">
<tparam name="T" class="type"/>
<function name="f7" id="5j4YKg9GCIyC/kpDPExDouNRI8E=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="39"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="38"/>
<param name="value">
<type name="T"/>
</param>
Expand All @@ -222,7 +222,7 @@
<template>
<tparam name="T" class="type"/>
<function name="f8" requires="std::is_integral_v&lt;T&gt;" id="N7SAlDvKDvPlACsckMXASo+muPE=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="43"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="42"/>
<return>
<type name="T"/>
</return>
Expand All @@ -239,7 +239,7 @@
<template>
<tparam name="T" class="type"/>
<function name="f9" requires="std::is_integral_v&lt;T&gt;" id="njCzIgSzvUpYyI1eg28pJ1dPwcM=">
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="48"/>
<file short-path="sfinae.cpp" source-path="sfinae.cpp" line="47"/>
<return>
<type name="T"/>
</return>
Expand Down
37 changes: 37 additions & 0 deletions test-files/include/std.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace std
{

template <bool C, typename T = void>
struct enable_if
{
using type = T;
};
template <typename T>
struct enable_if<false, T>
{};

template <bool C, typename T = void>
using enable_if_t = typename enable_if<C, T>::type;

template <typename ...Ts>
using void_t = void;

template <typename T>
struct is_integral
{
static constexpr bool value = true;
};

template <typename T>
bool is_integral_v = is_integral<T>::value;

template <typename T>
struct is_class
{
static constexpr bool value = true;
};

template <typename T>
bool is_class_v = is_class<T>::value;

}
2 changes: 1 addition & 1 deletion util/generate-config-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ def generate_config_info_inc(config):
def generate_header_comment():
header_comment = '/*\n'
header_comment += ' * This file is generated automatically from the json file\n'
header_comment += ' * `src/lib/Lib/ConfigOptions.json`. Do not edit this file\n'
header_comment += ' * `src/lib/ConfigOptions.json`. Do not edit this file\n'
header_comment += ' * manually. Instead, edit the json file and run the script\n'
header_comment += ' * `util/generate-config-info.py` to regenerate this file.\n'
header_comment += ' */\n\n'
Expand Down
Loading