[PATCH] D29724: [Driver] Report available language standards on user error

Paweł Żukowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 8 11:21:34 PST 2017


idlecode created this revision.

In case user did not provide valid standard name for `-std` option,
available values (with short description) will be reported.

To test: `clang -std=iso3103 -c source.c`


https://reviews.llvm.org/D29724

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1694,10 +1694,21 @@
       .Case(alias, LangStandard::lang_##id)
 #include "clang/Frontend/LangStandards.def"
       .Default(LangStandard::lang_unspecified);
-    if (LangStd == LangStandard::lang_unspecified)
+    if (LangStd == LangStandard::lang_unspecified) {
       Diags.Report(diag::err_drv_invalid_value)
         << A->getAsString(Args) << A->getValue();
-    else {
+      // Report all supported standards with description.
+      Diags.Report(diag::note_drv_supported_values);
+      for (unsigned KindValue = 0;
+          KindValue != LangStandard::lang_unspecified;
+          ++KindValue)
+      {
+        const LangStandard &Std = LangStandard::getLangStandardForKind(
+          static_cast<LangStandard::Kind>(KindValue));
+        Diags.Report(diag::note_drv_supported_value_with_description)
+          << Std.getName() << Std.getDescription();
+      }
+    } else {
       // Valid standard, check to make sure language and standard are
       // compatible.
       const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
Index: include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -230,6 +230,8 @@
   "The last /TC or /TP option takes precedence over earlier instances">;
 def note_drv_address_sanitizer_debug_runtime : Note<
   "AddressSanitizer doesn't support linking with debug runtime libraries yet">;
+def note_drv_supported_values : Note<"supported values are:">;
+def note_drv_supported_value_with_description : Note<" %0 - %1">;
 
 def err_analyzer_config_no_value : Error<
   "analyzer-config option '%0' has a key but no value">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29724.87682.patch
Type: text/x-patch
Size: 1940 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170208/0b713b31/attachment-0001.bin>


More information about the cfe-commits mailing list