From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 01DB93858D1E for ; Mon, 19 Dec 2022 15:59:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01DB93858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CGWMO+JTBu0bpP10Q2iL3084JsRpMT8UbwtxWHIKQI0=; b=YAuDAKiyRhSUvEWlvYjzDbrV6I94pE+o8RMPWsGS6NbulHmK4u/iuXet8X35X4p3LE+SpW Pca+1OKnIo2ttDndIquakdf0SizoXib35tJr1AKdvhY1X9xM8aqplHHXxRy1VS4mbEIPmB VZgDfELcMJhN7vmX9aPGf/HbyAM9RvI= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-108-if6F0-nZPXeVVheOFYYgYg-1; Mon, 19 Dec 2022 10:59:00 -0500 X-MC-Unique: if6F0-nZPXeVVheOFYYgYg-1 Received: by mail-qk1-f197.google.com with SMTP id s7-20020a05620a0bc700b006fcb1a3bb9dso7494621qki.15 for ; Mon, 19 Dec 2022 07:58:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CGWMO+JTBu0bpP10Q2iL3084JsRpMT8UbwtxWHIKQI0=; b=hXU5Ey/Pqa8HZsF1/zc1P4yuvPG2dyARBQY/TCqUzGY39yTS+ECkcGhMyyI5fr0o9o bNl0xSTQw73drATsme067X45mj2g1GOnDPn7V7tmvm+9DVR0/2weaXQ4GOI7lOfBIv0r bZEKJXGvhySmilVYlroVmOvazTQocQhqdr2bDvKQTrqHdu8b8ktKkHuWJMXcelYoWK46 RvJC4LM/ZxMX8tOFeE9PrDxNLPJJhqa1ofwFLlI/410+1VoAVCeXxIfPouUGstKpA+0j t7sW/neGM10oIQKhFaLOL2h5jRsI5oVUrFjcxnxqV7xybE6GScniUo0wWUsrkOV7gCe8 4yTg== X-Gm-Message-State: AFqh2koKFEQSolnzv03K8y4I0slQnmmCWOSTwyF6uzljuhe1rQF+OZyF peTJV1kC7nNJb5RtfLANLkl5Jf8x4a/VuxYZY4ozUZghRVlgtIe6vLavKnM1flx/fHXSM1Mi6TS 67IFVHxLI3U3o9kdSJQ== X-Received: by 2002:a05:6214:3311:b0:4c7:775c:76dc with SMTP id mo17-20020a056214331100b004c7775c76dcmr12467206qvb.34.1671465539031; Mon, 19 Dec 2022 07:58:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXsJeg76HkNRKjd7XNHIKXN2Kf1jq8Z9q2eiHuOja5azleqCbZZgnd0Bqi6mhYND47wfDf27Bw== X-Received: by 2002:a05:6214:3311:b0:4c7:775c:76dc with SMTP id mo17-20020a056214331100b004c7775c76dcmr12467189qvb.34.1671465538820; Mon, 19 Dec 2022 07:58:58 -0800 (PST) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id dt20-20020a05620a479400b006fbf88667bcsm7134144qkb.77.2022.12.19.07.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 07:58:58 -0800 (PST) Date: Mon, 19 Dec 2022 10:58:56 -0500 From: Marek Polacek To: Jakub Jelinek Cc: "Joseph S. Myers" , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c: Diagnose compound literals with function type [PR108043] Message-ID: References: MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Dec 19, 2022 at 12:05:48PM +0100, Jakub Jelinek wrote: > Hi! > > Both C99 and latest C2X say that compound literal shall have an object type > (complete object type in the latter case) or array of unknown bound, > so complit with function type is invalid. When the initializer had to be > non-empty for such case, we used to diagnose it as incorrect initializer, > but with (fntype){} now allowed we just ICE on it. > > The following patch diagnoses that. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? This looks OK to me, thanks. > 2022-12-19 Jakub Jelinek > > PR c/108043 > * c-parser.cc (c_parser_postfix_expression_after_paren_type): Diagnose > compound literals with function type. > > * gcc.dg/pr108043.c: New test. > * gcc.dg/c99-complit-2.c (foo): Adjust expected diagnostics for > complit with function type. > > --- gcc/c/c-parser.cc.jj 2022-11-18 09:00:44.331323558 +0100 > +++ gcc/c/c-parser.cc 2022-12-16 13:08:51.143083269 +0100 > @@ -10924,6 +10924,11 @@ c_parser_postfix_expression_after_paren_ > error_at (type_loc, "compound literal has variable size"); > type = error_mark_node; > } > + else if (TREE_CODE (type) == FUNCTION_TYPE) > + { > + error_at (type_loc, "compound literal has function type"); > + type = error_mark_node; > + } > if (constexpr_p && type != error_mark_node) > { > tree type_no_array = strip_array_types (type); > --- gcc/testsuite/gcc.dg/pr108043.c.jj 2022-12-16 13:15:40.122083457 +0100 > +++ gcc/testsuite/gcc.dg/pr108043.c 2022-12-16 13:15:20.840366320 +0100 > @@ -0,0 +1,12 @@ > +/* PR c/108043 */ > +/* { dg-do compile } */ > +/* { dg-options "" } */ > + > +typedef void F (void); > + > +void > +foo (void) > +{ > + (F) {}; /* { dg-error "compound literal has function type" } */ > + (F) { foo }; /* { dg-error "compound literal has function type" } */ > +} > --- gcc/testsuite/gcc.dg/c99-complit-2.c.jj 2020-01-12 11:54:37.393398623 +0100 > +++ gcc/testsuite/gcc.dg/c99-complit-2.c 2022-12-19 11:51:45.098467295 +0100 > @@ -23,7 +23,7 @@ foo (int a) > /* { dg-error "init" "incomplete union type" { target *-*-* } .-1 } */ > /* { dg-error "invalid use of undefined type" "" { target *-*-* } .-2 } */ > (void (void)) { 0 }; /* { dg-bogus "warning" "warning in place of error" } */ > - /* { dg-error "init" "function type" { target *-*-* } .-1 } */ > + /* { dg-error "compound literal has function type" "function type" { target *-*-* } .-1 } */ > (int [a]) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */ > /* { dg-error "init|variable" "VLA type" { target *-*-* } .-1 } */ > /* Initializers must not attempt to initialize outside the object > > Jakub > Marek