From patchwork Thu Sep 5 13:03:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1981260 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HaJOEBzB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X001f6x7qz1yXY for ; Thu, 5 Sep 2024 23:04:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C5A42386480F for ; Thu, 5 Sep 2024 13:04:17 +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.129.124]) by sourceware.org (Postfix) with ESMTP id 85E8B385843B for ; Thu, 5 Sep 2024 13:03:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85E8B385843B 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 85E8B385843B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725541437; cv=none; b=cfaqErC8XpsmJnKYS3kbMzz7sBzqLzqrI8VogWSpHl98UQTYrAxDifyqd6hfTVLuDsL/1PvwuNKkWcaUsW1tnVEGHBeN6vSpdfcuCFE28otSj4AyTuMzCvJWlpATqpHw6yCGtR7sbsxRYiVhT7YF9OLvJjCLexlLq4k1FchVQa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725541437; c=relaxed/simple; bh=YASllCXqnOA9zKpE1uc/w38HozFm3kllT7GasgD9arM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=IPgh7UoEbcKgevDyNdNY/UKJ4tR37Cv456Kra7Tfyta9IEB87nXibywICNPeSM2A0exZN0jolb5BE4/bU7ikbEg+kDFUbV9t70+GYnLNo7w3ndZ68h9BsDsiQP8T1Ho4Ja82GG37wm6PIuqNz/zw/6TJj1UU7PjeLz7ox69LPCs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725541434; 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=LvIyBZVBfi00ZOpZ6kwPWqABVMFv2mf5Yn+A6WZk3rg=; b=HaJOEBzBeVQ/xvNUHGljQUUy/ih2UDvQzylGwt5+wTHBJYs0J9DhVGXxSLcWEyT2GJe3gh 4N3FUOKi1rDzebvGEh2M8xitq2VUsBDglXF16SHDl7wU8B7oEO/2yV9cyqapqdRkT2vKBI 7hQ+pznM80reYb1w2L1SJnhAKSONBic= Received: from mx-prod-mc-01.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-5-1p_mFDmCMVqyW9PhWeW91w-1; Thu, 05 Sep 2024 09:03:51 -0400 X-MC-Unique: 1p_mFDmCMVqyW9PhWeW91w-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB5C8193E8CD for ; Thu, 5 Sep 2024 13:03:47 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.29]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 557E01955F44; Thu, 5 Sep 2024 13:03:47 +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 485D3iNE1865143 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 5 Sep 2024 15:03:44 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 485D3ib81865142; Thu, 5 Sep 2024 15:03:44 +0200 Date: Thu, 5 Sep 2024 15:03:44 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [RFC PATCH] c++: Add alignas further test coverage [PR110345] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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_H3, 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! I've tried to do the same thing I did for normal standard attributes also for alignas, but there are way too many cases which are silently accepted although my reading of: "An alignment-specifier may be applied to a variable or to a class data member, but it shall not be applied to a bit-field, a function parameter, or an exception-declaration ([except.handle]). An alignment-specifier may also be applied to the declaration of a class (in an elaborated-type-specifier ([dcl.type.elab]) or class-head ([class]), respectively)." I've marked the spots where I'd expect some pedwarn with // FIXME. Clearly we accept it e.g. on bit-fields, exception-declarations, enum declarations, functions, to e.g. array/reference etc. types, ... Is some of this intentional? Though, trying clang trunk, it diagnoses all the // FIXME lines. 2024-09-05 Jakub Jelinek PR c++/110345 * g++.dg/cpp0x/alignas21.C: New test. Jakub --- gcc/testsuite/g++.dg/cpp0x/alignas21.C.jj 2024-09-05 14:16:44.366395041 +0200 +++ gcc/testsuite/g++.dg/cpp0x/alignas21.C 2024-09-05 14:42:42.690465771 +0200 @@ -0,0 +1,156 @@ +// 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) +{ + alignas (int) int x1; + alignas ("foobar") int x2; // { dg-error "'alignas' argument has non-integral type 'const char \\\[7\\\]'" } + alignas (0) int x3; // { dg-warning "requested alignment '0' is not a positive power of 2" } + alignas ("foo", "bar", "baz") int x4; // { dg-error "'alignas' argument has non-integral type 'const char \\\[4\\\]'" } + // { dg-error "expected '\\\)' before ',' token" "" { target *-*-* } .-1 } + // { dg-error "expected declaration before ',' token" "" { target *-*-* } .-2 } + // { dg-error "expected primary-expression before ',' token" "" { target *-*-* } .-3 } + alignas (0, 1, 2) int x5; // { dg-error "expected '\\\)' before ',' token" } + // { dg-error "expected declaration before ',' token" "" { target *-*-* } .-1 } + // { dg-error "expected primary-expression before ',' token" "" { target *-*-* } .-2 } + + auto a = [] alignas (int) () {}; // FIXME + auto b = [] constexpr alignas (int) {}; // FIXME + // { 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 alignas (int) {}; // FIXME + // { dg-error "parameter declaration before lambda exception specification only optional with" "" { target c++20_down } .-1 } + auto d = [] () alignas (int) {}; // FIXME + auto e = new int [n] alignas (int); // { dg-warning "attributes ignored on outermost array type in new expression" } + auto e2 = new int [n] alignas (int) [42]; // { dg-warning "attributes ignored on outermost array type in new expression" } + auto f = new int [n][42] alignas (int); // FIXME + alignas (int); // { dg-warning "attributes at the beginning of statement are ignored" } + alignas (int) {} // { dg-warning "attributes at the beginning of statement are ignored" } + alignas (int) if (true) {} // { dg-warning "attributes at the beginning of statement are ignored" } + alignas (int) while (false) {} // { dg-warning "attributes at the beginning of statement are ignored" } + alignas (int) goto lab; // { dg-warning "attributes at the beginning of statement are ignored" } + alignas (int) lab:; // { dg-error "alignment may not be specified for 'lab'" } + alignas (int) try {} catch (int) {} // { dg-warning "attributes at the beginning of statement are ignored" } + if (alignas (int) int x = 0) {} + switch (n) + { + alignas (int) case 1: // { dg-error "alignment may not be specified for" } + alignas (int) break; // { dg-warning "attributes at the beginning of statement are ignored" } + alignas (int) default: // { dg-error "alignment may not be specified for" } + break; + } + for (alignas (int) auto a : arr) {} + for (alignas (int) auto [a, b] : arr2) {} // { dg-error "structured bindings only available with" "" { target c++14_down } } + alignas (int) asm (""); // { dg-warning "attributes ignored on 'asm' declaration" } + try {} catch (alignas (int) int x) {} // FIXME + try {} catch (alignas (int) int) {} // FIXME + try {} catch (int alignas (int) x) {} // { dg-warning "attribute ignored" } + try {} catch (int alignas (int)) {} // { dg-warning "attribute ignored" } + try {} catch (int x alignas (int)) {} // FIXME +} + +alignas (int) int bar (); // FIXME +using foobar alignas (int) = int; // FIXME +alignas (int) int a; +alignas (int) auto [b, c] = arr; // { dg-error "structured bindings only available with" "" { target c++14_down } } +alignas (int); // { dg-warning "attribute ignored" } +inline alignas (int) void baz () {} // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +constexpr alignas (int) int qux () { return 0; } // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +int alignas (int) d; // { dg-warning "attribute ignored" } +int const alignas (int) e = 1; // { dg-warning "attribute ignored" } +struct A {} alignas (int); // { dg-warning "attribute ignored in declaration of 'struct A'" } +struct A alignas (int); // { dg-warning "attribute ignored" } +struct A alignas (int) a1; // { dg-warning "attribute ignored" } +A alignas (int) a2; // { dg-warning "attribute ignored" } +enum B { B0 } alignas (int); // { dg-warning "attribute ignored in declaration of 'enum B'" } +enum B alignas (int); // { dg-warning "attribute ignored" } +enum B alignas (int) b1; // { dg-warning "attribute ignored" } +B alignas (int) b2; // { dg-warning "attribute ignored" } +struct alignas (int) C {}; +int f alignas (int); +int g[2] alignas (int); // FIXME +int g2 alignas (int) [2]; +int corge () alignas (int); // FIXME +int *alignas (int) h; // FIXME +int & alignas (int) i = f; // FIXME +int && alignas (int) j = 0; // FIXME +int S::* alignas (int) k; // FIXME +auto l = sizeof (int [2] alignas (int)); // FIXME +int freddy (alignas (int) int a, // { dg-error "alignment may not be specified for 'a'" } + alignas (int) int, // { dg-error "alignment may not be specified for ''" } + alignas (int) int c = 0, // { dg-error "alignment may not be specified for 'c'" } + alignas (int) int = 0); // { dg-error "alignment may not be specified for ''" } +void +corge (alignas (int) int a, // { dg-error "alignment may not be specified for 'a'" } + alignas (int) int, // { dg-error "alignment may not be specified for ''" } + alignas (int) int c = 0, // { dg-error "alignment may not be specified for 'c'" } + alignas (int) int = 0) // { dg-error "alignment may not be specified for ''" } +{ +} +alignas (int) void // FIXME +garply () +{ +} +int grault (int alignas (int) a, // { dg-warning "attribute ignored" } + int alignas (int), // { dg-warning "attribute ignored" } + int alignas (int) c = 0, // { dg-warning "attribute ignored" } + int alignas (int) = 0); // { dg-warning "attribute ignored" } +void +waldo (int alignas (int) a, // { dg-warning "attribute ignored" } + int alignas (int), // { dg-warning "attribute ignored" } + int alignas (int) c = 0, // { dg-warning "attribute ignored" } + int alignas (int) = 0) // { dg-warning "attribute ignored" } +{ +} +int plugh (int a alignas (int), // { dg-error "alignment may not be specified for 'a'" } + int b alignas (int) = 0); // { dg-error "alignment may not be specified for 'b'" } +void +thud (int a alignas (int), // { dg-error "alignment may not be specified for 'a'" } + int b alignas (int) = 0) // { dg-error "alignment may not be specified for 'b'" } +{ +} +enum alignas (int) D { D0 }; // FIXME +enum class alignas (int) E { E0 }; // FIXME +enum F {}; +enum alignas (int) F; // { dg-warning "type attributes ignored after type is already defined" } +enum G { + G0 alignas (int), // { dg-error "alignment may not be specified for 'G0'" } + G1 alignas (int) = 2 // { dg-error "alignment may not be specified for 'G1'" } +}; +namespace alignas (int) H { using H0 = int; } // { dg-error "expected identifier before 'alignas'" } + // { dg-error "H' does not name a type" "" { target *-*-* } .-1 } +namespace alignas (int) {} // { dg-error "expected identifier before 'alignas'" } + // { dg-error "expected unqualified-id before '\\\{' token" "" { target *-*-* } .-1 } +alignas (int) using namespace H; + // { dg-error "'H' is not a namespace-name" "" { target *-*-* } .-1 } +struct alignas (int) I +{ + alignas (int); // { dg-error "declaration does not declare anything" } + alignas (int) int i; + alignas (int) int foo (); // FIXME + alignas (int) int bar () { return 1; } // FIXME + alignas (int) int : 0; // FIXME + alignas (int) int i2 : 5; // FIXME + alignas (int) static int i3; + static int i4; +}; +alignas (int) int I::i4 = 0; +struct J : alignas (int) C {}; // { dg-warning "attributes on base specifiers are ignored" } +#if __cpp_concepts >= 201907L +template +concept K alignas (int) = requires { true; }; // { dg-error "alignment may not be specified for 'K'" "" { target c++20 } } +#endif +typedef int L alignas (int); +template +struct M {}; +template <> +struct alignas (int) M { int m; }; +typedef int N[2] alignas (int); // FIXME +typedef int O alignas (int) [2]; // FIXME