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

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).