[PATCH] Use -std=c++11 when no arguments are provided.

Ariel Bernal ariel.j.bernal at intel.com
Tue Aug 13 08:05:30 PDT 2013


  fixed the case when the user provides an empty compilation database.

Hi revane, tareqsiraj, Sarcasm,

http://llvm-reviews.chandlerc.com/D1337

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1337?vs=3378&id=3429#toc

Files:
  cpp11-migrate/tool/Cpp11Migrate.cpp

Index: cpp11-migrate/tool/Cpp11Migrate.cpp
===================================================================
--- cpp11-migrate/tool/Cpp11Migrate.cpp
+++ cpp11-migrate/tool/Cpp11Migrate.cpp
@@ -36,6 +36,11 @@
 TransformOptions GlobalOptions;
 
 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+const char NoBuildPath[] = "no_build_path";
+static cl::opt<std::string> BuildPath(
+    "p", cl::desc("Build Path"), cl::Optional, cl::init(NoBuildPath));
+static cl::list<std::string> SourcePaths(
+    cl::Positional, cl::desc("<source0> [... <sourceN>]"), cl::OneOrMore);
 static cl::extrahelp MoreHelp(
     "EXAMPLES:\n\n"
     "Apply all transforms on a given file, no compilation database:\n\n"
@@ -220,8 +225,28 @@
 
   TransformManager.registerTransforms();
 
-  // This causes options to be parsed.
-  CommonOptionsParser OptionsParser(argc, argv);
+  // Parse options and generate compilations.
+  OwningPtr<CompilationDatabase> Compilations(
+      FixedCompilationDatabase::loadFromCommandLine(argc, argv));
+  cl::ParseCommandLineOptions(argc, argv);
+  if (!Compilations) {
+    std::string ErrorMessage;
+    if (BuildPath != NoBuildPath) {
+      Compilations.reset(CompilationDatabase::autoDetectFromDirectory(
+          BuildPath, ErrorMessage));
+    } else {
+      Compilations.reset(CompilationDatabase::autoDetectFromSource(
+          SourcePaths[0], ErrorMessage));
+      // If no compilation database can be detected from source then we create
+      // a new FixedCompilationDatabase with c++11 support.
+      if (!Compilations) {
+        std::string CommandLine[] = {"-std=c++11"};
+        Compilations.reset(new FixedCompilationDatabase(".", CommandLine));
+      }
+    }
+    if (!Compilations)
+      llvm::report_fatal_error(ErrorMessage);
+  }
 
   // Since ExecutionTimeDirectoryName could be an empty string we compare
   // against the default value when the command line option is not specified.
@@ -269,9 +294,7 @@
        I != E; ++I) {
     Transform *T = *I;
 
-    if (T->apply(FileStates, OptionsParser.getCompilations(),
-                 OptionsParser.getSourcePathList()) !=
-        0) {
+    if (T->apply(FileStates, *Compilations, SourcePaths) != 0) {
       // FIXME: Improve ClangTool to not abort if just one file fails.
       return 1;
     }
@@ -300,8 +323,7 @@
     }
 
   if (FinalSyntaxCheck)
-    if (!doSyntaxCheck(OptionsParser.getCompilations(),
-                       OptionsParser.getSourcePathList(), FileStates))
+    if (!doSyntaxCheck(*Compilations, SourcePaths, FileStates))
       return 1;
 
   // Write results to file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1337.3.patch
Type: text/x-patch
Size: 2614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130813/aa33d44d/attachment.bin>


More information about the cfe-commits mailing list