Skip to content

Instantly share code, notes, and snippets.

@micbou
Created January 21, 2018 15:41
Show Gist options
  • Save micbou/a353fdd232cf2fd406173390d9d8a3ce to your computer and use it in GitHub Desktop.
Save micbou/a353fdd232cf2fd406173390d9d8a3ce to your computer and use it in GitHub Desktop.
Incorrect warnings when parsing with libclang in Windows mode
#include <string>
#include <iostream>
#include <clang-c/Index.h>
const char *flags[] = {
"clang",
"--driver-mode=cl",
"-xc++"
};
int main(int argc, const char *argv[]) {
if (argc != 2) {
std::cout << argv[0] << " file.cpp" << std::endl;
return EXIT_FAILURE;
}
CXIndex index = clang_createIndex(0, 0);
if (!index) {
std::cerr << "createIndex failed\n";
return EXIT_FAILURE;
}
CXTranslationUnit tu;
CXErrorCode result = clang_parseTranslationUnit2FullArgv(
index, argv[1], flags, sizeof(flags) / sizeof(flags[0]), nullptr, 0,
CXTranslationUnit_CreatePreambleOnFirstParse |
clang_defaultEditingTranslationUnitOptions(),
&tu);
if (result != CXError_Success) {
std::cerr << "clang_parseTranslationUnit2FullArgv failed with code "
<< result << "\n";
return EXIT_FAILURE;
}
size_t num_diagnostics = clang_getNumDiagnostics(tu);
for (size_t i = 0; i < num_diagnostics; ++i) {
CXDiagnostic diagnostic = clang_getDiagnostic(tu, i);
CXDiagnosticSeverity diagnostic_severity =
clang_getDiagnosticSeverity(diagnostic);
CXString raw_string = clang_getDiagnosticSpelling(diagnostic);
std::string string(clang_getCString(raw_string));
clang_disposeString(raw_string);
std::cout << string << "\n";
clang_disposeDiagnostic(diagnostic);
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment