From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9057 invoked by alias); 7 Jan 2019 19:09:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 8964 invoked by uid 89); 7 Jan 2019 19:09:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*Ad:U*jason, HTo:U*jason X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Jan 2019 19:09:33 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E3EA61D07 for ; Mon, 7 Jan 2019 19:09:32 +0000 (UTC) Received: from redhat.com (unknown [10.20.4.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BC135D75D; Mon, 7 Jan 2019 19:09:32 +0000 (UTC) Date: Mon, 07 Jan 2019 19:09:00 -0000 From: Marek Polacek To: GCC Patches , Jason Merrill , David Malcolm Subject: C++ PATCH for c++/88741 - wrong error with initializer-string Message-ID: <20190107190930.GD28316@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2019-01/txt/msg00332.txt.bz2 This fixes c++/88741, a bogus error with using [] in a template. Starting with the "more location wrapper nodes" patch, cp_complete_array_type can now receive a V_C_E in a CONSTRUCTOR, instead of just {"test"}, so we need to strip any location wrappers as elsewhere for this code to work. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-01-07 Marek Polacek PR c++/88741 - wrong error with initializer-string. * decl.c (cp_complete_array_type): Strip any location wrappers. * g++.dg/init/array50.C: New test. diff --git gcc/cp/decl.c gcc/cp/decl.c index 15bc4887a59..1fc7a1acf56 100644 --- gcc/cp/decl.c +++ gcc/cp/decl.c @@ -8433,6 +8433,7 @@ cp_complete_array_type (tree *ptype, tree initial_value, bool do_default) { vec *v = CONSTRUCTOR_ELTS (initial_value); tree value = (*v)[0].value; + STRIP_ANY_LOCATION_WRAPPER (value); if (TREE_CODE (value) == STRING_CST && v->length () == 1) diff --git gcc/testsuite/g++.dg/init/array50.C gcc/testsuite/g++.dg/init/array50.C new file mode 100644 index 00000000000..a5c129d0eb5 --- /dev/null +++ gcc/testsuite/g++.dg/init/array50.C @@ -0,0 +1,12 @@ +// PR c++/88741 + +template +void foo() +{ + char row[] = {"test"}; +} + +void bar() +{ + foo(); +}