public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/101545] New: [[nodiscard]]: Incorrect warning when creating a function alias
@ 2021-07-21 7:06 colomar.6.4.3 at gmail dot com
2021-07-21 7:07 ` [Bug c/101545] " colomar.6.4.3 at gmail dot com
2024-04-09 6:56 ` [Bug c/101545] copy attribute is not copying the C++11/C23 attributes correctly pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2021-07-21 7:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101545
Bug ID: 101545
Summary: [[nodiscard]]: Incorrect warning when creating a
function alias
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: colomar.6.4.3 at gmail dot com
Target Milestone: ---
The following code never discards that `42`, passing it to the caller of
foobar() (in a different translation unit), and forcing it to read the value.
The warnings about an ignored [[nodiscard]] are therefore incorrect.
I put the contents of the header in the same source file just for simplicity.
$ cat nodiscard.c
[[nodiscard]] int foo(void);
[[gnu::copy(foo)]] extern __typeof__(foo) bar;
[[nodiscard]] int foobar(void);
int foo(void)
{
return 42;
}
int foobar(void)
{
return bar(); /* This will return 42 */
}
[[gnu::alias("foo")]] [[gnu::copy(foo)]] extern __typeof__(foo) bar;
$ cc -Wall -Wextra -std=c2x -c nodiscard.c
nodiscard.c:3:1: warning: 'nodiscard' attribute directive ignored
[-Wattributes]
3 | [[gnu::copy(foo)]] extern __typeof__(foo) bar;
| ^
nodiscard.c:18:1: warning: 'nodiscard' attribute directive ignored
[-Wattributes]
18 | [[gnu::alias("foo")]] [[gnu::copy(foo)]] extern __typeof__(foo) bar;
| ^
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/101545] [[nodiscard]]: Incorrect warning when creating a function alias
2021-07-21 7:06 [Bug c/101545] New: [[nodiscard]]: Incorrect warning when creating a function alias colomar.6.4.3 at gmail dot com
@ 2021-07-21 7:07 ` colomar.6.4.3 at gmail dot com
2024-04-09 6:56 ` [Bug c/101545] copy attribute is not copying the C++11/C23 attributes correctly pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2021-07-21 7:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101545
--- Comment #1 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
The same code with [[gnu::warn_unused_result]] instead of [[nodiscard]] doesn't
trigger the warning.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/101545] copy attribute is not copying the C++11/C23 attributes correctly.
2021-07-21 7:06 [Bug c/101545] New: [[nodiscard]]: Incorrect warning when creating a function alias colomar.6.4.3 at gmail dot com
2021-07-21 7:07 ` [Bug c/101545] " colomar.6.4.3 at gmail dot com
@ 2024-04-09 6:56 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-09 6:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101545
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-04-09
Ever confirmed|0 |1
Summary|[[nodiscard]]: Incorrect |copy attribute is not
|warning when creating a |copying the C++11/C23
|function alias |attributes correctly.
CC| |pinskia at gcc dot gnu.org
Status|UNCONFIRMED |NEW
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
It has nothing to do with aliases at all. All has to do with the copy attribute
not copying the C++11/C23 attributes correctly.
Even the following C++ code incorrectly warns.
Like:
```
[[maybe_unused]] int foo(void);
[[gnu::copy(foo)]] extern __typeof__(foo) bar;
```
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-09 6:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 7:06 [Bug c/101545] New: [[nodiscard]]: Incorrect warning when creating a function alias colomar.6.4.3 at gmail dot com
2021-07-21 7:07 ` [Bug c/101545] " colomar.6.4.3 at gmail dot com
2024-04-09 6:56 ` [Bug c/101545] copy attribute is not copying the C++11/C23 attributes correctly pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).