PR c++/85842 - -Wreturn-type, constexpr if and generic lambda.
authorJason Merrill <jason@redhat.com>
Thu, 24 May 2018 20:03:18 +0000 (16:03 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 24 May 2018 20:03:18 +0000 (16:03 -0400)
* pt.c (tsubst_lambda_expr): Copy current_function_returns_* to
generic lambda.

From-SVN: r260685

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C [new file with mode: 0644]

index fdf73d182eb36331e2f62f632e0b497139b2b70a..371c8b76fef474471534fc01b9c730c965bf5c61 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-24  Jason Merrill  <jason@redhat.com>
+
+       PR c++/85842 - -Wreturn-type, constexpr if and generic lambda.
+       * pt.c (tsubst_lambda_expr): Copy current_function_returns_* to
+       generic lambda.
+
 2018-05-24  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        Pedwarn on a non-standard position of a C++ attribute.
index cfce9a9db62b21d8c4777a9c0bb7085802cbebac..d0fc9ee51a50e47794865b8f4489fa62d5b62836 100644 (file)
@@ -17636,6 +17636,17 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 
       register_parameter_specializations (oldfn, fn);
 
+      if (oldtmpl)
+       {
+         /* We might not partially instantiate some parts of the function, so
+            copy these flags from the original template.  */
+         language_function *ol = DECL_STRUCT_FUNCTION (oldfn)->language;
+         current_function_returns_value = ol->returns_value;
+         current_function_returns_null = ol->returns_null;
+         current_function_returns_abnormally = ol->returns_abnormally;
+         current_function_infinite_loop = ol->infinite_loop;
+       }
+
       tsubst_expr (DECL_SAVED_TREE (oldfn), args, complain, r,
                   /*constexpr*/false);
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C
new file mode 100644 (file)
index 0000000..8e31db3
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/85842
+// { dg-additional-options -std=c++17 }
+
+template<class T>
+auto f = [](auto&& arg) -> T* {
+    if constexpr (sizeof(arg) == 1) {
+        return nullptr;
+    } else {
+        return static_cast<T*>(&arg);
+    }
+};
+
+auto p = f<int>(0);