From patchwork Mon Dec 19 11:05:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 34474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2338928wrn; Mon, 19 Dec 2022 03:50:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXuDL9DhlWDIVjgIiolYkIIZLKxqVPFnA/NLOtyqxZZ3NZUN8+pAS/3j5QLRXfNitUVVKALg X-Received: by 2002:a17:906:1146:b0:7ae:cda1:76d0 with SMTP id i6-20020a170906114600b007aecda176d0mr6643810eja.15.1671450640383; Mon, 19 Dec 2022 03:50:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671450640; cv=none; d=google.com; s=arc-20160816; b=eJ7rXRi7UJSfEhQWkzckgu2sLmuQ2RkBysj2DER4A0c3uXRvKITuMdm4qM8CVoAtyw cA5m5wXsLnQB955YXgm5U1PvdRa+8wYQFQjQ6K26xdWAFlzSg2tMxo2JfuhiYYF2+czn Q4xMX19H0jCcjO2GEn6fVRHsoY+kEd5ypo7GJAbr75gOF5gUIlnjBOIO7nbn8Gg4n/Ya VfHpfKiSUfqxl75Ggc4GJ+bepb+iJUo1WBvnwhERyRhsVQh9JCc2HDsf6bDRGEY86LFH /ZASORMJ5P4Clps+i74xauwERIB8iVMXobITTknk8AgY2VnbZdI68v/cfZpCGL4Yw+1R JgYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oTSh1Blfd2bJjFooin/xQENEqn9au/pIo52DznmK6v4=; b=VqiUjhnZIJESyxExTBMV+lJMHIGzqFPG7M5OU1hEWUEKIXQ55GEDC63zoLBuMDas6R O60DYcY11kiYd85dyqTOEfXj7yH7nIY8wokjwOzrC8Lc/Z7qG8zLERWyyGUIk1KiZsns iZZ2SO7UGwKxj9jdOZYVg6ZdgFO0mJo9lADR+E878YSXDfjMa7HNv0EXorxQJ2Dtnbdx egL2iFfF/iX1XgBXgJyLK1MKvAJDSXGLFhhvlfrYdR1X3zPc9CrThv9Rx6tVdbWCWJhd 3LaTgLSeJqYWyBmD555Jdmnj7lzYZsFr4CAKLiQII3u+zdXOSAgEJxJcPQYOa701ykSS PhTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QTudq8eZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bn6-20020a170906c0c600b007c4f9ce306esi7305215ejb.729.2022.12.19.03.50.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 03:50:40 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QTudq8eZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD704388ED96 for ; Mon, 19 Dec 2022 11:09:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD704388ED96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671448147; bh=oTSh1Blfd2bJjFooin/xQENEqn9au/pIo52DznmK6v4=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=QTudq8eZsTt+HLdYQrI+7OfjNhEqOeWkOBsGncVPq5ntofxWjSi6sy14y1KZtHq/2 KIBOpviBOeDYgOUb5GsoU11As+nzHblZBZbEQeLbhclZ/fjPKGJbVp+PJDVfiH5jr1 rdf2Yy+y7NHfeSI6AJqm+IfQG32z5zbOhtCbeEJs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 7EDDF385B515 for ; Mon, 19 Dec 2022 11:05:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7EDDF385B515 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654--zZ1BkicOhaqbK3nJM7Gwg-1; Mon, 19 Dec 2022 06:05:54 -0500 X-MC-Unique: -zZ1BkicOhaqbK3nJM7Gwg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4A258588E7; Mon, 19 Dec 2022 11:05:53 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79B86492C14; Mon, 19 Dec 2022 11:05:52 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BJB5nd5776695 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 19 Dec 2022 12:05:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BJB5mln776694; Mon, 19 Dec 2022 12:05:48 +0100 Date: Mon, 19 Dec 2022 12:05:48 +0100 To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Diagnose compound literals with function type [PR108043] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752643026588970851?= X-GMAIL-MSGID: =?utf-8?q?1752643026588970851?= 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? 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. Jakub --- 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