aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-10-15 05:42:01 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-10-15 05:42:01 +0000
commit0aa86c0463a881be85fd34e04c7de3379997621d (patch)
treed7ca22480268c94ba0531ad35522a00970b932bd
parent7fe6208c3fa91f835813bb78236ef5c2bbf81053 (diff)
Add -Wc++98-compat warning for deduced 'auto' type specifier.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142057 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--lib/Sema/SemaType.cpp4
-rw-r--r--test/SemaCXX/cxx98-compat.cpp3
3 files changed, 9 insertions, 1 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 0fbf0cee0a..1fb8fb8b97 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1083,6 +1083,9 @@ def err_cannot_determine_declared_type_of_overloaded_function : Error<
"cannot determine the type of an overloaded function">;
// C++11 auto
+def warn_cxx98_compat_auto_type_specifier : Warning<
+ "'auto' type specifier is incompatible with C++98">,
+ InGroup<CXX98Compat>, DefaultIgnore;
def err_auto_variable_cannot_appear_in_own_initializer : Error<
"variable %0 declared with 'auto' type cannot appear in its own initializer">;
def err_illegal_decl_array_of_auto : Error<
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 2b563a50a9..d3a39967de 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1851,7 +1851,9 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
<< Error;
T = SemaRef.Context.IntTy;
D.setInvalidType(true);
- }
+ } else
+ SemaRef.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
+ diag::warn_cxx98_compat_auto_type_specifier);
}
if (SemaRef.getLangOptions().CPlusPlus &&
diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp
index d4c433e008..927df1f971 100644
--- a/test/SemaCXX/cxx98-compat.cpp
+++ b/test/SemaCXX/cxx98-compat.cpp
@@ -87,3 +87,6 @@ template<typename T> using AliasTemplate = T; // expected-warning {{alias declar
inline namespace N { // expected-warning {{inline namespaces are incompatible with C++98}}
}
+
+auto auto_deduction = 0; // expected-warning {{'auto' type specifier is incompatible with C++98}}
+int *p = new auto(0); // expected-warning {{'auto' type specifier is incompatible with C++98}}