From patchwork Tue Jul 1 18:49:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Pluzhnikov X-Patchwork-Id: 366189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 05A501400A7 for ; Wed, 2 Jul 2014 04:50:25 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=TEQc6DiJC31b2mC yDsSIoUuvE8TEa7D9SzvdBw+pw73uydBeLC2xM5ZYvqKNhz6Q7b1x67N49HvpizC xXoxCWKniA08X7N0TxKkYx0J+ARxmBDhRnW2gc/jJo9UxysfaksKJYPlioKBNobK PudFuJhgPXe2G2VyyAY9DNgxzwek= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=tE2wmpRvFGK//30Dgh2Lb ByZvSA=; b=k7YHZn0Yc/Z08SWS6FdCrnOlA7wKyLx6n3UbCdV+oceHlJyG60lAq e5dk5FNK2Pg5psJffvNaFnMy0dtfJJDrn140FMOJ/8E4gahEDiiDGYk39VKEcIbR 6eLO96mfKPhBifMEJoVjXkJHY3dxpG39se03oZHetRMM9pOmfok1gs= Received: (qmail 29603 invoked by alias); 1 Jul 2014 18:50:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 29563 invoked by uid 89); 1 Jul 2014 18:50:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ie0-f172.google.com Received: from mail-ie0-f172.google.com (HELO mail-ie0-f172.google.com) (209.85.223.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 01 Jul 2014 18:50:06 +0000 Received: by mail-ie0-f172.google.com with SMTP id lx4so8539041iec.3 for ; Tue, 01 Jul 2014 11:50:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=W2+J44ERRxcReP7O8D+KsRIqnYRCLnlO0O2bc2p98Ug=; b=G2jsOw9kig4stZe43qQFKSho+pEscyW8gboLttkPyj3tLZPEi2gGhxKH3NtVaU42yU SYmD4wI3+vodNhPBQaIAEFCjpnwa4UJ4sMuYBQEltg9AXHAOL7F75uGGFp4FeOm4oFxf +p1Nvdmw3+a46QQs3iQ9vIu3+omxBf5NIG0l8BYo1zVjHCNNzhlInyYaJHN16ZZ5aL4e 4GSxFZaUFzXmS3zEKAVUTE7YAXvbnWIiq1zABtZOGv4MMju8xwIr7ijOXju2+IE5Snpc OY8JS3u9cwcM7bpiv8fCbfQlcieoeFv/QVLzUT82X/Ms8gS5mzySrWOl31ITIjfSjSN2 sT2Q== X-Gm-Message-State: ALoCoQl9tlzIAch+GasHwweQztPjAuwpCyLswTXjyejuYj2BT40mt0JYzga+gm4Or5Y7Efpam8GF X-Received: by 10.42.78.208 with SMTP id o16mr46055320ick.16.1404240604314; Tue, 01 Jul 2014 11:50:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.32.168 with HTTP; Tue, 1 Jul 2014 11:49:32 -0700 (PDT) In-Reply-To: <53ADCB49.4060308@redhat.com> References: <53ADCB49.4060308@redhat.com> From: Paul Pluzhnikov Date: Tue, 1 Jul 2014 11:49:32 -0700 Message-ID: Subject: Re: Ok to backport r210653 (fix for PR58930) to gcc-4_9-branch? To: Jason Merrill Cc: gcc-patches , Paolo Carlini On Fri, Jun 27, 2014 at 12:51 PM, Jason Merrill wrote: > On 06/27/2014 11:04 AM, Paul Pluzhnikov wrote: >> >> Ok to backport r210653 (fix for PR58930) to gcc-4_9-branch? > > > OK, yes. Thanks. Committed attached patch as r212207. Tested on Linux/x86_64, no regressions. Index: gcc/testsuite/g++.dg/cpp0x/nsdmi-template11.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/nsdmi-template11.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/nsdmi-template11.C (revision 212207) @@ -0,0 +1,30 @@ +// PR c++/58930 +// { dg-do compile { target c++11 } } + +struct SampleModule +{ + explicit SampleModule (int); +}; + +template < typename > +struct BaseHandler +{ + SampleModule module_ { 0 }; +}; + +BaseHandler a; +// PR c++/58930 +// { dg-do compile { target c++11 } } + +struct SampleModule +{ + explicit SampleModule (int); +}; + +template < typename > +struct BaseHandler +{ + SampleModule module_ { 0 }; +}; + +BaseHandler a; Index: gcc/testsuite/g++.dg/cpp0x/nsdmi-template13.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/nsdmi-template13.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/nsdmi-template13.C (revision 212207) @@ -0,0 +1,22 @@ +// PR c++/58704 +// { dg-do compile { target c++11 } } + +struct A {}; + +template struct B +{ + A a[1] = { }; +}; + +B b; +// PR c++/58704 +// { dg-do compile { target c++11 } } + +struct A {}; + +template struct B +{ + A a[1] = { }; +}; + +B b; Index: gcc/testsuite/g++.dg/cpp0x/nsdmi-template12.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/nsdmi-template12.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/nsdmi-template12.C (revision 212207) @@ -0,0 +1,34 @@ +// PR c++/58753 +// { dg-do compile { target c++11 } } + +#include + +template +struct X {X(std::initializer_list) {}}; + +template +class T { + X x{1}; +}; + +int main() +{ + T t; +} +// PR c++/58753 +// { dg-do compile { target c++11 } } + +#include + +template +struct X {X(std::initializer_list) {}}; + +template +class T { + X x{1}; +}; + +int main() +{ + T t; +} Index: gcc/cp/init.c =================================================================== --- gcc/cp/init.c (revision 212206) +++ gcc/cp/init.c (revision 212207) @@ -522,6 +522,49 @@ } } +/* Return the non-static data initializer for FIELD_DECL MEMBER. */ + +tree +get_nsdmi (tree member, bool in_ctor) +{ + tree init; + tree save_ccp = current_class_ptr; + tree save_ccr = current_class_ref; + if (!in_ctor) + inject_this_parameter (DECL_CONTEXT (member), TYPE_UNQUALIFIED); + if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member)) + { + /* Do deferred instantiation of the NSDMI. */ + init = (tsubst_copy_and_build + (DECL_INITIAL (DECL_TI_TEMPLATE (member)), + DECL_TI_ARGS (member), + tf_warning_or_error, member, /*function_p=*/false, + /*integral_constant_expression_p=*/false)); + + init = digest_nsdmi_init (member, init); + } + else + { + init = DECL_INITIAL (member); + if (init && TREE_CODE (init) == DEFAULT_ARG) + { + error ("constructor required before non-static data member " + "for %qD has been parsed", member); + DECL_INITIAL (member) = error_mark_node; + init = NULL_TREE; + } + /* Strip redundant TARGET_EXPR so we don't need to remap it, and + so the aggregate init code below will see a CONSTRUCTOR. */ + if (init && TREE_CODE (init) == TARGET_EXPR + && !VOID_TYPE_P (TREE_TYPE (TARGET_EXPR_INITIAL (init)))) + init = TARGET_EXPR_INITIAL (init); + init = break_out_target_exprs (init); + } + current_class_ptr = save_ccp; + current_class_ref = save_ccr; + return init; +} + /* Initialize MEMBER, a FIELD_DECL, with INIT, a TREE_LIST of arguments. If TREE_LIST is void_type_node, an empty initializer list was given; if NULL_TREE no initializer was given. */ @@ -535,31 +578,7 @@ /* Use the non-static data member initializer if there was no mem-initializer for this field. */ if (init == NULL_TREE) - { - if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member)) - /* Do deferred instantiation of the NSDMI. */ - init = (tsubst_copy_and_build - (DECL_INITIAL (DECL_TI_TEMPLATE (member)), - DECL_TI_ARGS (member), - tf_warning_or_error, member, /*function_p=*/false, - /*integral_constant_expression_p=*/false)); - else - { - init = DECL_INITIAL (member); - if (init && TREE_CODE (init) == DEFAULT_ARG) - { - error ("constructor required before non-static data member " - "for %qD has been parsed", member); - init = NULL_TREE; - } - /* Strip redundant TARGET_EXPR so we don't need to remap it, and - so the aggregate init code below will see a CONSTRUCTOR. */ - if (init && TREE_CODE (init) == TARGET_EXPR - && !VOID_TYPE_P (TREE_TYPE (TARGET_EXPR_INITIAL (init)))) - init = TARGET_EXPR_INITIAL (init); - init = break_out_target_exprs (init); - } - } + init = get_nsdmi (member, /*ctor*/true); if (init == error_mark_node) return; Index: gcc/cp/typeck2.c =================================================================== --- gcc/cp/typeck2.c (revision 212206) +++ gcc/cp/typeck2.c (revision 212207) @@ -1097,6 +1097,22 @@ { return digest_init_r (type, init, false, flags, tf_warning_or_error); } + +/* Process the initializer INIT for an NSDMI DECL (a FIELD_DECL). */ +tree +digest_nsdmi_init (tree decl, tree init) +{ + gcc_assert (TREE_CODE (decl) == FIELD_DECL); + + int flags = LOOKUP_IMPLICIT; + if (DIRECT_LIST_INIT_P (init)) + flags = LOOKUP_NORMAL; + init = digest_init_flags (TREE_TYPE (decl), init, flags); + if (TREE_CODE (init) == TARGET_EXPR) + /* This represents the whole initialization. */ + TARGET_EXPR_DIRECT_INIT_P (init) = true; + return init; +} /* Set of flags used within process_init_constructor to describe the initializers. */ Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 212206) +++ gcc/cp/parser.c (revision 212207) @@ -17852,7 +17852,7 @@ /* Used by handling of trailing-return-types and NSDMI, in which 'this' is in scope even though it isn't real. */ -static void +void inject_this_parameter (tree ctype, cp_cv_quals quals) { tree this_parm; @@ -23686,16 +23686,7 @@ parsed_arg = check_default_argument (parmtype, parsed_arg, tf_warning_or_error); else - { - int flags = LOOKUP_IMPLICIT; - if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg) - && CONSTRUCTOR_IS_DIRECT_INIT (parsed_arg)) - flags = LOOKUP_NORMAL; - parsed_arg = digest_init_flags (TREE_TYPE (decl), parsed_arg, flags); - if (TREE_CODE (parsed_arg) == TARGET_EXPR) - /* This represents the whole initialization. */ - TARGET_EXPR_DIRECT_INIT_P (parsed_arg) = true; - } + parsed_arg = digest_nsdmi_init (decl, parsed_arg); } /* If the token stream has not been completely used up, then Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 212206) +++ gcc/cp/cp-tree.h (revision 212207) @@ -3436,6 +3436,9 @@ B b{1,2}, not B b({1,2}) or B b = {1,2}. */ #define CONSTRUCTOR_IS_DIRECT_INIT(NODE) (TREE_LANG_FLAG_0 (CONSTRUCTOR_CHECK (NODE))) +#define DIRECT_LIST_INIT_P(NODE) \ + (BRACE_ENCLOSED_INITIALIZER_P (NODE) && CONSTRUCTOR_IS_DIRECT_INIT (NODE)) + /* True if NODE represents a conversion for direct-initialization in a template. Set by perform_implicit_conversion_flags. */ #define IMPLICIT_CONV_EXPR_DIRECT_INIT(NODE) \ @@ -4353,6 +4356,11 @@ PARM_DECLs in cp_tree_equal. */ extern int comparing_specializations; +/* A type-qualifier, or bitmask therefore, using the TYPE_QUAL + constants. */ + +typedef int cp_cv_quals; + /* In parser.c. */ /* Nonzero if we are parsing an unevaluated operand: an operand to @@ -4362,6 +4370,7 @@ extern int cp_unevaluated_operand; extern tree cp_convert_range_for (tree, tree, tree, bool); extern bool parsing_nsdmi (void); +extern void inject_this_parameter (tree, cp_cv_quals); /* in pt.c */ @@ -4741,11 +4750,6 @@ extern GTY(()) operator_name_info_t assignment_operator_name_info [(int) MAX_TREE_CODES]; -/* A type-qualifier, or bitmask therefore, using the TYPE_QUAL - constants. */ - -typedef int cp_cv_quals; - /* Non-static member functions have an optional virt-specifier-seq. There is a VIRT_SPEC value for each virt-specifier. They can be combined by bitwise-or to form the complete set of @@ -5421,6 +5425,7 @@ extern tree build_zero_init (tree, tree, bool); extern tree build_value_init (tree, tsubst_flags_t); extern tree build_value_init_noctor (tree, tsubst_flags_t); +extern tree get_nsdmi (tree, bool); extern tree build_offset_ref (tree, tree, bool, tsubst_flags_t); extern tree throw_bad_array_new_length (void); @@ -6157,6 +6162,7 @@ extern void check_narrowing (tree, tree); extern tree digest_init (tree, tree, tsubst_flags_t); extern tree digest_init_flags (tree, tree, int); +extern tree digest_nsdmi_init (tree, tree); extern tree build_scoped_ref (tree, tree, tree *); extern tree build_x_arrow (location_t, tree, tsubst_flags_t);