r341098 - Add missing -Wc++11-compat / -Wc++14-compat warnings for:
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 30 12:16:36 PDT 2018
Author: rsmith
Date: Thu Aug 30 12:16:35 2018
New Revision: 341098
URL: http://llvm.org/viewvc/llvm-project?rev=341098&view=rev
Log:
Add missing -Wc++11-compat / -Wc++14-compat warnings for:
* generic lambdas
* return type deduction
* class template argument deduction
Added:
cfe/trunk/test/SemaCXX/cxx11-compat.cpp
- copied, changed from r341097, cfe/trunk/test/SemaCXX/cxx0x-compat.cpp
Removed:
cfe/trunk/test/SemaCXX/cxx0x-compat.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaCXX/cxx98-compat.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341098&r1=341097&r2=341098&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Aug 30 12:16:35 2018
@@ -2143,8 +2143,11 @@ def note_deduction_guide_template_access
"member template declared %0 here">;
def note_deduction_guide_access : Note<
"deduction guide declared %0 by intervening access specifier">;
+def warn_cxx14_compat_class_template_argument_deduction : Warning<
+ "class template argument deduction is incompatible with C++ standards "
+ "before C++17">, InGroup<CXXPre17Compat>, DefaultIgnore;
-// C++1y deduced return types
+// C++14 deduced return types
def err_auto_fn_deduction_failure : Error<
"cannot deduce return type %0 from returned value of type %1">;
def err_auto_fn_different_deductions : Error<
@@ -2160,6 +2163,9 @@ def err_auto_fn_return_init_list : Error
"cannot deduce return type from initializer list">;
def err_auto_fn_virtual : Error<
"function with deduced return type cannot be virtual">;
+def warn_cxx11_compat_deduced_return_type : Warning<
+ "return type deduction is incompatible with C++ standards before C++14">,
+ InGroup<CXXPre14Compat>, DefaultIgnore;
// C++11 override control
def override_keyword_only_allowed_on_virtual_member_functions : Error<
@@ -6576,6 +6582,11 @@ let CategoryName = "Lambda Issue" in {
def err_init_capture_deduction_failure_from_init_list : Error<
"cannot deduce type for lambda capture %0 from initializer list">;
+ // C++14 generic lambdas.
+ def warn_cxx11_compat_generic_lambda : Warning<
+ "generic lambdas are incompatible with C++11">,
+ InGroup<CXXPre14Compat>, DefaultIgnore;
+
// C++17 '*this' captures.
def warn_cxx14_compat_star_this_lambda_capture : Warning<
"by value capture of '*this' is incompatible with C++ standards before C++17">,
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=341098&r1=341097&r2=341098&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Aug 30 12:16:35 2018
@@ -9062,6 +9062,10 @@ QualType Sema::DeduceTemplateSpecializat
return QualType();
}
+ Diag(TSInfo->getTypeLoc().getBeginLoc(),
+ diag::warn_cxx14_compat_class_template_argument_deduction)
+ << TSInfo->getTypeLoc().getSourceRange();
+
// Can't deduce from dependent arguments.
if (Expr::hasAnyTypeDependentArguments(Inits))
return Context.DependentTy;
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=341098&r1=341097&r2=341098&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Aug 30 12:16:35 2018
@@ -2887,6 +2887,7 @@ static QualType GetDeclSpecTypeForDeclar
// class template argument deduction)?
bool IsCXXAutoType =
(Auto && Auto->getKeyword() != AutoTypeKeyword::GNUAutoType);
+ bool IsDeducedReturnType = false;
switch (D.getContext()) {
case DeclaratorContext::LambdaExprContext:
@@ -2978,10 +2979,12 @@ static QualType GetDeclSpecTypeForDeclar
case DeclaratorContext::TrailingReturnVarContext:
if (!SemaRef.getLangOpts().CPlusPlus14 || !IsCXXAutoType)
Error = 13; // Function return type
+ IsDeducedReturnType = true;
break;
case DeclaratorContext::ConversionIdContext:
if (!SemaRef.getLangOpts().CPlusPlus14 || !IsCXXAutoType)
Error = 14; // conversion-type-id
+ IsDeducedReturnType = true;
break;
case DeclaratorContext::FunctionalCastContext:
if (isa<DeducedTemplateSpecializationType>(Deduced))
@@ -3066,10 +3069,14 @@ static QualType GetDeclSpecTypeForDeclar
D.getContext() != DeclaratorContext::LambdaExprContext) {
// If there was a trailing return type, we already got
// warn_cxx98_compat_trailing_return_type in the parser.
- // If this was a lambda, we already warned on that too.
SemaRef.Diag(AutoRange.getBegin(),
- diag::warn_cxx98_compat_auto_type_specifier)
- << AutoRange;
+ D.getContext() ==
+ DeclaratorContext::LambdaExprParameterContext
+ ? diag::warn_cxx11_compat_generic_lambda
+ : IsDeducedReturnType
+ ? diag::warn_cxx11_compat_deduced_return_type
+ : diag::warn_cxx98_compat_auto_type_specifier)
+ << AutoRange;
}
}
@@ -4445,14 +4452,18 @@ static TypeSourceInfo *GetFullTypeForDec
// trailing-return-type is only required if we're declaring a function,
// and not, for instance, a pointer to a function.
if (D.getDeclSpec().hasAutoTypeSpec() &&
- !FTI.hasTrailingReturnType() && chunkIndex == 0 &&
- !S.getLangOpts().CPlusPlus14) {
- S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
- D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto
- ? diag::err_auto_missing_trailing_return
- : diag::err_deduced_return_type);
- T = Context.IntTy;
- D.setInvalidType(true);
+ !FTI.hasTrailingReturnType() && chunkIndex == 0) {
+ if (!S.getLangOpts().CPlusPlus14) {
+ S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
+ D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto
+ ? diag::err_auto_missing_trailing_return
+ : diag::err_deduced_return_type);
+ T = Context.IntTy;
+ D.setInvalidType(true);
+ } else {
+ S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
+ diag::warn_cxx11_compat_deduced_return_type);
+ }
} else if (FTI.hasTrailingReturnType()) {
// T must be exactly 'auto' at this point. See CWG issue 681.
if (isa<ParenType>(T)) {
@@ -4482,6 +4493,9 @@ static TypeSourceInfo *GetFullTypeForDec
T = Context.IntTy;
D.setInvalidType(true);
}
+ } else {
+ // This function type is not the type of the entity being declared,
+ // so checking the 'auto' is not the responsibility of this chunk.
}
}
Removed: cfe/trunk/test/SemaCXX/cxx0x-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-compat.cpp?rev=341097&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-compat.cpp (removed)
@@ -1,58 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat-pedantic -verify %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++11-compat-pedantic -verify %s
-
-#if __cplusplus < 201103L
-
-namespace N {
- template<typename T> void f(T) {} // expected-note 2{{here}}
- namespace M {
- template void ::N::f<int>(int); // expected-warning {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}
- }
-}
-using namespace N;
-template void f<char>(char); // expected-warning {{explicit instantiation of 'N::f' must occur in namespace 'N'}}
-
-template<typename T> void g(T) {} // expected-note 2{{here}}
-namespace M {
- template void g<int>(int); // expected-warning {{explicit instantiation of 'g' must occur at global scope}}
- template void ::g<char>(char); // expected-warning {{explicit instantiation of 'g' must occur at global scope}}
-}
-
-template inline void g<double>(double); // expected-warning {{explicit instantiation cannot be 'inline'}}
-
-void g() {
- auto int n = 0; // expected-warning {{'auto' storage class specifier is redundant and incompatible with C++11}}
-}
-
-int n;
-struct S {
- char c;
-}
-s = { n }, // expected-warning {{non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list in C++11}} expected-note {{explicit cast}}
-t = { 1234 }; // expected-warning {{constant expression evaluates to 1234 which cannot be narrowed to type 'char' in C++11}} expected-warning {{changes value}} expected-note {{explicit cast}}
-
-#define PRIuS "uS"
-int printf(const char *, ...);
-typedef __typeof(sizeof(int)) size_t;
-void h(size_t foo, size_t bar) {
- printf("foo is %"PRIuS", bar is %"PRIuS, foo, bar); // expected-warning 2{{identifier after literal will be treated as a reserved user-defined literal suffix in C++11}}
-}
-
-#define _x + 1
-char c = 'x'_x; // expected-warning {{will be treated as a user-defined literal suffix}}
-
-template<int ...N> int f() { // expected-warning {{C++11 extension}}
- return (N + ...); // expected-warning {{C++17 extension}}
-}
-
-#else
-
-auto init_capture = [a(0)] {}; // expected-warning {{initialized lambda captures are incompatible with C++ standards before C++14}}
-static_assert(true); // expected-warning {{incompatible with C++ standards before C++17}}
-
-template<int ...N> int f() { return (N + ...); } // expected-warning {{incompatible with C++ standards before C++17}}
-
-namespace [[]] NS_with_attr {} // expected-warning {{incompatible with C++ standards before C++17}}
-enum { e [[]] }; // expected-warning {{incompatible with C++ standards before C++17}}
-
-#endif
Copied: cfe/trunk/test/SemaCXX/cxx11-compat.cpp (from r341097, cfe/trunk/test/SemaCXX/cxx0x-compat.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-compat.cpp?p2=cfe/trunk/test/SemaCXX/cxx11-compat.cpp&p1=cfe/trunk/test/SemaCXX/cxx0x-compat.cpp&r1=341097&r2=341098&rev=341098&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx11-compat.cpp Thu Aug 30 12:16:35 2018
@@ -47,12 +47,30 @@ template<int ...N> int f() { // expected
#else
+decltype(auto) x = 0; // expected-warning {{'decltype(auto)' type specifier is incompatible}}
+
auto init_capture = [a(0)] {}; // expected-warning {{initialized lambda captures are incompatible with C++ standards before C++14}}
-static_assert(true); // expected-warning {{incompatible with C++ standards before C++17}}
-template<int ...N> int f() { return (N + ...); } // expected-warning {{incompatible with C++ standards before C++17}}
+auto generic_lambda =
+ [](
+ auto // expected-warning {{generic lambdas are incompatible}}
+ *a) {};
+
+auto deduced_return_type(); // expected-warning {{incompatible with C++ standards before C++14}}
+auto *another_deduced_return_type(); // expected-warning {{incompatible with C++ standards before C++14}}
+decltype(auto) also_deduced_return_type(); // expected-warning {{return type deduction}} expected-warning {{'decltype(auto)' type specifier is incompatible}}
+int f();
+auto (*not_deduced_return_type)() = f;
+
+auto deduced_lambda_return_type = []() ->
+ auto // expected-warning {{return type deduction is incompatible}}
+{};
+
+auto trailing_non_deduced_return_type() -> int;
+auto trailing_deduced_return_type() -> auto; // expected-warning {{incompatible with C++ standards before C++14}}
-namespace [[]] NS_with_attr {} // expected-warning {{incompatible with C++ standards before C++17}}
-enum { e [[]] }; // expected-warning {{incompatible with C++ standards before C++17}}
+struct A {
+ operator auto(); // expected-warning {{return type deduction is incompatible}}
+};
#endif
Modified: cfe/trunk/test/SemaCXX/cxx98-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx98-compat.cpp?rev=341098&r1=341097&r2=341098&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx98-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx98-compat.cpp Thu Aug 30 12:16:35 2018
@@ -103,7 +103,8 @@ struct RefQualifier {
auto f() -> int; // expected-warning {{trailing return types are incompatible with C++98}}
#ifdef CXX14COMPAT
-auto ff() { return 5; } // expected-warning {{'auto' type specifier is incompatible with C++98}}
+auto ff() { return 5; } // expected-warning {{'auto' type specifier is incompatible with C++98}}
+// expected-warning at -1 {{return type deduction is incompatible with C++ standards before C++14}}
#endif
void RangeFor() {
More information about the cfe-commits
mailing list