Don't produce a redundant "auto type is incompatible with C++98" on every lambda...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 May 2018 21:27:30 +0000 (21:27 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 May 2018 21:27:30 +0000 (21:27 +0000)
We already warned about the lambda, and we don't have a source location for the imagined "auto" anyway.

llvm-svn: 332401

clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/cxx98-compat.cpp

index b13570f..b51d494 100644 (file)
@@ -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;
index 33516f7..ed26660 100644 (file)
@@ -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 {