https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127394

Юрий Матронов <ymbx at yandex dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ymbx at yandex dot ru

--- Comment #1 from Юрий Матронов <ymbx at yandex dot ru> ---
Confirmed on GCC 16.2.1 with `-std=c23` as well.

Interestingly, the `[[nodiscard]]` attribute itself is still applied and
triggers `-Wunused-result` at call sites, so the `-Wattributes` diagnostic on
the closing brace is purely a false positive:

\$ cat main.c
enum [[nodiscard]] err_code : int {
    ERR_OK = 0,
    ERR_FAIL = 1
};

enum err_code do_work(void) {
    return ERR_FAIL;
}

int main(void) {
    do_work();
    return 0;
}

\$ gcc -std=c23 -Wall -Wextra main.c
main.c:4:1: warning: type attributes ignored after type is already defined
[-Wattributes]
    4 | };
      | ^
main.c: In function ‘main’:
main.c:11:5: warning: ignoring return value of type ‘enum err_code’, declared
with attribute ‘nodiscard’ [-Wunused-result]
   11 |     do_work();
      |     ^~~~~~~~~
main.c:6:15: note: in call to ‘do_work’, declared here
    6 | enum err_code do_work(void) {
      |               ^~~~~~~

Reply via email to