aboutsummaryrefslogtreecommitdiff
path: root/gcc/file-find.h
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-04-29 21:38:14 -0400
committerMarek Polacek <polacek@redhat.com>2021-05-13 21:13:32 -0400
commit149061188c7c6ddf27663c8c00b7574fc8d0fd23 (patch)
tree73ad0e8a10cdf67cb96a97cd2909cdaacf2dbe44 /gcc/file-find.h
parentf9af11c7f156bede9aa28410073acbab7b0fa0fe (diff)
downloadgcc-149061188c7c6ddf27663c8c00b7574fc8d0fd23.zip
gcc-149061188c7c6ddf27663c8c00b7574fc8d0fd23.tar.gz
gcc-149061188c7c6ddf27663c8c00b7574fc8d0fd23.tar.bz2
c++: Check attributes on friend declarations [PR99032]
This patch implements [dcl.attr.grammar]/5: "If an attribute-specifier-seq appertains to a friend declaration ([class.friend]), that declaration shall be a definition." This restriction applies to C++11-style attributes as well as GNU attributes with the exception that we allow GNU attributes that require a type, such as vector_size to continue accepting code as in attrib63.C. There are various forms of friend declarations, we have friend templates, C++11 extended friend declarations, and so on. In some cases we already ignore the attribute and warn that it was ignored. But certain cases weren't diagnosed, and with this patch we'll give a hard error. I tried hard not to emit both a warning and error and I think it worked out. Jason provided the cp_parser_decl_specifier_seq hunk to detect using standard attributes in the middle of decl-specifiers, which is invalid. Co-authored-by: Jason Merrill <jason@redhat.com> gcc/cp/ChangeLog: PR c++/99032 * cp-tree.h (any_non_type_attribute_p): Declare. * decl.c (grokdeclarator): Diagnose when an attribute appertains to a friend declaration that is not a definition. * decl2.c (any_non_type_attribute_p): New. * parser.c (cp_parser_decl_specifier_seq): Diagnose standard attributes in the middle of decl-specifiers. (cp_parser_elaborated_type_specifier): Diagnose when an attribute appertains to a friend declaration that is not a definition. (cp_parser_member_declaration): Likewise. gcc/testsuite/ChangeLog: PR c++/99032 * g++.dg/cpp0x/friend7.C: New test. * g++.dg/cpp0x/gen-attrs-4.C: Add dg-error. * g++.dg/cpp0x/gen-attrs-39-1.C: Likewise. * g++.dg/cpp0x/gen-attrs-74.C: New test. * g++.dg/ext/attrib63.C: New test.
Diffstat (limited to 'gcc/file-find.h')
0 files changed, 0 insertions, 0 deletions