diff options
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r-- | gcc/cp/decl.c | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index c9cac551a55..754f433c30a 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5488,11 +5488,20 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, DECL_INITIALIZED_IN_CLASS_P (decl) = 1; auto_node = type_uses_auto (type); - if (auto_node && !type_dependent_expression_p (init)) + if (auto_node) { - type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node); - if (type == error_mark_node) - return; + if (init == NULL_TREE) + { + error ("declaration of %q#D has no initializer", decl); + TREE_TYPE (decl) = error_mark_node; + return; + } + else if (!type_dependent_expression_p (init)) + { + type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node); + if (type == error_mark_node) + return; + } } if (processing_template_decl) @@ -8228,16 +8237,40 @@ grokdeclarator (const cp_declarator *declarator, /* Pick up the exception specifications. */ raises = declarator->u.function.exception_specification; + /* Say it's a definition only for the CALL_EXPR + closest to the identifier. */ + funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id; + /* Handle a late-specified return type. */ + if (funcdecl_p) + { + if (type_uses_auto (type)) + { + if (!declarator->u.function.late_return_type) + { + error ("%qs function uses auto type specifier without" + " late return type", name); + return error_mark_node; + } + else if (!is_auto (type)) + { + error ("%qs function with late return type not using" + " auto type specifier as its type", name); + return error_mark_node; + } + } + else if (declarator->u.function.late_return_type) + { + error ("%qs function with late return type not declared" + " with auto type specifier", name); + return error_mark_node; + } + } type = splice_late_return_type (type, declarator->u.function.late_return_type); if (type == error_mark_node) return error_mark_node; - /* Say it's a definition only for the CALL_EXPR - closest to the identifier. */ - funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id; - if (ctype == NULL_TREE && decl_context == FIELD && funcdecl_p |