r332401 - Don't produce a redundant "auto type is incompatible with C++98" on every lambda with no explicit return type.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue May 15 14:27:30 PDT 2018


Author: rsmith
Date: Tue May 15 14:27:30 2018
New Revision: 332401

URL: http://llvm.org/viewvc/llvm-project?rev=332401&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaCXX/cxx98-compat.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=332401&r1=332400&r2=332401&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue May 15 14:27:30 2018
@@ -2962,9 +2962,11 @@ static QualType GetDeclSpecTypeForDeclar
 
       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;

Modified: cfe/trunk/test/SemaCXX/cxx98-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx98-compat.cpp?rev=332401&r1=332400&r2=332401&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx98-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx98-compat.cpp Tue May 15 14:27:30 2018
@@ -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 {




More information about the cfe-commits mailing list