From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64319 invoked by alias); 29 Nov 2017 22:32:27 -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 64279 invoked by uid 89); 29 Nov 2017 22:32:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=int128, decomposes 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; Wed, 29 Nov 2017 22:32:17 +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 E58CC4A6E6 for ; Wed, 29 Nov 2017 22:32:15 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7898A5D6A3; Wed, 29 Nov 2017 22:32:15 +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 vATMWCof020724; Wed, 29 Nov 2017 23:32:12 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vATMWB4x020723; Wed, 29 Nov 2017 23:32:11 +0100 Date: Wed, 29 Nov 2017 22:35:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix ICE on invalid std::tuple_size<...>::value (PR c++/83205) Message-ID: <20171129223211.GB2353@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02523.txt.bz2 Hi! If tsize doesn't fit into uhwi, then it obviously can't match the number of identifiers in the structured binding declaration. While we could use compare_tree_int and avoid that way this conversion to uhwi (though, compare_tree_int does that anyway), for the normal uhwi case we have special cases in cnt_mismatch shared by the other kinds of structured bindings that handle smaller and larger cases separately, so I think it is better to do it this way. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-11-29 Jakub Jelinek PR c++/83205 * decl.c (cp_finish_decomp): Handle the case when tsize is not error_mark_node, but doesn't fit into uhwi. * g++.dg/cpp1z/decomp32.C: New test. --- gcc/cp/decl.c.jj 2017-11-28 22:23:34.000000000 +0100 +++ gcc/cp/decl.c 2017-11-29 15:00:24.487658715 +0100 @@ -7518,6 +7518,12 @@ cp_finish_decomp (tree decl, tree first, "constant expression", type); goto error_out; } + if (!tree_fits_uhwi_p (tsize)) + { + error_at (loc, "%u names provided while %qT decomposes into " + "%E elements", count, type, tsize); + goto error_out; + } eltscnt = tree_to_uhwi (tsize); if (count != eltscnt) goto cnt_mismatch; --- gcc/testsuite/g++.dg/cpp1z/decomp32.C.jj 2017-11-29 15:08:59.215378903 +0100 +++ gcc/testsuite/g++.dg/cpp1z/decomp32.C 2017-11-29 15:10:31.576244649 +0100 @@ -0,0 +1,24 @@ +// PR c++/83205 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct A { int i; }; +struct B { int i; }; +namespace std { + template struct tuple_size; + template <> struct tuple_size { + static constexpr int value = -1; + }; +#ifdef __SIZEOF_INT128__ + template <> struct tuple_size { + static constexpr unsigned __int128 value = -1; + }; +#endif +} + +auto [a] = A{}; // { dg-error "1 names provided while 'A' decomposes into -1 elements" } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } +#ifdef __SIZEOF_INT128__ +auto [b] = B{}; // { dg-error "1 names provided while 'B' decomposes into \[0-9xa-fXA-F]* elements" "" { target int128 } } + // { dg-warning "structured bindings only available with" "" { target { c++14_down && int128 } } .-1 } +#endif Jakub