aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl2.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2010-02-09 15:05:51 -0500
committerJason Merrill <jason@gcc.gnu.org>2010-02-09 15:05:51 -0500
commit643d4cd6a10f6d202011eb3005c65994219932f3 (patch)
tree26a08d06bcdc1e2c8c582ce22c772d0c2726683d /gcc/cp/decl2.c
parentb16be5f2c5a0f9aaf398c55c2a3802d878433731 (diff)
downloadgcc-643d4cd6a10f6d202011eb3005c65994219932f3.zip
gcc-643d4cd6a10f6d202011eb3005c65994219932f3.tar.gz
gcc-643d4cd6a10f6d202011eb3005c65994219932f3.tar.bz2
re PR c++/42370 ([C++0x][lambda] in a void function: "Warning: control reaches end of non-void function")
PR c++/42370 * decl2.c (change_return_type): New fn. * semantics.c (apply_lambda_return_type): Use it. * cp-tree.h: Declare it. From-SVN: r156634
Diffstat (limited to 'gcc/cp/decl2.c')
-rw-r--r--gcc/cp/decl2.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 2b284fb..c5b6e87 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -139,6 +139,33 @@ build_memfn_type (tree fntype, tree ctype, cp_cv_quals quals)
return fntype;
}
+/* Return a variant of FNTYPE, a FUNCTION_TYPE or METHOD_TYPE, with its
+ return type changed to NEW_RET. */
+
+tree
+change_return_type (tree new_ret, tree fntype)
+{
+ tree newtype;
+ tree args = TYPE_ARG_TYPES (fntype);
+ tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
+ tree attrs = TYPE_ATTRIBUTES (fntype);
+
+ if (same_type_p (new_ret, TREE_TYPE (fntype)))
+ return fntype;
+
+ if (TREE_CODE (fntype) == FUNCTION_TYPE)
+ newtype = build_function_type (new_ret, args);
+ else
+ newtype = build_method_type_directly (TYPE_METHOD_BASETYPE (fntype),
+ new_ret, TREE_CHAIN (args));
+ if (raises)
+ newtype = build_exception_variant (newtype, raises);
+ if (attrs)
+ newtype = cp_build_type_attribute_variant (newtype, attrs);
+
+ return newtype;
+}
+
/* Build a PARM_DECL with NAME and TYPE, and set DECL_ARG_TYPE
appropriately. */