From patchwork Tue Dec 10 20:47:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1207281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515648-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="ZsPQnFe9"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="C+NYi9qq"; 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 47XXFt6nSdz9sR0 for ; Wed, 11 Dec 2019 07:48:18 +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:content-transfer-encoding; q=dns; s=default; b=gn/ 35fJvgJclqpqpV7v3CGZUiyn/pHrQZ8x5CZH7e7Q1v0V3/B5UbZLEfhXRWGFHMXO ZKLpQ8sKswjgcDzAhBD5e+GXtHLJlP4stPIMrjcoYxFgleSWzDlz7+cjEig2rj+O +OAAUodCG7laikaUa/lvx2/3CRGHxy+zWI1x21W4= 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:content-transfer-encoding; s=default; bh=+HhC4SQvs WtXpgVdkDyTkr+bMZU=; b=ZsPQnFe9Iiqjs9Q0QTAU47yOY0tVFwetfThXktPUj zFUm3pECg5J0EvmmSA/1OGyqSs/hWFNhc4Hn1fQ3kvjIJUZ386AAWHW30AoQ8/MU Vop5geMEzaGiVuFOBwKNZ0stviKSESVZM1jEfkWgQeEFK/+ox5bUNvriD6sqoOlX 8w= Received: (qmail 124237 invoked by alias); 10 Dec 2019 20:47:27 -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 124161 invoked by uid 89); 10 Dec 2019 20:47:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=inherited X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Dec 2019 20:47:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576010843; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YhVaflyZD7TPPwGT7cwbnTFYyJbQ62N6cz49D46Fli0=; b=C+NYi9qqwgH/+Ztm4mnFpb52/ZLpVkwZoeCdMPua+flTXAxdM20YYyl/Na9hKECQOWBCXX 1X78DAUq6xO5b6KjVla9K7nMkeeYSyWOXR4+SkLa3OgonFAJRFohsQd0JzqCLw2/2F3bBz kgGnoAkN1qypqZz0umqo6jw3qZrWnu8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17-7pe6_rTEP3aF4U4w2n_hZA-1; Tue, 10 Dec 2019 15:47:22 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5C5BB8024D2 for ; Tue, 10 Dec 2019 20:47:21 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06F7570936; Tue, 10 Dec 2019 20:47:20 +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 xBAKlIa8007302; Tue, 10 Dec 2019 21:47:19 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xBAKlH3P007301; Tue, 10 Dec 2019 21:47:17 +0100 Date: Tue, 10 Dec 2019 21:47:17 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix -std=c++17 and earlier handling of CLASSTYPE_NON_AGGREGATE (PR c++/92869) Message-ID: <20191210204717.GF10088@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! In C++20, types with user-declared constructors are not aggregate types, while in C++17 only types with user-provided or explicit constructors. In check_bases_and_members we handle it properly: CLASSTYPE_NON_AGGREGATE (t) |= ((cxx_dialect < cxx2a ? type_has_user_provided_or_explicit_constructor (t) : TYPE_HAS_USER_CONSTRUCTOR (t)) || TYPE_POLYMORPHIC_P (t)); but for templates the code right now behaves the C++20 way regardless of the selected standard. The following patch tweaks finish_struct to match check_bases_and_members. I had to add !CLASSTYPE_NON_AGGREGATE check because type_has_user_provided_or_explicit_constructor -> user_provided_p ICEd on inherited ctors represented as USING_DECLs. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-12-10 Jakub Jelinek PR c++/92869 * class.c (finish_struct): For C++17 and earlier, check type_has_user_provided_or_explicit_constructor rather than TYPE_HAS_USER_CONSTRUCTOR whether to set CLASSTYPE_NON_AGGREGATE. * g++.dg/cpp0x/aggr3.C: New test. Jakub --- gcc/cp/class.c.jj 2019-12-06 00:40:44.525629037 +0100 +++ gcc/cp/class.c 2019-12-10 14:18:41.171380767 +0100 @@ -7456,7 +7456,13 @@ finish_struct (tree t, tree attributes) /* Remember current #pragma pack value. */ TYPE_PRECISION (t) = maximum_field_alignment; - if (TYPE_HAS_USER_CONSTRUCTOR (t)) + if (cxx_dialect < cxx2a) + { + if (!CLASSTYPE_NON_AGGREGATE (t) + && type_has_user_provided_or_explicit_constructor (t)) + CLASSTYPE_NON_AGGREGATE (t) = 1; + } + else if (TYPE_HAS_USER_CONSTRUCTOR (t)) CLASSTYPE_NON_AGGREGATE (t) = 1; /* Fix up any variants we've already built. */ --- gcc/testsuite/g++.dg/cpp0x/aggr3.C.jj 2019-12-10 14:25:22.344231923 +0100 +++ gcc/testsuite/g++.dg/cpp0x/aggr3.C 2019-12-10 14:23:31.700927787 +0100 @@ -0,0 +1,20 @@ +// PR c++/92869 +// { dg-do compile { target c++11 } } + +struct A { + A () = default; + A (const A &) = default; + A (A &&) = default; + int arr[3]; +}; + +template +struct B { + B () = default; + B (const B &) = default; + B (B &&) = default; + T arr[N]; +}; + +A a = { { 1, 2, 3 } }; // { dg-error "could not convert" "" { target c++2a } } +B b = { { 1, 2, 3 } }; // { dg-error "could not convert" "" { target c++2a } }