]> granicus.if.org Git - clang/commitdiff
When using -std= flag added check to make sure language and standard are compatable
authorChad Rosier <mcrosier@apple.com>
Mon, 2 May 2011 19:24:53 +0000 (19:24 +0000)
committerChad Rosier <mcrosier@apple.com>
Mon, 2 May 2011 19:24:53 +0000 (19:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130710 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/LangStandard.h
include/clang/Frontend/LangStandards.def
lib/Frontend/CompilerInvocation.cpp

index 74ca5191dd48b6e60c17054084b95587b219276c..ea37bdd1022be4d6d358ba931586f13e063c18ad 100644 (file)
@@ -18,14 +18,15 @@ namespace frontend {
 
 enum LangFeatures {
   BCPLComment = (1 << 0),
-  C99 = (1 << 1),
-  C1X = (1 << 2),
-  CPlusPlus = (1 << 3),
-  CPlusPlus0x = (1 << 4),
-  Digraphs = (1 << 5),
-  GNUMode = (1 << 6),
-  HexFloat = (1 << 7),
-  ImplicitInt = (1 << 8)
+  C89 = (1 << 1),
+  C99 = (1 << 2),
+  C1X = (1 << 3),
+  CPlusPlus = (1 << 4),
+  CPlusPlus0x = (1 << 5),
+  Digraphs = (1 << 6),
+  GNUMode = (1 << 7),
+  HexFloat = (1 << 8),
+  ImplicitInt = (1 << 9)
 };
 
 }
@@ -54,6 +55,9 @@ public:
   /// hasBCPLComments - Language supports '//' comments.
   bool hasBCPLComments() const { return Flags & frontend::BCPLComment; }
 
+  /// isC89 - Language is a superset of C89.
+  bool isC89() const { return Flags & frontend::C89; }
+
   /// isC99 - Language is a superset of C99.
   bool isC99() const { return Flags & frontend::C99; }
 
index 586e5c8fa2a41aa742e0db98e9801bf6a465d35a..6055ad51828e97db27266371a5a8595886b99d4a 100644 (file)
 // C89-ish modes.
 LANGSTANDARD(c89, "c89",
              "ISO C 1990",
-             ImplicitInt)
+             C89 | ImplicitInt)
 LANGSTANDARD(c90, "c90",
              "ISO C 1990",
-             ImplicitInt)
+             C89 | ImplicitInt)
 LANGSTANDARD(iso9899_1990, "iso9899:1990",
              "ISO C 1990",
-             ImplicitInt)
+             C89 | ImplicitInt)
 
 LANGSTANDARD(c94, "iso9899:199409",
              "ISO C 1990 with amendment 1",
-             Digraphs | ImplicitInt)
+             C89 | Digraphs | ImplicitInt)
 
 LANGSTANDARD(gnu89, "gnu89",
              "ISO C 1990 with GNU extensions",
-             BCPLComment | Digraphs | GNUMode | ImplicitInt)
+             BCPLComment | C89 | Digraphs | GNUMode | ImplicitInt)
 
 // C99-ish modes
 LANGSTANDARD(c99, "c99",
@@ -87,7 +87,6 @@ LANGSTANDARD(gnucxx0x, "gnu++0x",
              BCPLComment | CPlusPlus | CPlusPlus0x | Digraphs | GNUMode)
 
 // OpenCL
-
 LANGSTANDARD(opencl, "cl",
              "OpenCL 1.0",
              BCPLComment | C99 | Digraphs | HexFloat)
index 1d4cd15ac4804e50b71c7c911e82bc7bf7bb137f..b84e4c82b30f3503af99f1ea04ee2eb73014be85 100644 (file)
@@ -1397,6 +1397,40 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
     if (LangStd == LangStandard::lang_unspecified)
       Diags.Report(diag::err_drv_invalid_value)
         << A->getAsString(Args) << A->getValue(Args);
+    else {
+      // Valid standard, check to make sure language and standard are compatable.    
+      const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
+      switch (IK) {
+      case IK_C:
+      case IK_ObjC:
+      case IK_PreprocessedC:
+      case IK_PreprocessedObjC:
+        if (!(Std.isC89() || Std.isC99()))
+          Diags.Report(diag::err_drv_argument_not_allowed_with)
+            << A->getAsString(Args) << "C/ObjC";
+        break;
+      case IK_CXX:
+      case IK_ObjCXX:
+      case IK_PreprocessedCXX:
+      case IK_PreprocessedObjCXX:
+        if (!Std.isCPlusPlus())
+          Diags.Report(diag::err_drv_argument_not_allowed_with)
+            << A->getAsString(Args) << "C++/ObjC++";
+        break;
+      case IK_OpenCL:
+        if (!Std.isC99())
+          Diags.Report(diag::err_drv_argument_not_allowed_with)
+            << A->getAsString(Args) << "OpenCL";
+        break;
+      case IK_CUDA:
+        if (!Std.isCPlusPlus())
+          Diags.Report(diag::err_drv_argument_not_allowed_with)
+            << A->getAsString(Args) << "CUDA";
+        break;
+      default:
+        break;
+      }
+    }
   }
 
   if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) {