]> granicus.if.org Git - clang/commitdiff
Change the wording of the extension warning from
authorDmitri Gribenko <gribozavr@gmail.com>
Mon, 24 Sep 2012 18:19:21 +0000 (18:19 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Mon, 24 Sep 2012 18:19:21 +0000 (18:19 +0000)
> 'long long' is an extension when C99 mode is not enabled
to
> 'long long' is a C++11 extension
while compiling in C++98 mode.

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

include/clang/Basic/DiagnosticCommonKinds.td
lib/Lex/PPExpressions.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaType.cpp
test/Lexer/long-long.cpp [new file with mode: 0644]
test/Sema/c89-2.c [deleted file]
test/Sema/c89.c
test/SemaCXX/constant-expression.cpp
test/SemaCXX/cxx98-compat-pedantic.cpp

index f85928740b4c65d9d1a4199d33b8fcef217b475d..999c6d261867fabae28ce4fe7f6559c04cbed00e 100644 (file)
@@ -78,9 +78,12 @@ def note_decl_hiding_tag_type : Note<
   "%1 %0 is hidden by a non-type declaration of %0 here">;
 
 // Sema && Lex
-def ext_longlong : Extension<
+def ext_c99_longlong : Extension<
   "'long long' is an extension when C99 mode is not enabled">,
   InGroup<LongLong>;
+def ext_cxx11_longlong : Extension<
+  "'long long' is a C++11 extension">,
+  InGroup<CXX11>;
 def warn_cxx98_compat_longlong : Warning<
   "'long long' is incompatible with C++98">,
   InGroup<CXX98CompatPedantic>, DefaultIgnore;
index f5984f58bf6f33cc1882ce3e30626b8101c95272..d5a88db470d8f47801ec5bef162017d5f320f395 100644 (file)
@@ -220,10 +220,15 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
     if (Literal.hasUDSuffix())
       PP.Diag(PeekTok, diag::err_pp_invalid_udl) << /*integer*/1;
 
-    // long long is a C99 feature.
-    if (!PP.getLangOpts().C99 && Literal.isLongLong)
-      PP.Diag(PeekTok, PP.getLangOpts().CPlusPlus0x ?
-              diag::warn_cxx98_compat_longlong : diag::ext_longlong);
+    // 'long long' is a C99 or C++11 feature.
+    if (!PP.getLangOpts().C99 && Literal.isLongLong) {
+      if (PP.getLangOpts().CPlusPlus)
+        PP.Diag(PeekTok,
+             PP.getLangOpts().CPlusPlus0x ?
+             diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
+      else
+        PP.Diag(PeekTok, diag::ext_c99_longlong);
+    }
 
     // Parse the integer literal into Result.
     if (Literal.GetIntegerValue(Result.Val)) {
index b864a2e8a06e07195e891d428e0eb1dbea15b4b8..41985328bb769a1d3e3798c75dafb4a02271e23e 100644 (file)
@@ -2777,11 +2777,15 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
   } else {
     QualType Ty;
 
-    // long long is a C99 feature.
-    if (!getLangOpts().C99 && Literal.isLongLong)
-      Diag(Tok.getLocation(),
-           getLangOpts().CPlusPlus0x ?
-             diag::warn_cxx98_compat_longlong : diag::ext_longlong);
+    // 'long long' is a C99 or C++11 feature.
+    if (!getLangOpts().C99 && Literal.isLongLong) {
+      if (getLangOpts().CPlusPlus)
+        Diag(Tok.getLocation(),
+             getLangOpts().CPlusPlus0x ?
+             diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
+      else
+        Diag(Tok.getLocation(), diag::ext_c99_longlong);
+    }
 
     // Get the value in the widest-possible width.
     unsigned MaxWidth = Context.getTargetInfo().getIntMaxTWidth();
index b5328144bb2eddad669738f8bf0d494ee08be9c7..243ae12d2a031c0dad0dce468223af6f2cd9fa72 100644 (file)
@@ -698,11 +698,15 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
       case DeclSpec::TSW_longlong:
         Result = Context.LongLongTy;
 
-        // long long is a C99 feature.
-        if (!S.getLangOpts().C99)
-          S.Diag(DS.getTypeSpecWidthLoc(),
-                 S.getLangOpts().CPlusPlus0x ?
-                   diag::warn_cxx98_compat_longlong : diag::ext_longlong);
+        // 'long long' is a C99 or C++11 feature.
+        if (!S.getLangOpts().C99) {
+          if (S.getLangOpts().CPlusPlus)
+            S.Diag(DS.getTypeSpecWidthLoc(),
+                   S.getLangOpts().CPlusPlus0x ?
+                   diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
+          else
+            S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_c99_longlong);
+        }
         break;
       }
     } else {
@@ -713,11 +717,15 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
       case DeclSpec::TSW_longlong:
         Result = Context.UnsignedLongLongTy;
 
-        // long long is a C99 feature.
-        if (!S.getLangOpts().C99)
-          S.Diag(DS.getTypeSpecWidthLoc(),
-                 S.getLangOpts().CPlusPlus0x ?
-                   diag::warn_cxx98_compat_longlong : diag::ext_longlong);
+        // 'long long' is a C99 or C++11 feature.
+        if (!S.getLangOpts().C99) {
+          if (S.getLangOpts().CPlusPlus)
+            S.Diag(DS.getTypeSpecWidthLoc(),
+                   S.getLangOpts().CPlusPlus0x ?
+                   diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
+          else
+            S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_c99_longlong);
+        }
         break;
       }
     }
diff --git a/test/Lexer/long-long.cpp b/test/Lexer/long-long.cpp
new file mode 100644 (file)
index 0000000..c3f371d
--- /dev/null
@@ -0,0 +1,22 @@
+/* RUN: %clang_cc1 -x c   -std=c89   -fsyntax-only -verify -pedantic-errors -Wno-empty-translation-unit %s
+ * RUN: %clang_cc1 -x c   -std=c99   -fsyntax-only -verify -pedantic-errors -Wno-empty-translation-unit %s
+ * RUN: %clang_cc1 -x c++ -std=c++98 -fsyntax-only -verify -pedantic-errors -Wno-empty-translation-unit %s
+ * RUN: %clang_cc1 -x c++ -std=c++11 -fsyntax-only -verify -Wc++98-compat-pedantic -Wno-empty-translation-unit %s
+ */
+
+#if !defined(__cplusplus)
+#  if __STDC_VERSION__ < 199901L
+/* expected-error@19 {{'long long' is an extension when C99 mode is not enabled}} */
+#  endif
+#else
+#  if __cplusplus < 201103L
+/* expected-error@19 {{'long long' is a C++11 extension}} */
+#  else
+/* expected-warning@19 {{'long long' is incompatible with C++98}} */
+#  endif
+#endif
+
+#if 1 > 2LL
+#  error should not happen
+#endif
+
diff --git a/test/Sema/c89-2.c b/test/Sema/c89-2.c
deleted file mode 100644 (file)
index 14b955a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-/* RUN: %clang_cc1 %s -std=c89 -pedantic-errors -Wno-empty-translation-unit -verify
- */
-
-#if 1LL        /* expected-error {{long long}} */
-#endif
index 110d7e137621f2ef1edf203ca4b1e7a0ec3508e8..a410a626edac5f2cb9bdb88f4f85778e8cce1f8a 100644 (file)
@@ -110,3 +110,9 @@ typedef CI *array_of_pointer_to_CI[5];
 const array_of_pointer_to_CI mine3;
 
 void main() {} /* expected-error {{'main' must return 'int'}} */
+
+long long ll1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
+         -42LL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
+unsigned long long ull1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
+                   42ULL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
+
index ec50cb7d92fcdf2315b566c0e419b546fdacceb1..942bf414742b26445e3cf3dfa37954d5a71c4086 100644 (file)
@@ -115,7 +115,7 @@ int array2[recurse2]; // expected-warning {{variable length array}} expected-war
 namespace FloatConvert {
   typedef int a[(int)42.3];
   typedef int a[(int)42.997];
-  typedef int b[(long long)4e20]; // expected-warning {{variable length}} expected-error {{variable length}} expected-warning {{'long long' is an extension}}
+  typedef int b[(long long)4e20]; // expected-warning {{variable length}} expected-error {{variable length}} expected-warning {{'long long' is a C++11 extension}}
 }
 
 // PR12626
index c07f64e614d25f4c17b32a244f605674c46db255..18fd1520ec4e32ad6539c8f6d8efd64268516f45 100644 (file)
@@ -32,3 +32,9 @@ int *ArraySizeConversion = new int[ConvertToInt()]; // expected-warning {{implic
 
 template<typename T> class ExternTemplate {};
 extern template class ExternTemplate<int>; // expected-warning {{extern templates are incompatible with C++98}}
+
+long long ll1 = // expected-warning {{'long long' is incompatible with C++98}}
+         -42LL; // expected-warning {{'long long' is incompatible with C++98}}
+unsigned long long ull1 = // expected-warning {{'long long' is incompatible with C++98}}
+                   42ULL; // expected-warning {{'long long' is incompatible with C++98}}
+