From patchwork Thu Sep 5 07:19:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 97123 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE4A6386549A for ; Thu, 5 Sep 2024 07:20:11 +0000 (GMT) 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 ESMTP id 737CC386481F for ; Thu, 5 Sep 2024 07:19:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 737CC386481F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 737CC386481F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725520777; cv=none; b=W9DVu0GqEfVRlyoPpXXJfm92uRQPwufL59aYG5v9AKwK6qTy0ErhnO9bRB6Bnx3JQBeWbGwfskMQwuWUHr+X5mANVJbQTf8xlirTjX71cZjyIHVrQ1e70UT32fHjZiXGsw3ewCDvU4E+xP7nPvJyHvtbrFYoofkrhdXIwMuwd7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725520777; c=relaxed/simple; bh=e/RD/ll12UjFhmPqAfSF4qV8BC0abpADKYCUXHTvqBw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=V7e+d+V1Ew1iwzzwiQA+A4OwLFyeSC8wDOxze0mmv6x1ewmL2t5Nbs2s3kc7TxGp09vLtjROuwjcDKSYbFbVl5dIdugNgItVdZdCdS8hWVSayGVcoKKEE1CN2RZzQSYXv5Z68uNSrIVBl9THD0LCianBl4LsTzGKNa7l/vhyb1o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725520775; 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; bh=96juKJ5hGqJWeyaxiS3tTkP1gU4d2eCKLYCLaeeGbiw=; b=DzlQqAp35HicC8Qdphy6C1oa6fpCjv2+LD3lA+JnwxLvt+KXN67cZPqZqvn6Foc8hA3AFd 6jNYrGHfbjtmzv0UDFrUd+2GOz5veOQKhY5b/m+9AGeSa/CEXXwIc9uoZVxXlSf6r47MsP 2d66pUq7EMKxqKk9bmPbNi7P0FTP1Hc= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-438-R0S3ffz-OxWmHyexboeA4w-1; Thu, 05 Sep 2024 03:19:33 -0400 X-MC-Unique: R0S3ffz-OxWmHyexboeA4w-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 62E1F19560BC for ; Thu, 5 Sep 2024 07:19:26 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.29]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F18231956048; Thu, 5 Sep 2024 07:19:24 +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 4857JMhk1837183 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 5 Sep 2024 09:19:22 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4857JMaR1837182; Thu, 5 Sep 2024 09:19:22 +0200 Date: Thu, 5 Sep 2024 09:19:22 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Add fallthrough attribute further test coverage [PR110345] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-0.9 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Hi! Similarly for fallthrough attribute. Had to add a second testcase because the diagnostics for fallthrough not used within switch at all is done during expansion and expansion won't happen if there are other errors in the testcase. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-09-05 Jakub Jelinek PR c++/110345 * g++.dg/cpp0x/attr-fallthrough1.C: New test. * g++.dg/cpp0x/attr-fallthrough2.C: New test. Jakub --- gcc/testsuite/g++.dg/cpp0x/attr-fallthrough1.C.jj 2024-09-04 16:27:52.786654084 +0200 +++ gcc/testsuite/g++.dg/cpp0x/attr-fallthrough1.C 2024-09-04 16:44:41.879666097 +0200 @@ -0,0 +1,169 @@ +// C++ 26 P2552R3 - On the ignorability of standard attributes +// { dg-do compile { target c++11 } } + +int arr[2]; +struct S { int a, b; }; +S arr2[2]; + +void +foo (int n) +{ + switch (n) + { + case 1: + [[fallthrough (n > 0)]]; // { dg-error "'fallthrough' attribute does not take any arguments" } + case 2: + break; + case 3: + [[fallthrough]]; + case 4: + break; + case 5: + [[fallthrough ("abc")]]; // { dg-error "'fallthrough' attribute does not take any arguments" } + case 6: + break; + case 7: + [[fallthrough (1, 2, 3)]]; // { dg-error "'fallthrough' attribute does not take any arguments" } + case 8: + [[fallthrough]]; // { dg-error "attribute 'fallthrough' not preceding a case label or default label" } + foo (n - 1); + break; + default: + break; + } + + [[fallthrough]] int x1; // { dg-error "'fallthrough' attribute ignored" } + + auto a = [] [[fallthrough]] () {}; // { dg-error "'fallthrough' attribute ignored" } + auto b = [] constexpr [[fallthrough]] {}; // { dg-error "'fallthrough' attribute ignored" } + // { dg-error "parameter declaration before lambda declaration specifiers only optional with" "" { target c++20_down } .-1 } + // { dg-error "'constexpr' lambda only available with" "" { target c++14_down } .-2 } + auto c = [] noexcept [[fallthrough]] {}; // { dg-error "'fallthrough' attribute ignored" } + // { dg-error "parameter declaration before lambda exception specification only optional with" "" { target c++20_down } .-1 } + auto d = [] () [[fallthrough]] {}; // { dg-error "'fallthrough' attribute ignored" } + auto e = new int [n] [[fallthrough]]; // { dg-warning "attributes ignored on outermost array type in new expression" } + auto e2 = new int [n] [[fallthrough]] [42]; // { dg-warning "attributes ignored on outermost array type in new expression" } + auto f = new int [n][42] [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] {} // { dg-warning "attributes at the beginning of statement are ignored" } + [[fallthrough]] if (true) {} // { dg-warning "attributes at the beginning of statement are ignored" } + [[fallthrough]] while (false) {} // { dg-warning "attributes at the beginning of statement are ignored" } + [[fallthrough]] goto lab; // { dg-warning "attributes at the beginning of statement are ignored" } + [[fallthrough]] lab:; // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] try {} catch (int) {} // { dg-warning "attributes at the beginning of statement are ignored" } + if ([[fallthrough]] int x = 0) {} // { dg-error "'fallthrough' attribute ignored" } + switch (n) + { + [[fallthrough]] case 1: // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] break; // { dg-warning "attributes at the beginning of statement are ignored" } + [[fallthrough]] default: // { dg-error "'fallthrough' attribute ignored" } + break; + } + for ([[fallthrough]] auto a : arr) {} // { dg-error "'fallthrough' attribute ignored" } + for ([[fallthrough]] auto [a, b] : arr2) {} // { dg-error "'fallthrough' attribute ignored" } + // { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } + [[fallthrough]] asm (""); // { dg-warning "attributes ignored on 'asm' declaration" } + try {} catch ([[fallthrough]] int x) {} // { dg-error "'fallthrough' attribute ignored" } + try {} catch ([[fallthrough]] int) {} // { dg-error "'fallthrough' attribute ignored" } + try {} catch (int [[fallthrough]] x) {} // { dg-warning "attribute ignored" } + try {} catch (int [[fallthrough]]) {} // { dg-warning "attribute ignored" } + try {} catch (int x [[fallthrough]]) {} // { dg-error "'fallthrough' attribute ignored" } +} + +[[fallthrough]] int bar (); // { dg-error "'fallthrough' attribute ignored" } +using foobar [[fallthrough]] = int; // { dg-error "'fallthrough' attribute ignored" } +[[fallthrough]] int a; // { dg-error "'fallthrough' attribute ignored" } +[[fallthrough]] auto [b, c] = arr; // { dg-error "'fallthrough' attribute ignored" } + // { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } +[[fallthrough]]; // { dg-warning "attribute ignored" } +inline [[fallthrough]] void baz () {} // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +constexpr [[fallthrough]] int qux () { return 0; } // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +int [[fallthrough]] d; // { dg-warning "attribute ignored" } +int const [[fallthrough]] e = 1; // { dg-warning "attribute ignored" } +struct A {} [[fallthrough]]; // { dg-warning "attribute ignored in declaration of 'struct A'" } +struct A [[fallthrough]]; // { dg-warning "attribute ignored" } +struct A [[fallthrough]] a1; // { dg-warning "attribute ignored" } +A [[fallthrough]] a2; // { dg-warning "attribute ignored" } +enum B { B0 } [[fallthrough]]; // { dg-warning "attribute ignored in declaration of 'enum B'" } +enum B [[fallthrough]]; // { dg-warning "attribute ignored" } +enum B [[fallthrough]] b1; // { dg-warning "attribute ignored" } +B [[fallthrough]] b2; // { dg-warning "attribute ignored" } +struct [[fallthrough]] C {}; // { dg-error "'fallthrough' attribute ignored" } +int f [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } +int g[2] [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } +int g2 [[fallthrough]] [2]; // { dg-error "'fallthrough' attribute ignored" } +int corge () [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } +int *[[fallthrough]] h; // { dg-error "'fallthrough' attribute ignored" } +int & [[fallthrough]] i = f; // { dg-error "'fallthrough' attribute ignored" } +int && [[fallthrough]] j = 0; // { dg-error "'fallthrough' attribute ignored" } +int S::* [[fallthrough]] k; // { dg-error "'fallthrough' attribute ignored" } +auto l = sizeof (int [2] [[fallthrough]]); // { dg-error "'fallthrough' attribute ignored" } +int freddy ([[fallthrough]] int a, // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int, // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int c = 0, // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int = 0); // { dg-error "'fallthrough' attribute ignored" } +void +corge ([[fallthrough]] int a, // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int, // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int c = 0, // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int = 0) // { dg-error "'fallthrough' attribute ignored" } +{ +} +[[fallthrough]] void +garply () // { dg-error "'fallthrough' attribute ignored" } +{ +} +int grault (int [[fallthrough]] a, // { dg-warning "attribute ignored" } + int [[fallthrough]], // { dg-warning "attribute ignored" } + int [[fallthrough]] c = 0, // { dg-warning "attribute ignored" } + int [[fallthrough]] = 0); // { dg-warning "attribute ignored" } +void +waldo (int [[fallthrough]] a, // { dg-warning "attribute ignored" } + int [[fallthrough]], // { dg-warning "attribute ignored" } + int [[fallthrough]] c = 0, // { dg-warning "attribute ignored" } + int [[fallthrough]] = 0) // { dg-warning "attribute ignored" } +{ +} +int plugh (int a [[fallthrough]], // { dg-error "'fallthrough' attribute ignored" } + int b [[fallthrough]] = 0); // { dg-error "'fallthrough' attribute ignored" } +void +thud (int a [[fallthrough]], // { dg-error "'fallthrough' attribute ignored" } + int b [[fallthrough]] = 0) // { dg-error "'fallthrough' attribute ignored" } +{ +} +enum [[fallthrough]] D { D0 }; // { dg-error "'fallthrough' attribute ignored" } +enum class [[fallthrough]] E { E0 }; // { dg-error "'fallthrough' attribute ignored" } +enum F {}; +enum [[fallthrough]] F; // { dg-warning "type attributes ignored after type is already defined" } +enum G { + G0 [[fallthrough]], // { dg-error "'fallthrough' attribute ignored" } + G1 [[fallthrough]] = 2 // { dg-error "'fallthrough' attribute ignored" } +}; +namespace [[fallthrough]] H { using H0 = int; } // { dg-warning "'fallthrough' attribute directive ignored" } */ +namespace [[fallthrough]] {} // { dg-warning "'fallthrough' attribute directive ignored" } +[[fallthrough]] using namespace H; // { dg-warning "'fallthrough' attribute directive ignored" } +struct [[fallthrough]] I // { dg-error "'fallthrough' attribute ignored" } +{ + [[fallthrough]]; // { dg-error "declaration does not declare anything" } + [[fallthrough]] int i; // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int foo (); // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int bar () { return 1; } // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int : 0; // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] int i2 : 5; // { dg-error "'fallthrough' attribute ignored" } + [[fallthrough]] static int i3; // { dg-error "'fallthrough' attribute ignored" } + static int i4; +}; +[[fallthrough]] int I::i4 = 0; // { dg-error "'fallthrough' attribute ignored" } +struct J : [[fallthrough]] C {}; // { dg-warning "attributes on base specifiers are ignored" } +#if __cpp_concepts >= 201907L +template +concept K [[fallthrough]] = requires { true; }; // { dg-error "'fallthrough' attribute ignored" "" { target c++20 } } +#endif +typedef int L [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } +template +struct M {}; +template <> +struct [[fallthrough]] M { int m; }; // { dg-error "'fallthrough' attribute ignored" } +typedef int N[2] [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } +typedef int O [[fallthrough]] [2]; // { dg-error "'fallthrough' attribute ignored" } --- gcc/testsuite/g++.dg/cpp0x/attr-fallthrough2.C.jj 2024-09-04 16:46:49.540022110 +0200 +++ gcc/testsuite/g++.dg/cpp0x/attr-fallthrough2.C 2024-09-04 16:46:45.707071471 +0200 @@ -0,0 +1,10 @@ +// C++ 26 P2552R3 - On the ignorability of standard attributes +// { dg-do compile { target c++11 } } + +void +foo () +{ + [[fallthrough]]; // { dg-error "invalid use of attribute 'fallthrough'" } +lab:; + goto lab; +}