mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
Use -xc (instead of -xc++) for files ending with .c.
A good chunk of c files will fail to compile under c++ mode.
This commit is contained in:
parent
639bf8a431
commit
440fa950a0
@ -113,6 +113,12 @@ bool ShouldAddToAngleIncludes(const std::string& arg) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true if we should use the C, not C++, language spec for the given
|
||||||
|
// file.
|
||||||
|
bool IsCFile(const std::string& path) {
|
||||||
|
return EndsWith(path, ".c");
|
||||||
|
}
|
||||||
|
|
||||||
Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
||||||
std::unordered_set<std::string>& quote_includes, std::unordered_set<std::string>& angle_includes,
|
std::unordered_set<std::string>& quote_includes, std::unordered_set<std::string>& angle_includes,
|
||||||
const std::vector<std::string>& extra_flags, const CompileCommandsEntry& entry) {
|
const std::vector<std::string>& extra_flags, const CompileCommandsEntry& entry) {
|
||||||
@ -187,12 +193,20 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
|||||||
for (const auto& flag : extra_flags)
|
for (const auto& flag : extra_flags)
|
||||||
result.args.push_back(flag);
|
result.args.push_back(flag);
|
||||||
|
|
||||||
// Clang does not have good hueristics for determining source language. We
|
// Clang does not have good hueristics for determining source language, we
|
||||||
// default to C++11 if the user has not specified.
|
// should explicitly specify it.
|
||||||
if (!AnyStartsWith(result.args, "-x"))
|
if (!AnyStartsWith(result.args, "-x")) {
|
||||||
|
if (IsCFile(entry.file))
|
||||||
|
result.args.push_back("-xc");
|
||||||
|
else
|
||||||
result.args.push_back("-xc++");
|
result.args.push_back("-xc++");
|
||||||
if (!AnyStartsWith(result.args, "-std="))
|
}
|
||||||
|
if (!AnyStartsWith(result.args, "-std=")) {
|
||||||
|
if (IsCFile(entry.file))
|
||||||
|
result.args.push_back("-std=c11");
|
||||||
|
else
|
||||||
result.args.push_back("-std=c++11");
|
result.args.push_back("-std=c++11");
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user