From 1e6db9338a8246776fd453aa35cfc72d5266e1a2 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 09:25:50 +0200 Subject: [PATCH 01/17] avoid msvc emulation --- src/lib/MrDocsCompilationDatabase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index e565db784..e0396e877 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -288,7 +288,7 @@ adjustCommandLine( // Copy the compiler path // ------------------------------------------------------ std::string const& progName = cmdline.front(); - std::vector new_cmdline = {progName}; + std::vector new_cmdline = {std::string{"clang"}}; // ------------------------------------------------------ // Convert to InputArgList @@ -317,7 +317,7 @@ adjustCommandLine( // ------------------------------------------------------ // Add flags to ignore all warnings. Any options that // affect warnings will be discarded later. - new_cmdline.emplace_back(is_clang_cl ? "/w" : "-w"); + new_cmdline.emplace_back("-w"); new_cmdline.emplace_back("-fsyntax-only"); // ------------------------------------------------------ From 9427cf135c326bdaddb46f8ba3fd851905f579d9 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 09:45:56 +0200 Subject: [PATCH 02/17] skip some msvc args --- src/lib/MrDocsCompilationDatabase.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index e0396e877..104f44a1e 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -219,10 +219,10 @@ isValidMrDocsOption( driver::options::OPT_clang_ignored_gcc_optimization_f_Group, driver::options::OPT_clang_ignored_legacy_options_Group, driver::options::OPT_clang_ignored_m_Group, - driver::options::OPT_flang_ignored_w_Group -#if 0 + driver::options::OPT_flang_ignored_w_Group, + // input file options - driver::options::OPT_INPUT, + //driver::options::OPT_INPUT, // output file options driver::options::OPT_o, @@ -237,11 +237,10 @@ isValidMrDocsOption( driver::options::OPT__SLASH_Fr, driver::options::OPT__SLASH_Fm, driver::options::OPT__SLASH_Fx, -#endif - // driver::options::OPT__SLASH_TP - // driver::options::OPT__SLASH_Tp - // driver::options::OPT__SLASH_TC - // driver::options::OPT__SLASH_Tc + driver::options::OPT__SLASH_TP, + driver::options::OPT__SLASH_Tp, + driver::options::OPT__SLASH_TC, + driver::options::OPT__SLASH_Tc )) { return false; From bb07fd28ff4b1eca8fe107bba77cbe2a7f4227c2 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 11:33:21 +0200 Subject: [PATCH 03/17] translate args --- src/lib/MrDocsCompilationDatabase.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 104f44a1e..8a810f84a 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -514,10 +514,14 @@ adjustCommandLine( { continue; } - new_cmdline.insert( - new_cmdline.end(), - cmdline.begin() + idx0, - cmdline.begin() + idx); + + // Append the translated arguments to the new command line + llvm::opt::ArgStringList output; + arg->render(args, output); + + for (auto const& v : output) { + new_cmdline.push_back(v); + } } return new_cmdline; From ad395e44d48c19728d36c2e8ce10200108bc1ebd Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 11:45:32 +0200 Subject: [PATCH 04/17] tweak --- src/lib/MrDocsCompilationDatabase.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 8a810f84a..bbf7b704a 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -299,18 +299,6 @@ adjustCommandLine( cmdLineCStrs.data(), cmdLineCStrs.data() + cmdLineCStrs.size()); - // ------------------------------------------------------ - // Get driver mode - // ------------------------------------------------------ - // The driver mode distinguishes between clang/gcc and msvc - // command line option formats. The value is deduced from - // the `-drive-mode` option or from `progName`. - // Common values are "gcc", "g++", "cpp", "cl" and "flang". - StringRef const driver_mode = driver::getDriverMode(progName, cmdLineCStrs); - // Identify if we should use "msvc/clang-cl" or "clang/gcc" format - // for options. - bool const is_clang_cl = driver::IsClangCL(driver_mode); - // ------------------------------------------------------ // Supress all warnings // ------------------------------------------------------ @@ -491,6 +479,18 @@ adjustCommandLine( new_cmdline.emplace_back(std::format("-I{}", inc)); } + // ------------------------------------------------------ + // Get driver mode + // ------------------------------------------------------ + // The driver mode distinguishes between clang/gcc and msvc + // command line option formats. The value is deduced from + // the `-drive-mode` option or from `progName`. + // Common values are "gcc", "g++", "cpp", "cl" and "flang". + StringRef const driver_mode = driver::getDriverMode(progName, cmdLineCStrs); + // Identify if we should use "msvc/clang-cl" or "clang/gcc" format + // for options. + bool const is_clang_cl = driver::IsClangCL(driver_mode); + // ------------------------------------------------------ // Adjust each argument in the command line // ------------------------------------------------------ From 1b05a940d76dab1fbd522f9918b7e189e7886958 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 12:18:27 +0200 Subject: [PATCH 05/17] ignore more msvc options --- src/lib/MrDocsCompilationDatabase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index bbf7b704a..778384d92 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -220,6 +220,8 @@ isValidMrDocsOption( driver::options::OPT_clang_ignored_legacy_options_Group, driver::options::OPT_clang_ignored_m_Group, driver::options::OPT_flang_ignored_w_Group, + driver::options::OPT__SLASH_O, + driver::options::OPT__SLASH_EH, // input file options //driver::options::OPT_INPUT, From 22aae97e11adf0aeeca5645d0f43d080a7eaf9ec Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 13:01:25 +0200 Subject: [PATCH 06/17] more... --- src/lib/MrDocsCompilationDatabase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 778384d92..7bdc4b1cb 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -222,6 +222,8 @@ isValidMrDocsOption( driver::options::OPT_flang_ignored_w_Group, driver::options::OPT__SLASH_O, driver::options::OPT__SLASH_EH, + driver::options::OPT__SLASH_GR, + driver::options::OPT__SLASH_GR_, // input file options //driver::options::OPT_INPUT, From 04747884574d757af2cdbe0f0f58264236d12fd7 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 13:04:39 +0200 Subject: [PATCH 07/17] fix unused --- src/lib/MrDocsCompilationDatabase.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 7bdc4b1cb..1b9076060 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -510,8 +510,6 @@ adjustCommandLine( while (idx < cmdline.size()) { // Parse one argument as a Clang option - // ParseOneArg updates Index to the next argument to be parsed. - unsigned const idx0 = idx; std::unique_ptr arg = opts_table.ParseOneArg(args, idx, visibility); if (!isValidMrDocsOption(workingDir, arg)) From 1ce477caed92fd02462a37aa10d00a4c0f4c0669 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 14:14:08 +0200 Subject: [PATCH 08/17] Translate clang-cl /std: into clang -std= --- src/lib/MrDocsCompilationDatabase.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 1b9076060..ae21f9b2c 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -402,7 +402,7 @@ adjustCommandLine( isExplicitCCompileCommand || (!isExplicitCppCompileCommand && isImplicitCSourceFile); constexpr auto is_std_option = [](std::string_view const opt) { - return opt.starts_with("-std=") || opt.starts_with("--std=") || opt.starts_with("/std:"); + return opt.starts_with("-std=") || opt.starts_with("--std=") || opt.starts_with("/std:") || opt.starts_with("-std:"); }; if (std::ranges::find_if(cmdline, is_std_option) == cmdline.end()) { @@ -517,12 +517,32 @@ adjustCommandLine( continue; } + // Translate clang-cl /std: into clang -std= + const llvm::opt::Option opt = + arg->getOption().getUnaliasedOption(); + if (opt.matches(clang::driver::options::OPT__SLASH_std)) + { + MRDOCS_ASSERT(arg->getNumValues() == 1); + + std::string_view v = arg->getValue(); + if (v == "c++latest" || v == "c++preview") + { + new_cmdline.emplace_back("-std=c++23"); + } + else // c++14,c++17,c++20,c11,c17 + { + new_cmdline.emplace_back(std::format("-std={}", v)); + } + continue; + } + // Append the translated arguments to the new command line llvm::opt::ArgStringList output; arg->render(args, output); - for (auto const& v : output) { - new_cmdline.push_back(v); + for (auto const& v : output) + { + new_cmdline.emplace_back(v); } } From dc42cfffaccd3a0446a5c5969670d0bf8e745a65 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 10 Sep 2025 14:46:53 +0200 Subject: [PATCH 09/17] typo --- src/lib/MrDocsCompilationDatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index ae21f9b2c..1942550fb 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -525,7 +525,7 @@ adjustCommandLine( MRDOCS_ASSERT(arg->getNumValues() == 1); std::string_view v = arg->getValue(); - if (v == "c++latest" || v == "c++preview") + if (v == "c++latest" || v == "c++23preview") { new_cmdline.emplace_back("-std=c++23"); } From c1331119e53cbbe8eb346a2de605a9595ac1f43e Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Thu, 11 Sep 2025 09:03:11 +0200 Subject: [PATCH 10/17] tweaks --- src/lib/MrDocsCompilationDatabase.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 1942550fb..5017c5a3b 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -402,9 +402,10 @@ adjustCommandLine( isExplicitCCompileCommand || (!isExplicitCppCompileCommand && isImplicitCSourceFile); constexpr auto is_std_option = [](std::string_view const opt) { - return opt.starts_with("-std=") || opt.starts_with("--std=") || opt.starts_with("/std:") || opt.starts_with("-std:"); + return opt.starts_with("-std=") || opt.starts_with("--std=") || + opt.starts_with("/std:") || opt.starts_with("-std:"); }; - if (std::ranges::find_if(cmdline, is_std_option) == cmdline.end()) + if (std::ranges::none_of(cmdline, is_std_option)) { if (!isCCompileCommand) { @@ -440,7 +441,7 @@ adjustCommandLine( for (auto const& inc : it->second) { new_cmdline.emplace_back(std::format("-isystem{}", inc)); - } + } } } From 4d13984e12197fb78bde348e034fd2dddc167b6d Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Fri, 12 Sep 2025 09:05:03 +0200 Subject: [PATCH 11/17] ignore some more --- src/lib/MrDocsCompilationDatabase.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 5017c5a3b..98cb5bb2f 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -224,6 +224,7 @@ isValidMrDocsOption( driver::options::OPT__SLASH_EH, driver::options::OPT__SLASH_GR, driver::options::OPT__SLASH_GR_, + driver::options::OPT__SLASH_M_Group, // input file options //driver::options::OPT_INPUT, From 57011a55aaa54f67dfeca59a75b37f0868a44355 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Tue, 16 Sep 2025 15:08:07 +0200 Subject: [PATCH 12/17] draft up test suite for adjustCommandLine --- src/test/lib/MrDocsCompilationDatabase.cpp | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/test/lib/MrDocsCompilationDatabase.cpp diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp new file mode 100644 index 000000000..21a6895ba --- /dev/null +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -0,0 +1,102 @@ +// +// Licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) +// +// Official repository: https://github.com/cppalliance/mrdocs +// + +#include "lib/ConfigImpl.hpp" +#include "lib/MrDocsCompilationDatabase.hpp" +#include "lib/SingleFileDB.hpp" +#include +#include +#include +#include + +namespace clang { +namespace mrdocs { + +/** Compilation database for a single .cpp file. +*/ +class SingleFileTestDB + : public tooling::CompilationDatabase +{ + tooling::CompileCommand cc_; + +public: + explicit + SingleFileTestDB( + tooling::CompileCommand cc) + : cc_(std::move(cc)) + {} + + std::vector + getCompileCommands( + llvm::StringRef FilePath) const override + { + if (FilePath != cc_.Filename) + return {}; + return { cc_ }; + } + + std::vector + getAllFiles() const override + { + return { cc_.Filename }; + } + + std::vector + getAllCompileCommands() const override + { + return { cc_ }; + } +}; + +struct MrDocsCompilationDatabase_test +{ + Config::Settings fileSettings_; + ThreadPool threadPool_; + ReferenceDirectories dirs_; + + std::shared_ptr config_ = + ConfigImpl::load(fileSettings_, dirs_, threadPool_).value(); + + auto adjustCompileCommand(std::vector CommandLine) const + { + tooling::CompileCommand cc; + cc.Directory = "."; + cc.Filename = "test.cpp"; // file does not exist + cc.CommandLine = std::move(CommandLine); + cc.CommandLine.push_back(cc.Filename); + cc.Heuristic = "unit test"; + + // Create an adjusted MrDocsDatabase + std::unordered_map> defaultIncludePaths; + MrDocsCompilationDatabase compilations( + llvm::StringRef(cc.Directory), SingleFileTestDB(cc), config_, defaultIncludePaths); + return compilations.getCompileCommands(cc.Filename).front().CommandLine; + } + + void testClangCL() + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++latest"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST_EQ(adjusted[0], "clang"); + BOOST_TEST(contains(adjusted, "-std=c++23")); + } + + void run() + { + testClangCL(); + } +}; + +TEST_SUITE( + MrDocsCompilationDatabase_test, + "clang.mrdocs.MrDocsCompilationDatabase"); + +} // mrdocs +} // clang From 2bceef0840dc7d8c4dd7e81aa08cfe7feca58aed Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Tue, 16 Sep 2025 15:20:51 +0200 Subject: [PATCH 13/17] test /std --- src/test/lib/MrDocsCompilationDatabase.cpp | 61 ++++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index 21a6895ba..65209f6db 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -80,12 +80,65 @@ struct MrDocsCompilationDatabase_test return compilations.getCompileCommands(cc.Filename).front().CommandLine; } + void testClangCLStdFlag() + { + // /std:c++14 -> -std=c++14 + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++14"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(contains(adjusted, "-std=c++14")); + } + + // /std:c++17 -> -std=c++17 + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++17"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(contains(adjusted, "-std=c++17")); + } + + // /std:c++20 -> -std=c++20 + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++20"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(contains(adjusted, "-std=c++20")); + } + + // /std:c++23preview -> -std=c++23 + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++23preview"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(contains(adjusted, "-std=c++23")); + } + + // /std:c++latest -> -std=c++23 + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++latest"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(contains(adjusted, "-std=c++23")); + } + + // /std:c11 -> -std=c11 + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c11"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(contains(adjusted, "-std=c11")); + } + + // /std:c17 -> -std=c17 + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c17"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(contains(adjusted, "-std=c17")); + } + } + void testClangCL() { - auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++latest"}); - BOOST_TEST_GE(adjusted.size(), 2); - BOOST_TEST_EQ(adjusted[0], "clang"); - BOOST_TEST(contains(adjusted, "-std=c++23")); + auto adjusted = adjustCompileCommand({ "clang-cl"}); + BOOST_TEST_GE(adjusted.size(), 1); + BOOST_TEST_EQ(adjusted[0], "clang"); + + testClangCLStdFlag(); } void run() From b4501f2b635df16c7de0b35f8ceaa1eb23dc244b Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Tue, 16 Sep 2025 15:30:09 +0200 Subject: [PATCH 14/17] test /I --- src/test/lib/MrDocsCompilationDatabase.cpp | 43 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index 65209f6db..6ac21402b 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -11,7 +11,6 @@ #include "lib/ConfigImpl.hpp" #include "lib/MrDocsCompilationDatabase.hpp" #include "lib/SingleFileDB.hpp" -#include #include #include #include @@ -79,6 +78,16 @@ struct MrDocsCompilationDatabase_test llvm::StringRef(cc.Directory), SingleFileTestDB(cc), config_, defaultIncludePaths); return compilations.getCompileCommands(cc.Filename).front().CommandLine; } + + static bool has(std::vector const& commandLine, std::string_view flag) + { + return std::find(commandLine.begin(), commandLine.end(), flag) != commandLine.end(); + } + static bool has(std::vector const& commandLine, std::initializer_list flags) + { + MRDOCS_ASSERT(flags.size() > 0); + return std::search(commandLine.begin(), commandLine.end(), flags.begin(), flags.end()) != commandLine.end(); + } void testClangCLStdFlag() { @@ -86,49 +95,66 @@ struct MrDocsCompilationDatabase_test { auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++14"}); BOOST_TEST_GE(adjusted.size(), 2); - BOOST_TEST(contains(adjusted, "-std=c++14")); + BOOST_TEST(has(adjusted, "-std=c++14")); } // /std:c++17 -> -std=c++17 { auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++17"}); BOOST_TEST_GE(adjusted.size(), 2); - BOOST_TEST(contains(adjusted, "-std=c++17")); + BOOST_TEST(has(adjusted, "-std=c++17")); } // /std:c++20 -> -std=c++20 { auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++20"}); BOOST_TEST_GE(adjusted.size(), 2); - BOOST_TEST(contains(adjusted, "-std=c++20")); + BOOST_TEST(has(adjusted, "-std=c++20")); } // /std:c++23preview -> -std=c++23 { auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++23preview"}); BOOST_TEST_GE(adjusted.size(), 2); - BOOST_TEST(contains(adjusted, "-std=c++23")); + BOOST_TEST(has(adjusted, "-std=c++23")); } // /std:c++latest -> -std=c++23 { auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++latest"}); BOOST_TEST_GE(adjusted.size(), 2); - BOOST_TEST(contains(adjusted, "-std=c++23")); + BOOST_TEST(has(adjusted, "-std=c++23")); } // /std:c11 -> -std=c11 { auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c11"}); BOOST_TEST_GE(adjusted.size(), 2); - BOOST_TEST(contains(adjusted, "-std=c11")); + BOOST_TEST(has(adjusted, "-std=c11")); } // /std:c17 -> -std=c17 { auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c17"}); BOOST_TEST_GE(adjusted.size(), 2); - BOOST_TEST(contains(adjusted, "-std=c17")); + BOOST_TEST(has(adjusted, "-std=c17")); + } + } + + void testClangCLIncludeFlag() + { + // /I -> -I + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/I"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(has(adjusted, {"-I", ""})); + } + + // /external:I -> -isystem + { + auto adjusted = adjustCompileCommand({ "clang-cl", "/external:I"}); + BOOST_TEST_GE(adjusted.size(), 2); + BOOST_TEST(has(adjusted, {"-isystem", ""})); } } @@ -139,6 +165,7 @@ struct MrDocsCompilationDatabase_test BOOST_TEST_EQ(adjusted[0], "clang"); testClangCLStdFlag(); + testClangCLIncludeFlag(); } void run() From d4ba27fe7a2814230b3c45a17c89d4c180f481ab Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Tue, 16 Sep 2025 16:01:36 +0200 Subject: [PATCH 15/17] internal linkage --- src/test/lib/MrDocsCompilationDatabase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index 6ac21402b..8758179a0 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -18,6 +18,7 @@ namespace clang { namespace mrdocs { +namespace { /** Compilation database for a single .cpp file. */ class SingleFileTestDB @@ -53,6 +54,7 @@ class SingleFileTestDB return { cc_ }; } }; +} struct MrDocsCompilationDatabase_test { From c181b199f6f67c9dca127be635baa80c07635d5b Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Tue, 16 Sep 2025 16:10:44 +0200 Subject: [PATCH 16/17] comment --- src/lib/MrDocsCompilationDatabase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 98cb5bb2f..645400a96 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -403,8 +403,8 @@ adjustCommandLine( isExplicitCCompileCommand || (!isExplicitCppCompileCommand && isImplicitCSourceFile); constexpr auto is_std_option = [](std::string_view const opt) { - return opt.starts_with("-std=") || opt.starts_with("--std=") || - opt.starts_with("/std:") || opt.starts_with("-std:"); + return opt.starts_with("-std=") || opt.starts_with("--std=") || // clang options + opt.starts_with("/std:") || opt.starts_with("-std:"); // clang-cl options }; if (std::ranges::none_of(cmdline, is_std_option)) { From 0b7c9aa042153f8e495c3acdae1bc4ab668a747e Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Thu, 18 Sep 2025 10:02:14 +0200 Subject: [PATCH 17/17] ignore more cl flags --- src/lib/MrDocsCompilationDatabase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 645400a96..cb9de647f 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -225,6 +225,8 @@ isValidMrDocsOption( driver::options::OPT__SLASH_GR, driver::options::OPT__SLASH_GR_, driver::options::OPT__SLASH_M_Group, + driver::options::OPT__SLASH_MP, + driver::options::OPT__SLASH_Zc, // input file options //driver::options::OPT_INPUT,