[cfe-commits] r141898 - in /cfe/trunk: include/clang/Basic/DiagnosticCommonKinds.td include/clang/Basic/DiagnosticGroups.td lib/Parse/ParseTemplate.cpp lib/Sema/SemaType.cpp test/SemaCXX/cxx98-compat.cpp

Jeffrey Yasskin jyasskin at google.com
Thu Oct 13 15:18:05 PDT 2011


Author: jyasskin
Date: Thu Oct 13 17:18:05 2011
New Revision: 141898

URL: http://llvm.org/viewvc/llvm-project?rev=141898&view=rev
Log:
Implement the first piece of a -Wc++98-compat flag so that people can build in
C++11 mode but keep their sources compatible with C++98.  This patch implements
the -Wc++98-compat-variadic-templates sub-flag and -Wc++98-compat to include
it.

Added:
    cfe/trunk/test/SemaCXX/cxx98-compat.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/lib/Parse/ParseTemplate.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=141898&r1=141897&r2=141898&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Thu Oct 13 17:18:05 2011
@@ -53,6 +53,9 @@
 def err_expected_namespace_name : Error<"expected namespace name">;
 def ext_variadic_templates : ExtWarn<
   "variadic templates are a C++11 extension">, InGroup<CXX0x>;
+def warn_cxx98_compat_variadic_templates :
+  Warning<"variadic templates are incompatible with C++98">,
+  InGroup<CXX98CompatVariadicTemplates>, DefaultIgnore;
 def err_default_special_members : Error<
   "only special member functions may be defaulted">;
 def err_friends_define_only_namespace_scope : Error<

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=141898&r1=141897&r2=141898&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Oct 13 17:18:05 2011
@@ -57,6 +57,15 @@
 def CXX0xNarrowing : DiagGroup<"c++0x-narrowing">;
 
 def CXX0xCompat : DiagGroup<"c++0x-compat", [CXX0xNarrowing]>;
+
+// These groups warn in C++0x mode about non-C++98 constructs, and
+// constructs with different behavior between the two versions of the
+// language.  Each particular warning should be in a specific group as
+// well as the general -Wc++98-compat group.
+// FIXME: This is highly incomplete.
+def CXX98CompatVariadicTemplates : DiagGroup<"c++98-compat-variadic-templates">;
+def CXX98Compat : DiagGroup<"c++98-compat", [CXX98CompatVariadicTemplates]>;
+
 def : DiagGroup<"effc++">;
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=141898&r1=141897&r2=141898&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Thu Oct 13 17:18:05 2011
@@ -475,8 +475,10 @@
     Ellipsis = true;
     EllipsisLoc = ConsumeToken();
 
-    if (!getLang().CPlusPlus0x)
-      Diag(EllipsisLoc, diag::ext_variadic_templates);
+    Diag(EllipsisLoc,
+         getLang().CPlusPlus0x
+           ? diag::warn_cxx98_compat_variadic_templates
+           : diag::ext_variadic_templates);
   }
 
   // Grab the template parameter name (if given)
@@ -547,8 +549,10 @@
   if (Tok.is(tok::ellipsis)) {
     EllipsisLoc = ConsumeToken();
     
-    if (!getLang().CPlusPlus0x)
-      Diag(EllipsisLoc, diag::ext_variadic_templates);
+    Diag(EllipsisLoc,
+         getLang().CPlusPlus0x
+           ? diag::warn_cxx98_compat_variadic_templates
+           : diag::ext_variadic_templates);
   }
       
   // Get the identifier, if given.

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=141898&r1=141897&r2=141898&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Oct 13 17:18:05 2011
@@ -2488,8 +2488,11 @@
       // it expands those parameter packs.
       if (T->containsUnexpandedParameterPack())
         T = Context.getPackExpansionType(T, llvm::Optional<unsigned>());
-      else if (!LangOpts.CPlusPlus0x)
-        S.Diag(D.getEllipsisLoc(), diag::ext_variadic_templates);
+      else
+        S.Diag(D.getEllipsisLoc(),
+               LangOpts.CPlusPlus0x
+                 ? diag::warn_cxx98_compat_variadic_templates
+                 : diag::ext_variadic_templates);
       break;
     
     case Declarator::FileContext:

Added: cfe/trunk/test/SemaCXX/cxx98-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx98-compat.cpp?rev=141898&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx98-compat.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx98-compat.cpp Thu Oct 13 17:18:05 2011
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++0x -Wc++98-compat -verify %s
+
+template<typename ...T>  // expected-warning {{variadic templates are incompatible with C++98}}
+class Variadic1 {};
+
+template<template<typename> class ...T>  // expected-warning {{variadic templates are incompatible with C++98}}
+class Variadic2 {};
+
+template<int ...I>  // expected-warning {{variadic templates are incompatible with C++98}}
+class Variadic3 {};





More information about the cfe-commits mailing list