From a33bce9e9145dfb25bab73ad25c456999ffd5d15 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 12 Feb 2019 16:24:34 +0100 Subject: [PATCH] Clang: Fix command line builder Add "-nostdinc++" only for C++. Change-Id: I21228fca80045b040877328f41ca0edb4f227fcc Reviewed-by: Ivan Donchevskii --- src/libs/clangsupport/commandlinebuilder.h | 7 ++++--- tests/unit/unittest/commandlinebuilder-test.cpp | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libs/clangsupport/commandlinebuilder.h b/src/libs/clangsupport/commandlinebuilder.h index 38db85badea..aa384f1180d 100644 --- a/src/libs/clangsupport/commandlinebuilder.h +++ b/src/libs/clangsupport/commandlinebuilder.h @@ -54,7 +54,7 @@ public: addToolChainArguments(toolChainArguments); addLanguage(projectInfo, sourceType); addLanguageVersion(projectInfo); - addNoStdIncAndNoStdLibInc(); + addNoStdIncAndNoStdLibInc(projectInfo.language); addCompilerMacros(projectInfo.compilerMacros); addProjectIncludeSearchPaths( sortedIncludeSearchPaths(projectInfo.projectIncludeSearchPaths)); @@ -272,10 +272,11 @@ public: } } - void addNoStdIncAndNoStdLibInc() + void addNoStdIncAndNoStdLibInc(Utils::Language language) { commandLine.emplace_back("-nostdinc"); - commandLine.emplace_back("-nostdinc++"); + if (language == Utils::Language::Cxx) + commandLine.emplace_back("-nostdinc++"); } public: diff --git a/tests/unit/unittest/commandlinebuilder-test.cpp b/tests/unit/unittest/commandlinebuilder-test.cpp index 3d684e10bca..c6bdd33d3fb 100644 --- a/tests/unit/unittest/commandlinebuilder-test.cpp +++ b/tests/unit/unittest/commandlinebuilder-test.cpp @@ -137,9 +137,13 @@ TYPED_TEST(CommandLineBuilder, CHeader) Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - ASSERT_THAT( - builder.commandLine, - ElementsAre("clang", "-x", "c-header", "-std=c11", "-nostdinc", "-nostdinc++", toNativePath("/source/file.c").path())); + ASSERT_THAT(builder.commandLine, + ElementsAre("clang", + "-x", + "c-header", + "-std=c11", + "-nostdinc", + toNativePath("/source/file.c").path())); } TYPED_TEST(CommandLineBuilder, CSource) @@ -150,7 +154,7 @@ TYPED_TEST(CommandLineBuilder, CSource) Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.c"}; ASSERT_THAT(builder.commandLine, - ElementsAre("clang", "-x", "c", "-std=c11", "-nostdinc", "-nostdinc++", "/source/file.c")); + ElementsAre("clang", "-x", "c", "-std=c11", "-nostdinc", "/source/file.c")); } TYPED_TEST(CommandLineBuilder, ObjectiveCHeader) @@ -167,7 +171,6 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCHeader) "objective-c-header", "-std=c11", "-nostdinc", - "-nostdinc++", toNativePath("/source/file.c").path())); } @@ -185,7 +188,6 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCSource) "objective-c", "-std=c11", "-nostdinc", - "-nostdinc++", "/source/file.c")); }