From 7e783eb31289e9c506e33c1f9286387c0ff08425 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 2 Nov 2011 20:16:43 +0000 Subject: PR c++/50810 gcc/c-family * c-opts.c (c_common_handle_option): Enable -Wnarrowing as part of -Wall; include -Wnarrowing in -Wc++0x-compat; adjust default Wnarrowing for C++0x and C++98. * c.opt ([Wnarrowing]): Update. gcc/cp * typeck2.c (check_narrowing): Adjust OPT_Wnarrowing diagnostics. (digest_init_r): Call check_narrowing irrespective of the C++ dialect. * decl.c (check_initializer): Likewise. * semantics.c (finish_compound_literal): Likewise. gcc/ * configure.ac: Add -Wno-narrowing to warning options. libcpp/ * configure.ac: Add -Wno-narrowing to warning options. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180794 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 860556c21a9..edbc783b567 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5538,7 +5538,7 @@ check_initializer (tree decl, tree init, int flags, tree *cleanup) else { init = reshape_init (type, init, tf_warning_or_error); - if (cxx_dialect >= cxx0x && SCALAR_TYPE_P (type)) + if (SCALAR_TYPE_P (type)) check_narrowing (type, init); } } -- cgit v1.2.1 From c7b89256f73ad16b147bec0176ebacf9ca8d9454 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 4 Nov 2011 12:54:08 +0000 Subject: PR c++/48370 * call.c (extend_ref_init_temps, extend_ref_init_temps_1): New. (set_up_extended_ref_temp): Use it. Change cleanup parm to VEC. (initialize_reference): Just call convert_like. * decl.c (grok_reference_init): Just call initialize_reference. (build_init_list_var_init): Remove. (check_initializer): Change cleanup parm to VEC. Handle references like other types. Call perform_implicit_conversion instead of build_init_list_var_init. Don't use build_aggr_init for aggregate initialization of arrays. (cp_finish_decl): Change cleanup to VEC. * typeck2.c (store_init_value): Call extend_ref_init_temps. Use build_vec_init for non-constant arrays. * init.c (expand_aggr_init_1): Adjust. (build_vec_init): Avoid re-converting an initializer that's already digested. * mangle.c (mangle_ref_init_variable): Add a discriminator. * cp-tree.h: Adjust. * typeck.c (convert_for_initialization): Adjust. * decl2.c (maybe_emit_vtables): Adjust. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180944 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 114 +++++++++++++++++----------------------------------------- 1 file changed, 33 insertions(+), 81 deletions(-) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index edbc783b567..50c45de8633 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -71,7 +71,7 @@ static void require_complete_types_for_parms (tree); static int ambi_op_p (enum tree_code); static int unary_op_p (enum tree_code); static void push_local_name (tree); -static tree grok_reference_init (tree, tree, tree, tree *, int); +static tree grok_reference_init (tree, tree, tree, int); static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *, int, int, tree); static int check_static_variable_definition (tree, tree); @@ -91,7 +91,7 @@ static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool); static int walk_namespaces_r (tree, walk_namespaces_fn, void *); static void maybe_deduce_size_from_array_init (tree, tree); static void layout_var_decl (tree); -static tree check_initializer (tree, tree, int, tree *); +static tree check_initializer (tree, tree, int, VEC(tree,gc) **); static void make_rtl_for_nonlocal_decl (tree, tree, const char *); static void save_function_data (tree); static void copy_type_enum (tree , tree); @@ -4611,11 +4611,8 @@ start_decl_1 (tree decl, bool initialized) Quotes on semantics can be found in ARM 8.4.3. */ static tree -grok_reference_init (tree decl, tree type, tree init, tree *cleanup, - int flags) +grok_reference_init (tree decl, tree type, tree init, int flags) { - tree tmp; - if (init == NULL_TREE) { if ((DECL_LANG_SPECIFIC (decl) == 0 @@ -4641,62 +4638,8 @@ grok_reference_init (tree decl, tree type, tree init, tree *cleanup, DECL_INITIAL for local references (instead assigning to them explicitly); we need to allow the temporary to be initialized first. */ - tmp = initialize_reference (type, init, decl, cleanup, flags, - tf_warning_or_error); - if (DECL_DECLARED_CONSTEXPR_P (decl)) - { - tmp = cxx_constant_value (tmp); - DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) - = reduced_constant_expression_p (tmp); - } - - if (tmp == error_mark_node) - return NULL_TREE; - else if (tmp == NULL_TREE) - { - error ("cannot initialize %qT from %qT", type, TREE_TYPE (init)); - return NULL_TREE; - } - - if (TREE_STATIC (decl) && !TREE_CONSTANT (tmp)) - return tmp; - - DECL_INITIAL (decl) = tmp; - - return NULL_TREE; -} - -/* Subroutine of check_initializer. We're initializing a DECL of - std::initializer_list TYPE from a braced-init-list INIT, and need to - extend the lifetime of the underlying array to match that of the decl, - just like for reference initialization. CLEANUP is as for - grok_reference_init. */ - -static tree -build_init_list_var_init (tree decl, tree type, tree init, tree *array_init, - tree *cleanup) -{ - tree aggr_init, array, arrtype; - init = perform_implicit_conversion (type, init, tf_warning_or_error); - if (error_operand_p (init)) - return error_mark_node; - - aggr_init = TARGET_EXPR_INITIAL (init); - array = CONSTRUCTOR_ELT (aggr_init, 0)->value; - arrtype = TREE_TYPE (array); - STRIP_NOPS (array); - gcc_assert (TREE_CODE (array) == ADDR_EXPR); - array = TREE_OPERAND (array, 0); - /* If the array is constant, finish_compound_literal already made it a - static variable and we don't need to do anything here. */ - if (decl && TREE_CODE (array) == TARGET_EXPR) - { - tree var = set_up_extended_ref_temp (decl, array, cleanup, array_init); - var = build_address (var); - var = convert (arrtype, var); - CONSTRUCTOR_ELT (aggr_init, 0)->value = var; - } - return init; + return initialize_reference (type, init, flags, + tf_warning_or_error); } /* Designated initializers in arrays are not supported in GNU C++. @@ -5440,7 +5383,7 @@ build_aggr_init_full_exprs (tree decl, tree init, int flags) evaluated dynamically to initialize DECL. */ static tree -check_initializer (tree decl, tree init, int flags, tree *cleanup) +check_initializer (tree decl, tree init, int flags, VEC(tree,gc) **cleanups) { tree type = TREE_TYPE (decl); tree init_code = NULL; @@ -5509,19 +5452,26 @@ check_initializer (tree decl, tree init, int flags, tree *cleanup) } else if (!init && DECL_REALLY_EXTERN (decl)) ; - else if (TREE_CODE (type) == REFERENCE_TYPE) - init = grok_reference_init (decl, type, init, cleanup, flags); - else if (init || type_build_ctor_call (type)) + else if (init || type_build_ctor_call (type) + || TREE_CODE (type) == REFERENCE_TYPE) { - if (!init) + if (TREE_CODE (type) == REFERENCE_TYPE) + { + init = grok_reference_init (decl, type, init, flags); + flags |= LOOKUP_ALREADY_DIGESTED; + } + else if (!init) check_for_uninitialized_const_var (decl); /* Do not reshape constructors of vectors (they don't need to be reshaped. */ else if (BRACE_ENCLOSED_INITIALIZER_P (init)) { if (is_std_init_list (type)) - init = build_init_list_var_init (decl, type, init, - &extra_init, cleanup); + { + init = perform_implicit_conversion (type, init, + tf_warning_or_error); + flags |= LOOKUP_ALREADY_DIGESTED; + } else if (TYPE_NON_AGGREGATE_CLASS (type)) { /* Don't reshape if the class has constructors. */ @@ -5550,9 +5500,10 @@ check_initializer (tree decl, tree init, int flags, tree *cleanup) if (type == error_mark_node) return NULL_TREE; - if (type_build_ctor_call (type) - || (CLASS_TYPE_P (type) - && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)))) + if ((type_build_ctor_call (type) || CLASS_TYPE_P (type)) + && !(flags & LOOKUP_ALREADY_DIGESTED) + && !(init && BRACE_ENCLOSED_INITIALIZER_P (init) + && CP_AGGREGATE_TYPE_P (type))) { init_code = build_aggr_init_full_exprs (decl, init, flags); @@ -5594,7 +5545,7 @@ check_initializer (tree decl, tree init, int flags, tree *cleanup) if (init && TREE_CODE (init) != TREE_VEC) { - init_code = store_init_value (decl, init, flags); + init_code = store_init_value (decl, init, cleanups, flags); if (pedantic && TREE_CODE (type) == ARRAY_TYPE && DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST @@ -5956,7 +5907,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, tree asmspec_tree, int flags) { tree type; - tree cleanup; + VEC(tree,gc) *cleanups = NULL; const char *asmspec = NULL; int was_readonly = 0; bool var_definition_p = false; @@ -5979,9 +5930,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (type == error_mark_node) return; - /* Assume no cleanup is required. */ - cleanup = NULL_TREE; - /* If a name was specified, get the string. */ if (at_namespace_scope_p ()) asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree); @@ -6101,7 +6049,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* This variable seems to be a non-dependent constant, so process its initializer. If check_initializer returns non-null the initialization wasn't constant after all. */ - tree init_code = check_initializer (decl, init, flags, &cleanup); + tree init_code = check_initializer (decl, init, flags, &cleanups); if (init_code == NULL_TREE) init = NULL_TREE; } @@ -6202,7 +6150,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, error ("Java object %qD not allocated with %", decl); init = NULL_TREE; } - init = check_initializer (decl, init, flags, &cleanup); + init = check_initializer (decl, init, flags, &cleanups); /* Thread-local storage cannot be dynamically initialized. */ if (DECL_THREAD_LOCAL_P (decl) && init) { @@ -6367,8 +6315,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* If a CLEANUP_STMT was created to destroy a temporary bound to a reference, insert it in the statement-tree now. */ - if (cleanup) - push_cleanup (decl, cleanup, false); + if (cleanups) + { + unsigned i; tree t; + FOR_EACH_VEC_ELT_REVERSE (tree, cleanups, i, t) + push_cleanup (decl, t, false); + } if (was_readonly) TREE_READONLY (decl) = 1; -- cgit v1.2.1 From 8ff0f9e3a3d3efc8cbb71c34d56595b00b874726 Mon Sep 17 00:00:00 2001 From: jason Date: Sat, 5 Nov 2011 03:28:05 +0000 Subject: PR c++/48370 * decl.c (cp_finish_decl): Run cleanups in the right order. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181001 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 50c45de8633..65413df2620 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5907,7 +5907,8 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, tree asmspec_tree, int flags) { tree type; - VEC(tree,gc) *cleanups = NULL; + VEC(tree,gc) *cleanups = make_tree_vector (); + unsigned i; tree t; const char *asmspec = NULL; int was_readonly = 0; bool var_definition_p = false; @@ -6315,12 +6316,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* If a CLEANUP_STMT was created to destroy a temporary bound to a reference, insert it in the statement-tree now. */ - if (cleanups) - { - unsigned i; tree t; - FOR_EACH_VEC_ELT_REVERSE (tree, cleanups, i, t) - push_cleanup (decl, t, false); - } + FOR_EACH_VEC_ELT (tree, cleanups, i, t) + push_cleanup (decl, t, false); + release_tree_vector (cleanups); if (was_readonly) TREE_READONLY (decl) = 1; -- cgit v1.2.1 From 912671062574134eafb369d14db8cf6c1d840f1a Mon Sep 17 00:00:00 2001 From: jason Date: Sat, 5 Nov 2011 21:06:34 +0000 Subject: * decl.c (cp_finish_decl): Mostly revert previous change. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181017 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 65413df2620..d2daf918956 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5907,8 +5907,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, tree asmspec_tree, int flags) { tree type; - VEC(tree,gc) *cleanups = make_tree_vector (); - unsigned i; tree t; + VEC(tree,gc) *cleanups = NULL; const char *asmspec = NULL; int was_readonly = 0; bool var_definition_p = false; @@ -6316,9 +6315,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* If a CLEANUP_STMT was created to destroy a temporary bound to a reference, insert it in the statement-tree now. */ - FOR_EACH_VEC_ELT (tree, cleanups, i, t) - push_cleanup (decl, t, false); - release_tree_vector (cleanups); + if (cleanups) + { + unsigned i; tree t; + FOR_EACH_VEC_ELT (tree, cleanups, i, t) + push_cleanup (decl, t, false); + } if (was_readonly) TREE_READONLY (decl) = 1; -- cgit v1.2.1 From 18aeca2550226b6e869545bf8e10fb68f3a2a55d Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 7 Nov 2011 17:51:16 +0000 Subject: * decl.c (cp_finish_decl): Only make_tree_vector if we're calling check_initializer. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181099 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d2daf918956..3b283d83d26 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6049,9 +6049,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* This variable seems to be a non-dependent constant, so process its initializer. If check_initializer returns non-null the initialization wasn't constant after all. */ - tree init_code = check_initializer (decl, init, flags, &cleanups); + tree init_code; + cleanups = make_tree_vector (); + init_code = check_initializer (decl, init, flags, &cleanups); if (init_code == NULL_TREE) init = NULL_TREE; + release_tree_vector (cleanups); } else if (!DECL_PRETTY_FUNCTION_P (decl)) /* Deduce array size even if the initializer is dependent. */ @@ -6150,6 +6153,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, error ("Java object %qD not allocated with %", decl); init = NULL_TREE; } + cleanups = make_tree_vector (); init = check_initializer (decl, init, flags, &cleanups); /* Thread-local storage cannot be dynamically initialized. */ if (DECL_THREAD_LOCAL_P (decl) && init) @@ -6320,6 +6324,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, unsigned i; tree t; FOR_EACH_VEC_ELT (tree, cleanups, i, t) push_cleanup (decl, t, false); + release_tree_vector (cleanups); } if (was_readonly) -- cgit v1.2.1 From 47c744263296d7150ef9e421a85b0be54ad7e3de Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 7 Nov 2011 17:51:24 +0000 Subject: PR c++/33255 * decl.c (save_function_data): Clear local_typedefs. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181100 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3b283d83d26..63da51d79d9 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -13021,6 +13021,7 @@ save_function_data (tree decl) f->base.x_stmt_tree.x_cur_stmt_list = NULL; f->bindings = NULL; f->x_local_names = NULL; + f->base.local_typedefs = NULL; } -- cgit v1.2.1 From 370478b178a3bdf01988c16782c90add8aea26aa Mon Sep 17 00:00:00 2001 From: dodji Date: Mon, 7 Nov 2011 21:28:50 +0000 Subject: PR c++/45114 - Support C++11 alias-declaration gcc/cp/ * cp-tree.h (TYPE_DECL_ALIAS_P, TYPE_ALIAS_P) (DECL_TYPE_TEMPLATE_P, DECL_ALIAS_TEMPLATE_P): New accessor macros. (TYPE_TEMPLATE_INFO): Get template info of an alias template specializations from its TYPE_DECL. (SET_TYPE_TEMPLATE_INFO): Set template info of alias template specializations into its TYPE_DECL. (DECL_CLASS_TEMPLATE_P): Re-write using the new DECL_TYPE_TEMPLATE_P. (enum cp_decl_spec): Add new ds_alias enumerator. (alias_type_or_template_p, alias_template_specialization_p): Declare new functions. * parser.c (cp_parser_alias_declaration): New static function. (cp_parser_check_decl_spec): Add "using" name for the `alias' declspec. (cp_parser_type_name): Update comment. Support simple-template-id representing alias template specializations in c++0x mode. (cp_parser_qualifying_entity): Update comment. Use cp_parser_type_name. (cp_parser_block_declaration): Handle alias-declaration in c++11. Update comment. (cp_parser_template_id): Handle specializations of alias templates. (cp_parser_member_declaration): Add alias-declaration production to comment. Support alias-declarations. (cp_parser_template_declaration_after_export): Handle alias templates in c++11. * decl.c (make_typename_type, make_unbound_class_template): Accept alias templates. (grokdeclarator): Set TYPE_DECL_ALIAS_P on alias declarations. * decl2.c (grokfield): Move template creation after setting up the TYPE_DECL of the alias, so that the TEMPLATE_DECL of the alias template actually carries the right type-id of the alias declaration. * pt.c (alias_type_or_template_p) (alias_template_specialization_p): Define new public functions. (maybe_process_partial_specialization): Reject partial specializations of alias templates. (primary_template_instantiation_p): Consider alias template instantiations. (push_template_decl_real): Assert that TYPE_DECLs of alias templates are different from those of class template. Store template info onto the TYPE_DECL of the alias template. (convert_template_argument): Strip aliases from template arguments. (lookup_template_class_1): Handle the creation of the specialization of an alias template. (tsubst_decl): Create a substituted copy of the TYPE_DECL of an member alias template. (tsubst): Handle substituting into the type of an alias template. Handle substituting UNBOUND_CLASS_TEMPLATE into BOUND_TEMPLATE_TEMPLATE_PARM. (do_type_instantiation): Better diagnostics when trying to explicitely instantiate a non-class template. * search.c (lookup_field_1, lookup_field_r): Support looking up alias templates. * semantics.c (finish_template_type): For instantiations of alias templates, return the TYPE_DECL of the actual alias and not the one of the aliased type. * error.c (dump_alias_template_specialization): New static function. (dump_type): Handle printing of alias templates and their specializations. templates. (dump_aggr_type): For specialization of alias templates, fetch arguments from the right place. (dump_decl): Print an alias-declaration like `using decl = type;' (dump_template_decl): Support printing of alias templates. gcc/testsuite/ * g++.dg/cpp0x/alias-decl-0.C: New test case. * g++.dg/cpp0x/alias-decl-1.C: Likewise. * g++.dg/cpp0x/alias-decl-3.C: Likewise. * g++.dg/cpp0x/alias-decl-4.C: Likewise. * g++.dg/cpp0x/alias-decl-6.C: Likewise. * g++.dg/cpp0x/alias-decl-7.C: Likewise. * g++.dg/cpp0x/alias-decl-8.C: Likewise. * g++.dg/cpp0x/alias-decl-9.C: Likewise. * g++.dg/cpp0x/alias-decl-10.C: Likewise. * g++.dg/ext/alias-decl-attr1.C: Likewise. * g++.dg/ext/alias-decl-attr2.C: Likewise. * g++.dg/ext/alias-decl-attr3.C: Likewise. * g++.dg/ext/alias-decl-attr4.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181118 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 63da51d79d9..e4b91cc533b 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3270,7 +3270,7 @@ make_typename_type (tree context, tree name, enum tag_types tag_type, return error_mark_node; } - if (want_template && !DECL_CLASS_TEMPLATE_P (t)) + if (want_template && !DECL_TYPE_TEMPLATE_P (t)) { if (complain & tf_error) error ("% names %q#T, which is not a class template", @@ -3338,7 +3338,7 @@ make_unbound_class_template (tree context, tree name, tree parm_list, if (tmpl && TREE_CODE (tmpl) == TYPE_DECL) tmpl = maybe_get_template_decl_from_type_decl (tmpl); - if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl)) + if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl)) { if (complain & tf_error) error ("no class template named %q#T in %q#T", name, context); @@ -9747,6 +9747,11 @@ grokdeclarator (const cp_declarator *declarator, memfn_quals != TYPE_UNQUALIFIED, inlinep, friendp, raises != NULL_TREE); + if (declspecs->specs[(int)ds_alias]) + /* Acknowledge that this was written: + `using analias = atype;'. */ + TYPE_DECL_ALIAS_P (decl) = 1; + return decl; } -- cgit v1.2.1