[Bug c++/106712] Incorrect propagation of C++11 attributes to subsequent function declarations

2022-08-29 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106712

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Marek Polacek  ---
Fixed.

[Bug c++/106712] Incorrect propagation of C++11 attributes to subsequent function declarations

2022-08-29 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106712

--- Comment #3 from CVS Commits  ---
The trunk branch has been updated by Marek Polacek :

https://gcc.gnu.org/g:98973354b8690f01e06b9f36106e786fd94ac7a3

commit r13-2256-g98973354b8690f01e06b9f36106e786fd94ac7a3
Author: Marek Polacek 
Date:   Fri Aug 26 18:03:53 2022 -0400

c++: Fix C++11 attribute propagation [PR106712]

When we have

  [[noreturn]] int fn1 [[nodiscard]](), fn2();

"noreturn" should apply to both fn1 and fn2 but "nodiscard" only to fn1:
[dcl.pre]/3: "The attribute-specifier-seq appertains to each of
the entities declared by the declarators of the init-declarator-list."
[dcl.spec.general]: "The attribute-specifier-seq affects the type
only for the declaration it appears in, not other declarations involving
the same type."

As Ed Catmur correctly analyzed, this is because, for the test above,
we call start_decl with prefix_attributes=noreturn, but this line:

  attributes = attr_chainon (attributes, prefix_attributes);

results in attributes == prefix_attributes, because chainon sees
that attributes is null so it just returns prefix_attributes.  Then
in grokdeclarator we reach

  *attrlist = attr_chainon (*attrlist, declarator->std_attributes);

which modifies prefix_attributes so now it's "noreturn, nodiscard"
and so fn2 is wrongly marked nodiscard as well.  Fixed by reversing
the order of arguments to attr_chainon.  That way, we tack the prefix
attributes onto ->std_attributes, avoiding modifying prefix_attributes.

PR c++/106712

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator): Reverse the order of arguments to
attr_chainon.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/gen-attrs-77.C: New test.

[Bug c++/106712] Incorrect propagation of C++11 attributes to subsequent function declarations

2022-08-26 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106712

Marek Polacek  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org
 Status|NEW |ASSIGNED

[Bug c++/106712] Incorrect propagation of C++11 attributes to subsequent function declarations

2022-08-22 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106712

Marek Polacek  changed:

   What|Removed |Added

 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2022-08-22
 CC||mpolacek at gcc dot gnu.org

--- Comment #2 from Marek Polacek  ---
Thanks for the report.  I plan to take a look.  Probably not a regression.

[Bug c++/106712] Incorrect propagation of C++11 attributes to subsequent function declarations

2022-08-22 Thread ed at catmur dot uk via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106712

--- Comment #1 from Ed Catmur  ---
I believe this is happening because start_decl can modify prefix_attributes (by
first chaining it onto attributes, then passing the merged chain to
grokdeclarator  which can then chain onto that merged chain).  If the attribute
list is empty, prefix_attributes is NULL_TREE and so is not affected.

If so, the simplest fix would be for start_decl to copy_list(prefix_attributes)
prior to chaining it.