From patchwork Fri Nov 16 09:00:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 998797 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-490227-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KVYGyP/2"; dkim-atps=neutral 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 42xBzR6J9Wz9sBQ for ; Fri, 16 Nov 2018 20:01:06 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=nQIYOAPC2+3OPw61Fl8d93+JTWddX 8p5WRmes1APEllOTs/G2BcCyoRKVGwF9R0Rm5oCo0Yf/ExrJDXfNI1Ba3Wn7mZ+C BkXDLHE5e815eO+8N993jqykSeLR4DnsYzQl34TW6DSVPgwtHR4ZqD2oKapLkJbh UxL7G73wfhG7uo= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=3k91hf/Mwy+i+009YGpZob8ba9U=; b=KVY GyP/2QV85iV7Tw1R79c9SxLTJo1wyNw2+0GghVgP0pH49xly26UCD9rtjV0QlrKl NHPAJm+mTqYWGPH8/yb9DYUfJtTqMfYthvIOHWI6Jc67TwwG5Mi/joe3tKBHR2MY BfLoNQZ8s1QdhhLfpclaetXvkQdCUYjitUpXi+tI= Received: (qmail 59903 invoked by alias); 16 Nov 2018 09:00:58 -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 59797 invoked by uid 89); 16 Nov 2018 09:00:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2833 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; Fri, 16 Nov 2018 09:00:42 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 800013164693; Fri, 16 Nov 2018 09:00:36 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F389727064; Fri, 16 Nov 2018 09:00:35 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id wAG90Ulg009568; Fri, 16 Nov 2018 10:00:30 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id wAG90Top009567; Fri, 16 Nov 2018 10:00:29 +0100 Date: Fri, 16 Nov 2018 10:00:29 +0100 From: Jakub Jelinek To: Jason Merrill , Nathan Sidwell Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Don't incorrectly reject {un, }signed char constexpr array initialization in templates (PR c++/87476) Message-ID: <20181116090029.GG11625@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! The following two testcases, one is a regression from GCC 8 (introduced by the constructor to STRING_CST optimization), the other seems to fail since C++11 support has been introduced (but is accepted by clang++) fail, because during parsing with processing_template_decl we end up with creating a STRING_CST with type of {un,}signed char array and later during instantiation digest_init_r rejects it, because it already has such a type rather than what it expects (char array) and bogusly complains that it is a wide string. The following patch fixes that. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-11-16 Jakub Jelinek PR c++/87476 * typeck2.c (digest_init_r): Re-add handing of signed/unsigned char strings and add it to the initialization of wide array from non-wide string diagnostics too. * g++.dg/cpp0x/pr87476-1.C: New test. * g++.dg/cpp0x/pr87476-2.C: New test. Jakub --- gcc/cp/typeck2.c.jj 2018-09-25 15:14:43.961258143 +0200 +++ gcc/cp/typeck2.c 2018-11-15 22:04:46.723230224 +0100 @@ -1063,7 +1063,9 @@ digest_init_r (tree type, tree init, int if (TYPE_PRECISION (typ1) == BITS_PER_UNIT) { - if (char_type != char_type_node) + if (char_type != char_type_node + && char_type != signed_char_type_node + && char_type != unsigned_char_type_node) { if (complain & tf_error) error_at (loc, "char-array initialized from wide string"); @@ -1072,7 +1074,9 @@ digest_init_r (tree type, tree init, int } else { - if (char_type == char_type_node) + if (char_type == char_type_node + || char_type == signed_char_type_node + || char_type == unsigned_char_type_node) { if (complain & tf_error) error_at (loc, --- gcc/testsuite/g++.dg/cpp0x/pr87476-1.C.jj 2018-11-15 17:52:13.736758511 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr87476-1.C 2018-11-15 17:42:03.577770280 +0100 @@ -0,0 +1,13 @@ +// PR c++/87476 +// { dg-do compile { target c++11 } } + +template +struct S { + void operator () () { constexpr unsigned char p[1] {}; } +}; + +void +foo () +{ + S<0>{} (); +} --- gcc/testsuite/g++.dg/cpp0x/pr87476-2.C.jj 2018-11-15 22:06:27.615571180 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr87476-2.C 2018-11-15 22:06:36.768420670 +0100 @@ -0,0 +1,23 @@ +// PR c++/87476 +// { dg-do compile { target c++11 } } + +void f0 () { constexpr char p[] = "11111"; } +void f1 () { constexpr unsigned char p[] = "11111"; } +void f2 () { constexpr signed char p[] = "11111"; } +template +void f3 () { constexpr char p[] = "11111"; } +template +void f4 () { constexpr unsigned char p[] = "11111"; } +template +void f5 () { constexpr signed char p[] = "11111"; } + +void +baz () +{ + f0 (); + f1 (); + f2 (); + f3<0> (); + f4<0> (); + f5<0> (); +}