r187275 - Handle a difference in lambda return type deduction between C++11 and C++1y: if

Richard Smith richard-llvm at metafoo.co.uk
Fri Jul 26 16:45:07 PDT 2013


Author: rsmith
Date: Fri Jul 26 18:45:07 2013
New Revision: 187275

URL: http://llvm.org/viewvc/llvm-project?rev=187275&view=rev
Log:
Handle a difference in lambda return type deduction between C++11 and C++1y: if
no return type is specified, C++11 will deduce a cv-qualified return type in
some cases, but C++1y never will.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
    cfe/trunk/test/SemaCXX/lambda-expressions.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=187275&r1=187274&r2=187275&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Jul 26 18:45:07 2013
@@ -2376,9 +2376,15 @@ Sema::ActOnCapScopeReturnStmt(SourceLoca
         return StmtError();
       RetValExp = Result.take();
 
-      if (!CurContext->isDependentContext())
+      if (!CurContext->isDependentContext()) {
         FnRetType = RetValExp->getType();
-      else
+        // In C++11, we take the type of the expression after decay and
+        // lvalue-to-rvalue conversion, so a class type can be cv-qualified.
+        // In C++1y, we perform template argument deduction as if the return
+        // type were 'auto', so an implicit return type is never cv-qualified.
+        if (getLangOpts().CPlusPlus1y && FnRetType.hasQualifiers())
+          FnRetType = FnRetType.getUnqualifiedType();
+      } else
         FnRetType = CurCap->ReturnType = Context.DependentTy;
     } else {
       if (RetValExp) {

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp?rev=187275&r1=187274&r2=187275&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp Fri Jul 26 18:45:07 2013
@@ -39,7 +39,10 @@ X infer_X_return_type_fail(X x) {
     if (y > 0)
       return X();
     else
-      return x; // expected-error{{return type 'const X' must match previous return type 'X' when lambda expression has unspecified explicit return type}}
+      return x;
+#if __cplusplus <= 201103L
+    // expected-error at -2 {{return type 'const X' must match previous return type 'X' when lambda expression has unspecified explicit return type}}
+#endif
   }(5);
 }
 

Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=187275&r1=187274&r2=187275&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Fri Jul 26 18:45:07 2013
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++0x -Wno-unused-value -fsyntax-only -verify -fblocks %s
+// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only -verify -fblocks %s
+// RUN: %clang_cc1 -std=c++1y -Wno-unused-value -fsyntax-only -verify -fblocks %s
 
 namespace std { class type_info; };
 
@@ -251,3 +252,16 @@ namespace PR16708 {
     return 0;
   };
 }
+
+namespace TypeDeduction {
+  struct S {};
+  void f() {
+    const S s {};
+    S &&t = [&] { return s; } ();
+#if __cplusplus <= 201103L
+    // expected-error at -2 {{drops qualifiers}}
+#else
+    S &&u = [&] () -> auto { return s; } ();
+#endif
+  }
+}





More information about the cfe-commits mailing list