[cfe-commits] r164545 - in /cfe/trunk: include/clang/Basic/DiagnosticCommonKinds.td lib/Lex/PPExpressions.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/Lexer/long-long.cpp test/Sema/c89-2.c test/Sema/c89.c test/SemaCXX/constant-expression.cpp test/SemaCXX/cxx98-compat-pedantic.cpp

Dmitri Gribenko gribozavr at gmail.com
Mon Sep 24 11:19:21 PDT 2012


Author: gribozavr
Date: Mon Sep 24 13:19:21 2012
New Revision: 164545

URL: http://llvm.org/viewvc/llvm-project?rev=164545&view=rev
Log:
Change the wording of the extension warning from
> '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.

Added:
    cfe/trunk/test/Lexer/long-long.cpp
Removed:
    cfe/trunk/test/Sema/c89-2.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
    cfe/trunk/lib/Lex/PPExpressions.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/c89.c
    cfe/trunk/test/SemaCXX/constant-expression.cpp
    cfe/trunk/test/SemaCXX/cxx98-compat-pedantic.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=164545&r1=164544&r2=164545&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Mon Sep 24 13:19:21 2012
@@ -78,9 +78,12 @@
   "%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;

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=164545&r1=164544&r2=164545&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Mon Sep 24 13:19:21 2012
@@ -220,10 +220,15 @@
     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)) {

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=164545&r1=164544&r2=164545&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 24 13:19:21 2012
@@ -2777,11 +2777,15 @@
   } 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();

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=164545&r1=164544&r2=164545&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Sep 24 13:19:21 2012
@@ -698,11 +698,15 @@
       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 @@
       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;
       }
     }

Added: cfe/trunk/test/Lexer/long-long.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/long-long.cpp?rev=164545&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/long-long.cpp (added)
+++ cfe/trunk/test/Lexer/long-long.cpp Mon Sep 24 13:19:21 2012
@@ -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 at 19 {{'long long' is an extension when C99 mode is not enabled}} */
+#  endif
+#else
+#  if __cplusplus < 201103L
+/* expected-error at 19 {{'long long' is a C++11 extension}} */
+#  else
+/* expected-warning at 19 {{'long long' is incompatible with C++98}} */
+#  endif
+#endif
+
+#if 1 > 2LL
+#  error should not happen
+#endif
+

Removed: cfe/trunk/test/Sema/c89-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c89-2.c?rev=164544&view=auto
==============================================================================
--- cfe/trunk/test/Sema/c89-2.c (original)
+++ cfe/trunk/test/Sema/c89-2.c (removed)
@@ -1,5 +0,0 @@
-/* RUN: %clang_cc1 %s -std=c89 -pedantic-errors -Wno-empty-translation-unit -verify
- */
-
-#if 1LL        /* expected-error {{long long}} */
-#endif

Modified: cfe/trunk/test/Sema/c89.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c89.c?rev=164545&r1=164544&r2=164545&view=diff
==============================================================================
--- cfe/trunk/test/Sema/c89.c (original)
+++ cfe/trunk/test/Sema/c89.c Mon Sep 24 13:19:21 2012
@@ -110,3 +110,9 @@
 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}} */
+

Modified: cfe/trunk/test/SemaCXX/constant-expression.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression.cpp?rev=164545&r1=164544&r2=164545&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression.cpp Mon Sep 24 13:19:21 2012
@@ -115,7 +115,7 @@
 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

Modified: cfe/trunk/test/SemaCXX/cxx98-compat-pedantic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx98-compat-pedantic.cpp?rev=164545&r1=164544&r2=164545&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx98-compat-pedantic.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx98-compat-pedantic.cpp Mon Sep 24 13:19:21 2012
@@ -32,3 +32,9 @@
 
 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}}
+





More information about the cfe-commits mailing list