diff options
author | Marek Polacek <polacek@redhat.com> | 2022-08-26 18:03:53 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-08-29 17:26:44 -0400 |
commit | 98973354b8690f01e06b9f36106e786fd94ac7a3 (patch) | |
tree | d35a699724295da39bc88de9784227bab996feb6 /gcc/ChangeLog | |
parent | b504149d2c92ddfcfab62ea6d1ed49ae72493e38 (diff) | |
download | gcc-98973354b8690f01e06b9f36106e786fd94ac7a3.zip gcc-98973354b8690f01e06b9f36106e786fd94ac7a3.tar.gz gcc-98973354b8690f01e06b9f36106e786fd94ac7a3.tar.bz2 |
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.
Diffstat (limited to 'gcc/ChangeLog')
0 files changed, 0 insertions, 0 deletions