]> granicus.if.org Git - clang/commitdiff
[Tooling] Correct the "-std" compile command option.
authorHaojian Wu <hokein@google.com>
Wed, 11 Apr 2018 09:18:18 +0000 (09:18 +0000)
committerHaojian Wu <hokein@google.com>
Wed, 11 Apr 2018 09:18:18 +0000 (09:18 +0000)
Summary:
"-std c++11" is not valid in compiler, we have to use "-std=c++11".

Test in vscode with this patch, code completion for header works as expected.

Reviewers: sammccall

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D45512

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329786 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Tooling/InterpolatingCompilationDatabase.cpp
unittests/Tooling/CompilationDatabaseTest.cpp

index cf29744f3075deb8b06da7b38f9c76b4f510577a..bc564584bd01a9b7949fe9e58d7a33965ae990df 100644 (file)
@@ -191,9 +191,9 @@ struct TransferableCommand {
     // --std flag may only be transferred if the language is the same.
     // We may consider "translating" these, e.g. c++11 -> c11.
     if (Std != LangStandard::lang_unspecified && foldType(TargetType) == Type) {
-      Result.CommandLine.push_back("-std");
       Result.CommandLine.push_back(
-          LangStandard::getLangStandardForKind(Std).getName());
+          "-std=" +
+          std::string(LangStandard::getLangStandardForKind(Std).getName()));
     }
     Result.CommandLine.push_back(Filename);
     return Result;
index 948090208c41dacc6f270b0031f8ed326b0dbce6..42497f70698bd6f66ac81b814fa94238585b8a63 100644 (file)
@@ -711,9 +711,9 @@ TEST_F(InterpolateTest, Language) {
 
   // .h is ambiguous, so we add explicit language flags
   EXPECT_EQ(getCommand("foo.h"),
-            "clang -D dir/foo.cpp -x c++-header -std c++17");
+            "clang -D dir/foo.cpp -x c++-header -std=c++17");
   // and don't add -x if the inferred language is correct.
-  EXPECT_EQ(getCommand("foo.hpp"), "clang -D dir/foo.cpp -std c++17");
+  EXPECT_EQ(getCommand("foo.hpp"), "clang -D dir/foo.cpp -std=c++17");
   // respect -x if it's already there.
   EXPECT_EQ(getCommand("baz.h"), "clang -D dir/baz.cee -x c-header");
   // prefer a worse match with the right language