Add (crude) workaround for _DEBUGGER_STEP_INTO #line in MSVC

Fixes #46.
This commit is contained in:
Jonathan Müller 2018-03-19 21:41:28 +01:00
commit 2004780ea6

View file

@ -88,7 +88,8 @@ namespace
} }
// parse and log diagnostic // parse and log diagnostic
void log_diagnostic(const diagnostic_logger& logger, const std::string& msg) // returns true if a diagnostic was logged due to a bug, but it is otherwise harmless
bool log_diagnostic(const diagnostic_logger& logger, const std::string& msg)
{ {
auto ptr = msg.c_str(); auto ptr = msg.c_str();
@ -104,7 +105,13 @@ namespace
while (*ptr && *ptr != '\n') while (*ptr && *ptr != '\n')
message.push_back(*ptr++); message.push_back(*ptr++);
// see https://github.com/foonathan/cppast/issues/46
auto harmless_diag =
message.find("invalid filename for #line directive") != std::string::npos;
logger.log("preprocessor", diagnostic{std::move(message), std::move(loc), sev}); logger.log("preprocessor", diagnostic{std::move(message), std::move(loc), sev});
return harmless_diag;
} }
// parses missing header file diagnostic and returns the file name, // parses missing header file diagnostic and returns the file name,
@ -349,6 +356,8 @@ namespace
std::string write_macro_file(const libclang_compile_config& c, const std::string& full_path, std::string write_macro_file(const libclang_compile_config& c, const std::string& full_path,
const diagnostic_logger& logger) const diagnostic_logger& logger)
{ {
auto expect_bad_exit_code = false;
std::string diagnostic; std::string diagnostic;
auto diagnostic_logger = [&](const char* str, std::size_t n) { auto diagnostic_logger = [&](const char* str, std::size_t n) {
diagnostic.reserve(diagnostic.size() + n); diagnostic.reserve(diagnostic.size() + n);
@ -358,7 +367,7 @@ namespace
else if (*str == '\n') else if (*str == '\n')
{ {
// consume current diagnostic // consume current diagnostic
log_diagnostic(logger, diagnostic); expect_bad_exit_code |= log_diagnostic(logger, diagnostic);
diagnostic.clear(); diagnostic.clear();
} }
else else
@ -381,7 +390,7 @@ namespace
auto exit_code = process.get_exit_status(); auto exit_code = process.get_exit_status();
DEBUG_ASSERT(diagnostic.empty(), detail::assert_handler{}); DEBUG_ASSERT(diagnostic.empty(), detail::assert_handler{});
if (exit_code != 0) if (exit_code != 0 && !expect_bad_exit_code)
throw libclang_error("preprocessor (macro): command '" + cmd throw libclang_error("preprocessor (macro): command '" + cmd
+ "' exited with non-zero exit code (" + std::to_string(exit_code) + "' exited with non-zero exit code (" + std::to_string(exit_code)
+ ")"); + ")");
@ -423,7 +432,7 @@ namespace
expect_bad_exit_code = true; expect_bad_exit_code = true;
} }
else else
log_diagnostic(logger, diagnostic); expect_bad_exit_code |= log_diagnostic(logger, diagnostic);
diagnostic.clear(); diagnostic.clear();
} }