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;
| ^