diff options
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r-- | gcc/cp/decl.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5c519146043..836506ef7be 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6400,7 +6400,9 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups) } if (init_code - && (DECL_IN_AGGR_P (decl) && !DECL_VAR_DECLARED_INLINE_P (decl))) + && (DECL_IN_AGGR_P (decl) + && DECL_INITIALIZED_IN_CLASS_P (decl) + && !DECL_VAR_DECLARED_INLINE_P (decl))) { static int explained = 0; @@ -7228,9 +7230,9 @@ find_decomp_class_base (location_t loc, tree type, tree ret) inform (DECL_SOURCE_LOCATION (field), "declared here"); return error_mark_node; } - else if (TREE_PRIVATE (field) || TREE_PROTECTED (field)) + else if (!accessible_p (type, field, true)) { - error_at (loc, "cannot decompose non-public member %qD of %qT", + error_at (loc, "cannot decompose inaccessible member %qD of %qT", field, type); inform (DECL_SOURCE_LOCATION (field), TREE_PRIVATE (field) @@ -7338,7 +7340,29 @@ get_tuple_decomp_init (tree decl, unsigned i) tree fns = lookup_qualified_name (TREE_TYPE (e), get_id, /*type*/false, /*complain*/false); - if (fns != error_mark_node) + bool use_member_get = false; + + /* To use a member get, member lookup must find at least one + declaration that is a function template + whose first template parameter is a non-type parameter. */ + for (tree iter = BASELINK_P (fns) ? BASELINK_FUNCTIONS (fns) : fns; + iter; + iter = OVL_NEXT (iter)) + { + tree fn = OVL_CURRENT (iter); + if (TREE_CODE (fn) == TEMPLATE_DECL) + { + tree tparms = DECL_TEMPLATE_PARMS (fn); + tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0); + if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL) + { + use_member_get = true; + break; + } + } + } + + if (use_member_get) { fns = lookup_template_function (fns, targs); return build_new_method_call (e, fns, /*args*/NULL, @@ -10105,6 +10129,8 @@ grokdeclarator (const cp_declarator *declarator, declspecs->locations); if (typespec_loc == UNKNOWN_LOCATION) typespec_loc = declspecs->locations[ds_type_spec]; + if (typespec_loc == UNKNOWN_LOCATION) + typespec_loc = input_location; /* Look inside a declarator for the name being declared and get it as a string, for an error message. */ |