summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@google.com>2011-10-13 22:18:05 +0000
committerJeffrey Yasskin <jyasskin@google.com>2011-10-13 22:18:05 +0000
commita722170eb95ddbf6b1223b6739b93058d996e05d (patch)
tree6ebaf58f58567d34018450bb0b5832186e982b1a /clang
parent51862b3890db908a624f6bc8b7203a9a31477930 (diff)
downloadbcm5719-llvm-a722170eb95ddbf6b1223b6739b93058d996e05d.tar.gz
bcm5719-llvm-a722170eb95ddbf6b1223b6739b93058d996e05d.zip
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. llvm-svn: 141898
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/DiagnosticCommonKinds.td3
-rw-r--r--clang/include/clang/Basic/DiagnosticGroups.td9
-rw-r--r--clang/lib/Parse/ParseTemplate.cpp12
-rw-r--r--clang/lib/Sema/SemaType.cpp7
-rw-r--r--clang/test/SemaCXX/cxx98-compat.cpp10
5 files changed, 35 insertions, 6 deletions
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 2f32a590e02..ef114eb7bd5 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -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<
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 55e88312811..3e1b7085dbd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -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">;
diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp
index 92fe4a5f335..3d68a4ab9db 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -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.
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index cee4ed67a1f..dc08320cad7 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -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/clang/test/SemaCXX/cxx98-compat.cpp b/clang/test/SemaCXX/cxx98-compat.cpp
new file mode 100644
index 00000000000..37815d47971
--- /dev/null
+++ b/clang/test/SemaCXX/cxx98-compat.cpp
@@ -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 {};
OpenPOWER on IntegriCloud