From 643d4cd6a10f6d202011eb3005c65994219932f3 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 9 Feb 2010 15:05:51 -0500 Subject: 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 --- gcc/cp/decl2.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gcc/cp/decl2.c') 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. */ -- cgit v1.1