diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c24266be..7d54a4bdf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/CMakeLists.txt b/CMakeLists.txt index 9631325e8..7afea0025 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/docs/modules/ROOT/pages/usage.adoc b/docs/modules/ROOT/pages/usage.adoc index 473aa4297..12eed3623 100644 --- a/docs/modules/ROOT/pages/usage.adoc +++ b/docs/modules/ROOT/pages/usage.adoc @@ -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 `` or `` 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++ -nostdlib++` 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++ -nostdlib++` and `-nostdinc` flags were passed to Clang. Additionally: - When `use-system-stdlib` is `false`, MrDocs will use the bundled libc++ headers available in `/share/mrdocs/headers/libcxx` and `/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 `/share/mrdocs/headers/libc-stubs`. This path can be adjusted with the `libc-includes` option. diff --git a/docs/mrdocs.schema.json b/docs/mrdocs.schema.json index 8865cd48f..ff800a73e 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -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, @@ -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, diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index a33826061..6e6aec336 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -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]; diff --git a/src/lib/ConfigOptions.json b/src/lib/ConfigOptions.json index a75281f17..87b070c1c 100644 --- a/src/lib/ConfigOptions.json +++ b/src/lib/ConfigOptions.json @@ -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", @@ -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", diff --git a/src/lib/MrDocsSettingsDB.cpp b/src/lib/MrDocsSettingsDB.cpp index 5740475ab..b8cd15d26 100644 --- a/src/lib/MrDocsSettingsDB.cpp +++ b/src/lib/MrDocsSettingsDB.cpp @@ -11,6 +11,7 @@ #include "MrDocsSettingsDB.hpp" #include +#include namespace clang { namespace mrdocs { @@ -59,6 +60,8 @@ MrDocsSettingsDB::MrDocsSettingsDB(ConfigImpl const& config) return {}; }); } + + llvm::ErrorOr clangPath = llvm::sys::findProgramByName("clang"); for (auto const& pathName: sourceFiles) { @@ -66,11 +69,9 @@ MrDocsSettingsDB::MrDocsSettingsDB(ConfigImpl const& config) auto parentDir = files::getParentDir(pathName); std::vector 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); diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index 31ea0e38d..66b1133ad 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -114,7 +114,10 @@ handleFile( // Create an adjusted MrDocsDatabase auto parentDir = files::getParentDir(filePath); - std::unordered_map> defaultIncludePaths; + std::unordered_map> defaultIncludePaths = { + {"clang", {MRDOCS_TEST_FILES_DIR "/include"}}, + {"clang-cl", {MRDOCS_TEST_FILES_DIR "/include"}}, + }; MrDocsCompilationDatabase compilations( llvm::StringRef(parentDir), SingleFileDB(filePath), config, defaultIncludePaths); diff --git a/test-files/golden-tests/config/sfinae/redeclare.cpp b/test-files/golden-tests/config/sfinae/redeclare.cpp index 7eb75ff95..11e39da79 100644 --- a/test-files/golden-tests/config/sfinae/redeclare.cpp +++ b/test-files/golden-tests/config/sfinae/redeclare.cpp @@ -1,6 +1,6 @@ // issue #850 -#include +#include template void f(std::enable_if_t>); diff --git a/test-files/golden-tests/config/sfinae/redeclare.yml b/test-files/golden-tests/config/sfinae/redeclare.yml new file mode 100644 index 000000000..8061ae78c --- /dev/null +++ b/test-files/golden-tests/config/sfinae/redeclare.yml @@ -0,0 +1,2 @@ +warn-if-doc-error: false +warn-no-paramdoc: false diff --git a/test-files/golden-tests/config/sfinae/return-based.cpp b/test-files/golden-tests/config/sfinae/return-based.cpp index e701be105..5d9fc4d16 100644 --- a/test-files/golden-tests/config/sfinae/return-based.cpp +++ b/test-files/golden-tests/config/sfinae/return-based.cpp @@ -1,6 +1,6 @@ // issue #849 -#include +#include template std::enable_if_t, int> f(); diff --git a/test-files/golden-tests/config/sfinae/return-based.yml b/test-files/golden-tests/config/sfinae/return-based.yml new file mode 100644 index 000000000..8061ae78c --- /dev/null +++ b/test-files/golden-tests/config/sfinae/return-based.yml @@ -0,0 +1,2 @@ +warn-if-doc-error: false +warn-no-paramdoc: false diff --git a/test-files/golden-tests/core/libcxx.yml b/test-files/golden-tests/core/libcxx.yml new file mode 100644 index 000000000..b3b0f2a2d --- /dev/null +++ b/test-files/golden-tests/core/libcxx.yml @@ -0,0 +1,2 @@ +use-system-stdlib: false +use-system-libc: false diff --git a/test-files/golden-tests/snippets/sqrt.cpp b/test-files/golden-tests/snippets/sqrt.cpp index 24d30487a..1ff09c6fd 100644 --- a/test-files/golden-tests/snippets/sqrt.cpp +++ b/test-files/golden-tests/snippets/sqrt.cpp @@ -1,5 +1,4 @@ -#include -#include +#include /** Computes the square root of an integral value. diff --git a/test-files/golden-tests/snippets/sqrt.xml b/test-files/golden-tests/snippets/sqrt.xml index ef5b19c51..3840317a1 100644 --- a/test-files/golden-tests/snippets/sqrt.xml +++ b/test-files/golden-tests/snippets/sqrt.xml @@ -5,7 +5,7 @@