diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-08-30 19:16:35 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-08-30 19:16:35 +0000 |
commit | 218538ebe95294ec8550853df15277d6b61c7c3d (patch) | |
tree | 8f439da6e194cda5de7c07661accbca35358fd7a /clang/lib/Sema | |
parent | 09ac4a1bc9a9662913924a413030cc9b35c93c20 (diff) | |
download | bcm5719-llvm-218538ebe95294ec8550853df15277d6b61c7c3d.tar.gz bcm5719-llvm-218538ebe95294ec8550853df15277d6b61c7c3d.zip |
Add missing -Wc++11-compat / -Wc++14-compat warnings for:
* generic lambdas
* return type deduction
* class template argument deduction
llvm-svn: 341098
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaType.cpp | 36 |
2 files changed, 29 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index b95ad1054d7..634554e0964 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -9062,6 +9062,10 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( 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; diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index a2153a2de96..2f4d1826165 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2887,6 +2887,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state, // 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 GetDeclSpecTypeForDeclarator(TypeProcessingState &state, 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 GetDeclSpecTypeForDeclarator(TypeProcessingState &state, 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 *GetFullTypeForDeclarator(TypeProcessingState &state, // 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 *GetFullTypeForDeclarator(TypeProcessingState &state, 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. } } |