From patchwork Fri Sep 6 18:37:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1982039 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=V2LXPqLt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4X0lNN3jczz1y1D for ; Sat, 7 Sep 2024 04:38:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5689E384A41C for ; Fri, 6 Sep 2024 18:38:08 +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 60E6E3858C56 for ; Fri, 6 Sep 2024 18:37:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60E6E3858C56 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 60E6E3858C56 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=1725647863; cv=none; b=AWJwCQKA0wMROrggfyjJnqUZ7DdvwWBmPpr841xH20UBbSuT60YlmJcEGSXekLLas01twLGGWW0WFiUGytJsEOPrAeHZXfDdzmvubA/3XN+ph9fU+gXdsguHj255tJ3MARRelYvKQoDcFRcR+pfzcf8H+bmbtzg2BY8g65AZgec= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725647863; c=relaxed/simple; bh=gFx/sIk2hsMYWQjZ19o6YaX67dppIbIq/0qIQGWgFEQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=sljqouyw2H7Z61X1cmoJcwPBnETDM5FkvEsjta2tzgLW/0co+woyyfuc2/JmfexZmRslWBTgMIYmQWO4IOWZFU9bNgHurn94/TpqbFqzbW7SuFndKLjDfujQXPyqGzAd4Z2eviaTZPnEnjxiHeLhTrGEGvkQdEBIs8iKUF6sv4Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725647858; 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=FMlRdMzXQPHHpIaLAvxDMEDNKvRN7W3Rk/SYTn9LFsY=; b=V2LXPqLtm3QQAEJBwJovII9mSt3WymB55oYr3CUaRyER2eddkIqrgMKRbanfbJHLUK2Bje fEkECHBDnB22+6KbxnaycNHGU9OEyeVqAvNL9hPlbAciLcOzrEphJbVBEbzs2LNweKTgtN swSDJqwmPsQz/8XJEx8ut7yfgklrIMY= 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-321-AHSX9MvXOeuJ5Wn78QwzgQ-1; Fri, 06 Sep 2024 14:37:35 -0400 X-MC-Unique: AHSX9MvXOeuJ5Wn78QwzgQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 07195195608B for ; Fri, 6 Sep 2024 18:37:16 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.29]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9AA0B1956094; Fri, 6 Sep 2024 18:37:14 +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 486IbAbb100134 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 6 Sep 2024 20:37:11 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 486IbAZd100133; Fri, 6 Sep 2024 20:37:10 +0200 Date: Fri, 6 Sep 2024 20:37:10 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix up pedantic handling of alignas [PR110345] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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, KAM_SHORT, 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! The following patch on top of the PR110345 P2552R3 series: https://gcc.gnu.org/pipermail/gcc-patches/2024-August/661904.html https://gcc.gnu.org/pipermail/gcc-patches/2024-August/661905.html https://gcc.gnu.org/pipermail/gcc-patches/2024-August/661906.html https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662330.html https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662331.html https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662333.html https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662334.html https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662336.html https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662379.html https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662380.html https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662381.html emits pedantic pedwarns for alignas appertaining to incorrect entities. As the middle-end and attribute exclusions look for "aligned" attribute, the patch transforms alignas into "internal "::aligned attribute (didn't use [[aligned (x)]] so that people can't type it that way). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-09-06 Jakub Jelinek PR c++/110345 gcc/c-family/ * c-common.h (attr_aligned_exclusions): Declare. (handle_aligned_attribute): Likewise. * c-attribs.cc (handle_aligned_attribute): No longer static. (attr_aligned_exclusions): Use extern instead of static. gcc/cp/ * cp-tree.h (enum cp_tree_index): Add CPTI_INTERNAL_IDENTIFIER. (internal_identifier): Define. (internal_attribute_table): Declare. * parser.cc (cp_parser_exception_declaration): Error on alignas on exception declaration. (cp_parser_std_attribute_spec): Turn alignas into internal ns aligned attribute rather than gnu. * decl.cc (initialize_predefined_identifiers): Initialize internal_identifier. * tree.cc (handle_alignas_attribute): New function. (internal_attributes): New variable. (internal_attribute_table): Likewise. * cp-objcp-common.h (cp_objcp_attribute_table): Add internal_attribute_table entry. gcc/testsuite/ * g++.dg/cpp0x/alignas1.C: Add dg-options "". * g++.dg/cpp0x/alignas2.C: Likewise. * g++.dg/cpp0x/alignas7.C: Likewise. * g++.dg/cpp0x/alignas21.C: New test. * g++.dg/ext/bitfield9.C: Expect a warning. * g++.dg/cpp2a/is-layout-compatible3.C: Add dg-options -pedantic. Expect a warning. Jakub --- gcc/c-family/c-common.h.jj 2024-09-06 13:43:37.311307920 +0200 +++ gcc/c-family/c-common.h 2024-09-06 15:33:47.497616169 +0200 @@ -1645,8 +1645,10 @@ extern int parse_tm_stmt_attr (tree, int extern int tm_attr_to_mask (tree); extern tree tm_mask_to_attr (int); extern tree find_tm_attribute (tree); +extern const struct attribute_spec::exclusions attr_aligned_exclusions[]; extern const struct attribute_spec::exclusions attr_cold_hot_exclusions[]; extern const struct attribute_spec::exclusions attr_noreturn_exclusions[]; +extern tree handle_aligned_attribute (tree *, tree, tree, int, bool *); extern tree handle_noreturn_attribute (tree *, tree, tree, int, bool *); extern tree handle_musttail_attribute (tree *, tree, tree, int, bool *); extern bool has_attribute (location_t, tree, tree, tree (*)(tree)); --- gcc/c-family/c-attribs.cc.jj 2024-09-06 13:43:37.300308064 +0200 +++ gcc/c-family/c-attribs.cc 2024-09-06 16:00:55.864465359 +0200 @@ -100,7 +100,6 @@ static tree handle_destructor_attribute static tree handle_mode_attribute (tree *, tree, tree, int, bool *); static tree handle_section_attribute (tree *, tree, tree, int, bool *); static tree handle_special_var_sec_attribute (tree *, tree, tree, int, bool *); -static tree handle_aligned_attribute (tree *, tree, tree, int, bool *); static tree handle_warn_if_not_aligned_attribute (tree *, tree, tree, int, bool *); static tree handle_strict_flex_array_attribute (tree *, tree, tree, @@ -192,7 +191,7 @@ static tree handle_null_terminated_strin { name, function, type, variable } /* Define attributes that are mutually exclusive with one another. */ -static const struct attribute_spec::exclusions attr_aligned_exclusions[] = +extern const struct attribute_spec::exclusions attr_aligned_exclusions[] = { /* Attribute name exclusion applies to: function, type, variable */ @@ -2806,7 +2805,7 @@ common_handle_aligned_attribute (tree *n /* Handle a "aligned" attribute; arguments as in struct attribute_spec.handler. */ -static tree +tree handle_aligned_attribute (tree *node, tree name, tree args, int flags, bool *no_add_attrs) { --- gcc/cp/cp-tree.h.jj 2024-09-06 13:58:09.428940803 +0200 +++ gcc/cp/cp-tree.h 2024-09-06 15:51:23.012904756 +0200 @@ -192,6 +192,7 @@ enum cp_tree_index CPTI_HEAP_VEC_UNINIT_IDENTIFIER, CPTI_HEAP_VEC_IDENTIFIER, CPTI_OMP_IDENTIFIER, + CPTI_INTERNAL_IDENTIFIER, CPTI_LANG_NAME_C, CPTI_LANG_NAME_CPLUSPLUS, @@ -345,6 +346,7 @@ extern GTY(()) tree cp_global_trees[CPTI #define heap_vec_uninit_identifier cp_global_trees[CPTI_HEAP_VEC_UNINIT_IDENTIFIER] #define heap_vec_identifier cp_global_trees[CPTI_HEAP_VEC_IDENTIFIER] #define omp_identifier cp_global_trees[CPTI_OMP_IDENTIFIER] +#define internal_identifier cp_global_trees[CPTI_INTERNAL_IDENTIFIER] #define lang_name_c cp_global_trees[CPTI_LANG_NAME_C] #define lang_name_cplusplus cp_global_trees[CPTI_LANG_NAME_CPLUSPLUS] @@ -8132,6 +8134,7 @@ extern bool is_byte_access_type (tree) extern bool is_byte_access_type_not_plain_char (tree); extern const struct scoped_attribute_specs cxx_gnu_attribute_table; extern const struct scoped_attribute_specs std_attribute_table; +extern const struct scoped_attribute_specs internal_attribute_table; extern tree make_ptrmem_cst (tree, tree); extern tree cp_build_type_attribute_variant (tree, tree); extern tree cp_build_reference_type (tree, bool); --- gcc/cp/parser.cc.jj 2024-09-06 14:29:48.392322139 +0200 +++ gcc/cp/parser.cc 2024-09-06 17:10:18.507455975 +0200 @@ -29681,7 +29681,15 @@ cp_parser_exception_declaration (cp_pars tree decl = grokdeclarator (declarator, &type_specifiers, CATCHPARM, 1, &type_specifiers.attributes); if (decl != error_mark_node && type_specifiers.attributes) - cplus_decl_attributes (&decl, type_specifiers.attributes, 0); + { + cplus_decl_attributes (&decl, type_specifiers.attributes, 0); + if (pedantic && lookup_attribute ("internal ", "aligned", + DECL_ATTRIBUTES (decl))) + pedwarn (type_specifiers.locations[ds_attribute] + ? type_specifiers.locations[ds_attribute] + : input_location, OPT_Wpedantic, + "% on exception declaration"); + } return decl; } @@ -31131,7 +31139,7 @@ cp_parser_std_attribute_spec (cp_parser /* Build the C++-11 representation of an 'aligned' attribute. */ attributes - = build_tree_list (build_tree_list (gnu_identifier, + = build_tree_list (build_tree_list (internal_identifier, aligned_identifier), alignas_expr); } --- gcc/cp/decl.cc.jj 2024-09-06 14:29:32.619526092 +0200 +++ gcc/cp/decl.cc 2024-09-06 15:51:53.437509531 +0200 @@ -4812,6 +4812,7 @@ initialize_predefined_identifiers (void) {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal}, {"heap []", &heap_vec_identifier, cik_normal}, {"omp", &omp_identifier, cik_normal}, + {"internal ", &internal_identifier, cik_normal}, {NULL, NULL, cik_normal} }; --- gcc/cp/tree.cc.jj 2024-09-06 14:30:05.278103789 +0200 +++ gcc/cp/tree.cc 2024-09-06 17:16:47.490434844 +0200 @@ -5127,6 +5127,35 @@ handle_maybe_unused_attribute (tree *nod return ret; } +/* The C++11 alignment specifier. It mostly maps to GNU aligned attribute, + but we need to do some extra pedantic checking. */ + +static tree +handle_alignas_attribute (tree *node, tree name, tree args, int flags, + bool *no_add_attrs) +{ + tree t = *node; + tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs); + if (pedantic) + { + if (TREE_CODE (*node) == FUNCTION_DECL) + pedwarn (input_location, OPT_Wattributes, + "% on function declaration"); + else if (TREE_CODE (*node) == ENUMERAL_TYPE) + pedwarn (input_location, OPT_Wattributes, + "% on enumerated type"); + else if (TYPE_P (*node) && t != *node) + pedwarn (input_location, OPT_Wattributes, + "% on a type other than class"); + else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node)) + pedwarn (input_location, OPT_Wattributes, "% on bit-field"); + else if (TREE_CODE (t) == TYPE_DECL) + pedwarn (input_location, OPT_Wattributes, + "% on a type alias"); + } + return ret; +} + /* Table of valid C++ attributes. */ static const attribute_spec cxx_gnu_attributes[] = { @@ -5177,6 +5206,18 @@ const scoped_attribute_specs std_attribu nullptr, { std_attributes } }; +/* Table of internal attributes. */ +static const attribute_spec internal_attributes[] = +{ + { "aligned", 0, 1, false, false, false, false, + handle_alignas_attribute, attr_aligned_exclusions } +}; + +const scoped_attribute_specs internal_attribute_table = +{ + "internal ", { internal_attributes } +}; + /* Handle an "init_priority" attribute; arguments as in struct attribute_spec.handler. */ static tree --- gcc/cp/cp-objcp-common.h.jj 2024-09-06 13:43:37.712302692 +0200 +++ gcc/cp/cp-objcp-common.h 2024-09-06 15:47:33.425887161 +0200 @@ -129,7 +129,8 @@ static const scoped_attribute_specs *con &cxx_gnu_attribute_table, &c_common_gnu_attribute_table, &c_common_clang_attribute_table, - &c_common_format_attribute_table + &c_common_format_attribute_table, + &internal_attribute_table }; #undef LANG_HOOKS_ATTRIBUTE_TABLE --- gcc/testsuite/g++.dg/cpp0x/alignas1.C.jj 2020-01-12 11:54:37.052403768 +0100 +++ gcc/testsuite/g++.dg/cpp0x/alignas1.C 2024-09-06 17:22:09.014284498 +0200 @@ -1,5 +1,6 @@ // PR c++/65734 // { dg-do compile { target c++11 } } +// { dg-options "" } template struct A { --- gcc/testsuite/g++.dg/cpp0x/alignas2.C.jj 2020-01-12 11:54:37.052403768 +0100 +++ gcc/testsuite/g++.dg/cpp0x/alignas2.C 2024-09-06 17:22:36.848925193 +0200 @@ -1,5 +1,6 @@ // PR c++/65734 // { dg-do compile { target c++11 } } +// { dg-options "" } template struct BVector --- gcc/testsuite/g++.dg/cpp0x/alignas7.C.jj 2020-01-12 11:54:37.052403768 +0100 +++ gcc/testsuite/g++.dg/cpp0x/alignas7.C 2024-09-06 17:23:02.934588031 +0200 @@ -1,5 +1,6 @@ // PR c++/71513 // { dg-do compile { target c++11 } } +// { dg-options "" } template < int N, typename T > struct A --- gcc/testsuite/g++.dg/cpp0x/alignas21.C.jj 2024-09-06 14:30:31.548763706 +0200 +++ gcc/testsuite/g++.dg/cpp0x/alignas21.C 2024-09-06 17:18:20.721231386 +0200 @@ -0,0 +1,157 @@ +// 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) () {}; // { dg-error "'alignas' on function declaration" } + auto b = [] constexpr alignas (int) {}; // { dg-error "'alignas' on a type other than class" } + // { 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) {}; // { dg-error "'alignas' on a type other than class" } + // { dg-error "parameter declaration before lambda exception specification only optional with" "" { target c++20_down } .-1 } + auto d = [] () alignas (int) {}; // { dg-error "'alignas' on a type other than class" } + 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); // { dg-error "'alignas' on a type other than class" } + 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) {} // { dg-error "'alignas' on exception declaration" } + try {} catch (alignas (int) int) {} // { dg-error "'alignas' on exception declaration" } + 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)) {} // { dg-error "'alignas' on exception declaration" } +} + +alignas (int) int bar (); // { dg-error "'alignas' on function declaration" } +using foobar alignas (int) = int; // { dg-error "'alignas' on a type alias" } +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); +struct alignas (int) Y; +int g[2] alignas (int); // { dg-error "'alignas' on a type other than class" } +int g2 alignas (int) [2]; +int corge () alignas (int); // { dg-error "'alignas' on a type other than class" } +int *alignas (int) h; // { dg-error "'alignas' on a type other than class" } +int & alignas (int) i = f; // { dg-error "'alignas' on a type other than class" } +int && alignas (int) j = 0; // { dg-error "'alignas' on a type other than class" } +int S::* alignas (int) k; // { dg-error "'alignas' on a type other than class" } +auto l = sizeof (int [2] alignas (int)); // { dg-error "'alignas' on a type other than class" } +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 +garply () // { dg-error "'alignas' on function declaration" } +{ +} +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 }; // { dg-error "'alignas' on enumerated type" } +enum class alignas (int) E { E0 }; // { dg-error "'alignas' on enumerated type" } +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 (); // { dg-error "'alignas' on function declaration" } + alignas (int) int bar () { return 1; } // { dg-error "'alignas' on function declaration" } + alignas (int) int : 0; // { dg-error "'alignas' on bit-field" } + alignas (int) int i2 : 5; // { dg-error "'alignas' on bit-field" } + 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); // { dg-error "'alignas' on a type alias" } +template +struct M {}; +template <> +struct alignas (int) M { int m; }; +typedef int N[2] alignas (int); // { dg-error "'alignas' on a type other than class" } +typedef int O alignas (int) [2]; // { dg-error "'alignas' on a type alias" } --- gcc/testsuite/g++.dg/ext/bitfield9.C.jj 2020-01-14 20:02:46.829609145 +0100 +++ gcc/testsuite/g++.dg/ext/bitfield9.C 2024-09-06 20:25:54.024691945 +0200 @@ -3,7 +3,7 @@ struct S { - char a:4; + char a:4; // { dg-warning "alignas' on bit-field" "" { target *-*-* } .+1 } char b:8 alignas(int); // { dg-warning "ISO C\\+\\+ allows bit-field attributes only before the ':' token" } char c:8 [[gnu::aligned(8)]]; // { dg-warning "ISO C\\+\\+ allows bit-field attributes only before the ':' token" } // { dg-error "two consecutive '\\\[' shall only introduce an attribute before '\\\[' token" "" { target *-*-* } .-1 } --- gcc/testsuite/g++.dg/cpp2a/is-layout-compatible3.C.jj 2022-11-17 22:10:05.809657315 +0100 +++ gcc/testsuite/g++.dg/cpp2a/is-layout-compatible3.C 2024-09-06 20:27:54.773223783 +0200 @@ -1,5 +1,6 @@ // P0466R5 // { dg-do compile { target c++20 } } +// { dg-options "-pedantic" } namespace std { @@ -34,7 +35,7 @@ union N { J v; }; union O { int a; int b; }; union P { int a : 1; int b : 12; }; enum Q : int { Q1, Q2 }; -enum alignas(16) R : int { R1, R2 }; +enum alignas(16) R : int { R1, R2 }; // { dg-warning "'alignas' on enumerated type" } struct U { [[no_unique_address]] S a1; [[no_unique_address]] S a2; [[no_unique_address]] S a3; }; struct V { [[no_unique_address]] S b1; [[no_unique_address]] T b2; [[no_unique_address]] S b3; }; struct alignas(16) A : public I {};