diff options
| author | Marek Polacek <polacek@redhat.com> | 2021-05-18 16:11:16 -0400 |
|---|---|---|
| committer | Marek Polacek <polacek@redhat.com> | 2021-05-19 13:10:15 -0400 |
| commit | adcb497bdba499d161d2e5e8de782bdd6f75d62c (patch) | |
| tree | a942fb6dd1ff181d3f39e0507b46db9045f88a9d /gcc/cp/decl.c | |
| parent | a911287e13d1a1f95259cb60c57293eabc2a27b9 (diff) | |
| download | gcc-adcb497bdba499d161d2e5e8de782bdd6f75d62c.zip gcc-adcb497bdba499d161d2e5e8de782bdd6f75d62c.tar.gz gcc-adcb497bdba499d161d2e5e8de782bdd6f75d62c.tar.bz2 | |
c++: Relax attribute on friend declaration checking [PR100596]
It turned out that there are codebases that profusely use GNU attributes
on friend declarations, so we have to dial back our checking and allow
them. And for C++11 attributes let's just warn instead of giving
errors.
PR c++/100596
gcc/cp/ChangeLog:
* cp-tree.h (any_non_type_attribute_p): Remove.
* decl.c (grokdeclarator): Turn an error into a warning and only
warn for standard attributes.
* decl2.c (any_non_type_attribute_p): Remove.
* parser.c (cp_parser_elaborated_type_specifier): Turn an error
into a warning and only warn for standard attributes.
(cp_parser_member_declaration): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/friend7.C: Turn a few dg-warnings into dg-errors.
Remove dg-errors for GNU attributes.
* g++.dg/ext/attrib63.C: Remove dg-error.
* g++.dg/cpp0x/friend8.C: New test.
Diffstat (limited to 'gcc/cp/decl.c')
| -rw-r--r-- | gcc/cp/decl.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 4f2fc2e..28052df 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -13731,11 +13731,15 @@ grokdeclarator (const cp_declarator *declarator, if (friendp) { - if (attrlist && !funcdef_flag - /* Hack to allow attributes like vector_size on a friend. */ - && any_non_type_attribute_p (*attrlist)) - error_at (id_loc, "attribute appertains to a friend " - "declaration that is not a definition"); + /* Packages tend to use GNU attributes on friends, so we only + warn for standard attributes. */ + if (attrlist && !funcdef_flag && cxx11_attribute_p (*attrlist)) + { + *attrlist = NULL_TREE; + if (warning_at (id_loc, OPT_Wattributes, "attribute ignored")) + inform (id_loc, "an attribute that appertains to a friend " + "declaration that is not a definition is ignored"); + } /* Friends are treated specially. */ if (ctype == current_class_type) ; /* We already issued a permerror. */ |
