r329786 - [Tooling] Correct the "-std" compile command option.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 11 02:18:18 PDT 2018


Author: hokein
Date: Wed Apr 11 02:18:18 2018
New Revision: 329786

URL: http://llvm.org/viewvc/llvm-project?rev=329786&view=rev
Log:
[Tooling] Correct the "-std" compile command option.

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

Modified:
    cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp
    cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Modified: cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp?rev=329786&r1=329785&r2=329786&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp Wed Apr 11 02:18:18 2018
@@ -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;

Modified: cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp?rev=329786&r1=329785&r2=329786&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp Wed Apr 11 02:18:18 2018
@@ -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




More information about the cfe-commits mailing list