https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110345
--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:cd647514a539943ade6461efbf056a7c3f4305c6 commit r15-6384-gcd647514a539943ade6461efbf056a7c3f4305c6 Author: Jakub Jelinek <ja...@redhat.com> Date: Fri Dec 20 10:12:08 2024 +0100 c++: Disallow [[deprecated]] on types other than class/enum definitions [PR110345] For C++ 26 P2552R3 I went through all the spots (except modules) where attribute-specifier-seq appears in the grammar and tried to construct a testcase in all those spots, for now for [[deprecated]] attribute. The patch below contains that testcase. One needed change for this particular attribute was that currently we handle [[deprecated]] exactly the same as [[gnu::deprecated]], but for the latter unlike C++14 or later we allow it also on almost all types, while the standard is strict and allows it only on https://eel.is/c++draft/dcl.attr#deprecated-2 The attribute may be applied to the declaration of a class, a typedef-name, a variable, a non-static data member, a function, a namespace, an enumeration, an enumerator, a concept, or a template specialization. The following patch just adds a pedwarn for the cases that gnu::deprecated allows but C++14 disallows, so integral/floating/boolean types, pointers/references, array types, function types etc. Basically, for TYPE_P, if the attribute is applied in place (which means the struct/union/class/enum definition), it is allowed, otherwise pedwarned. I've tried to compile it also with latest clang and there is agreement in most of the diagnostics, just at block scope (inside of foo) it doesn't diagnose auto e = new int [n] [[deprecated]]; auto e2 = new int [n] [[deprecated]] [42]; [[deprecated]] lab:; and at namespace scope [[deprecated]]; I think that all feels like clang++ bug. Also this pedwarns on [[deprecated]] int : 0; at class scope, that isn't a non-static data member... I guess to mark the paper as implemented (or what has been already voted into C++23 earlier) we'll need to add similar testcase for all the other standard attributes and make sure we check what the attributes can appertain to and what they can't. 2024-12-19 Jakub Jelinek <ja...@redhat.com> PR c++/110345 * parser.cc (cp_parser_std_attribute): Don't transform [[deprecated]] into [[gnu::deprecated]]. * tree.cc (handle_std_deprecated_attribute): New function. (std_attributes): Add deprecated entry. * g++.dg/cpp0x/attr-deprecated1.C: New test. --- Comment #15 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:92216cbc59b3a4566d49de5dfa059b70b03d639a commit r15-6385-g92216cbc59b3a4566d49de5dfa059b70b03d639a Author: Jakub Jelinek <ja...@redhat.com> Date: Fri Dec 20 10:17:56 2024 +0100 c++: Fix up maybe_unused attribute handling [PR110345] When adding test coverage for maybe_unused attribute, I've run into several things: 1) similarly to deprecated attribute, the attribute shouldn't pedantically appertain to types other than class/enumeration definitions 2) similarly to deprecated attribute, the attribute shouldn't pedantically appertain to unnamed bit-fields 3) the standard says that it can appertain to identifier labels, but we handled it silently also on case and default labels 4) I've run into a weird spurious error on int f [[maybe_unused]]; int & [[maybe_unused]] i = f; int && [[maybe_unused]] j = 0; The problem was that we create an attribute variant for the int & type, then create an attribute variant for the int && type, and the type_canon_hash hashing just thought those 2 are the same, so used int & [[maybe_unused]] type for j rather than int && [[maybe_unused]]. As TYPE_REF_IS_RVALUE is a flag in the generic code, it was easily possible to hash that flag and compare it 2024-12-19 Jakub Jelinek <ja...@redhat.com> PR c++/110345 gcc/ * tree.cc (type_hash_canon_hash): Hash TYPE_REF_IS_RVALUE for REFERENCE_TYPE. (type_cache_hasher::equal): Compare TYPE_REF_IS_RVALUE for REFERENCE_TYPE. gcc/cp/ * tree.cc (handle_maybe_unused_attribute): New function. (std_attributes): Use handle_maybe_unused_attribute instead of handle_unused_attribute for maybe_unused attribute. gcc/testsuite/ * g++.dg/cpp0x/attr-maybe_unused1.C: New test. * g++.dg/cpp0x/alignas21.C: Add test for int && alignas (int).