]> granicus.if.org Git - clang/commitdiff
Implement the first piece of a -Wc++98-compat flag so that people can build in
authorJeffrey Yasskin <jyasskin@google.com>
Thu, 13 Oct 2011 22:18:05 +0000 (22:18 +0000)
committerJeffrey Yasskin <jyasskin@google.com>
Thu, 13 Oct 2011 22:18:05 +0000 (22:18 +0000)
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.

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

include/clang/Basic/DiagnosticCommonKinds.td
include/clang/Basic/DiagnosticGroups.td
lib/Parse/ParseTemplate.cpp
lib/Sema/SemaType.cpp
test/SemaCXX/cxx98-compat.cpp [new file with mode: 0644]

index 2f32a590e023a77623c30f8a2cf7195c261f6ad5..ef114eb7bd5570f05e563a76c1e53b15d81206da 100644 (file)
@@ -53,6 +53,9 @@ def err_invalid_storage_class_in_func_decl : Error<
 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<
index 55e88312811deaf01564cf6332b705f6e80e7ea0..3e1b7085dbdd7a9024dbc3586e11b31588c8e70c 100644 (file)
@@ -57,6 +57,15 @@ def FormatZeroLength : DiagGroup<"format-zero-length">;
 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">;
index 92fe4a5f335faaf442febe5bb2bf3dea747d8e17..3d68a4ab9db8e29e294f5625925c98598f2c1814 100644 (file)
@@ -475,8 +475,10 @@ Decl *Parser::ParseTypeParameter(unsigned Depth, unsigned Position) {
     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 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) {
   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.
index cee4ed67a1fed2381cc416807704d3baea5a438e..dc08320cad71caf1d68fe7af3aa5faab384830ad 100644 (file)
@@ -2488,8 +2488,11 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
       // 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:
diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp
new file mode 100644 (file)
index 0000000..37815d4
--- /dev/null
@@ -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 {};