From 0be5162f64047decec3c655bf3fb3618b3d8d8e8 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 15 May 2018 21:27:30 +0000 Subject: [PATCH] Don't produce a redundant "auto type is incompatible with C++98" on every lambda with no explicit return type. We already warned about the lambda, and we don't have a source location for the imagined "auto" anyway. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332401 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaType.cpp | 4 +++- test/SemaCXX/cxx98-compat.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index b13570f97b..b51d49461f 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -2962,9 +2962,11 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state, T = SemaRef.Context.IntTy; D.setInvalidType(true); - } else if (!HaveTrailing) { + } else if (!HaveTrailing && + 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; diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp index 33516f7068..ed2666036a 100644 --- a/test/SemaCXX/cxx98-compat.cpp +++ b/test/SemaCXX/cxx98-compat.cpp @@ -47,6 +47,8 @@ namespace TemplateParsing { void Lambda() { []{}(); // expected-warning {{lambda expressions are incompatible with C++98}} + // Don't warn about implicit "-> auto" here. + [](){}(); // expected-warning {{lambda expressions are incompatible with C++98}} } struct Ctor { -- 2.40.0