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

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Raffaello Bertini from comment #9)
> More than to fix something,
> it was a suggestion to evolve or add a warning to tell the user that those
> kind of statements are basically like not written at all, ignored as the
> final result.

That is not what happens.
We do have the -Wpedantic/-pedantic/-pedantic-errors diagnostics shown above,
and otherwise it is well defined, same as if you wrote
MyFunc my_func __attribute__((const));

MyFunc __attribute__((const)) * g_f = my_func;
instead.  Just with the attribute syntax you get an extra warning:
warning: ‘const’ attribute on function returning ‘void’ [-Wattributes]

But if the function returned anything but int, there would be no warning and it
would behave like any other const attributed function, i.e. if the result is
unused, it can be dead code eliminated, if it is called multiple times, the
compiler can CSE those calls into one, assume they don't have any observable
side-effect other than the return value, ...
Just when the function returns void and is declared const, it means it is
totally useless because it can't have any side-effects nor dependencies on
global memory and the return value is the only thing that matters.

Reply via email to