diff --git a/.clang-format b/.clang-format index 1033103e5..f31bb5f34 100644 --- a/.clang-format +++ b/.clang-format @@ -227,3 +227,7 @@ IncludeCategories: # Comments FixNamespaceComments: true CommentPragmas: '^ clang-format' + +--- +Language: Json +BasedOnStyle: llvm diff --git a/CMakeLists.txt b/CMakeLists.txt index f96cea1ab..fe1472813 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -387,6 +387,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 f904ece17..5aa7d5199 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -557,7 +557,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, @@ -567,7 +567,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/docs/website/snippets/sqrt.cpp b/docs/website/snippets/sqrt.cpp index 24d30487a..dde92f52c 100644 --- a/docs/website/snippets/sqrt.cpp +++ b/docs/website/snippets/sqrt.cpp @@ -1,5 +1,4 @@ #include -#include /** Computes the square root of an integral value. diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index 303a8e12c..73c3f31a5 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -2352,7 +2352,8 @@ extractSFINAEInfo(clang::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_); clang::TemplateArgument ArgsI = Args[I]; diff --git a/src/lib/ConfigOptions.json b/src/lib/ConfigOptions.json index dc8212890..9fc57d73e 100644 --- a/src/lib/ConfigOptions.json +++ b/src/lib/ConfigOptions.json @@ -493,7 +493,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", @@ -513,7 +513,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 d32b0cc6b..edbc9e0ce 100644 --- a/src/lib/MrDocsSettingsDB.cpp +++ b/src/lib/MrDocsSettingsDB.cpp @@ -11,6 +11,7 @@ #include "MrDocsSettingsDB.hpp" #include +#include namespace mrdocs { @@ -60,17 +61,18 @@ MrDocsSettingsDB::MrDocsSettingsDB(ConfigImpl const& config) }); } + llvm::ErrorOr clangPath = llvm::sys::findProgramByName( + "clang"); + for (auto const& pathName: sourceFiles) { // auto fileName = files::getFileName(pathName); 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 847e5825d..07b0e4c94 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -125,7 +125,10 @@ handleFile( auto parentDir = files::getParentDir(filePath); std::unordered_map> - defaultIncludePaths; + defaultIncludePaths = { + { "clang", { MRDOCS_TEST_FILES_DIR "/include" } }, + { "clang-cl", { MRDOCS_TEST_FILES_DIR "/include" } }, + }; // Test normally { diff --git a/test-files/golden-tests/config/sfinae/redeclare.cpp b/test-files/golden-tests/config/sfinae/redeclare.cpp index 7eb75ff95..7b122fa88 100644 --- a/test-files/golden-tests/config/sfinae/redeclare.cpp +++ b/test-files/golden-tests/config/sfinae/redeclare.cpp @@ -10,5 +10,4 @@ void f(std::enable_if_t>); template void f(std::enable_if_t>) -{ -} \ No newline at end of file +{} 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.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..dde92f52c 100644 --- a/test-files/golden-tests/snippets/sqrt.cpp +++ b/test-files/golden-tests/snippets/sqrt.cpp @@ -1,5 +1,4 @@ #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 @@