Red Hat Bugzilla – Bug 1315010
gcc: -ftrack-macro-expansion=0 triggers indentation warnings with -Wall
Last modified: 2017-07-27 04:04:32 EDT
Created attachment 1133367 [details]
Description of problem:
Macros htons and ntohs emit gcc warning Wmisleading-indentation.
Which is enabled with gcc argument -Wall.
It breaks my effort to compile without warning and with -Werror.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Compile attached file
sh$ gcc -O2 -Wall -ftrack-macro-expansion=0 -c pok.c
pok.c: In function ‘main’:
pok.c:13:5: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation]
pok.c:13:5: note: ...this ‘else’ clause, but it is not
pok.c:14:5: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation]
pok.c:14:5: note: ...this ‘else’ clause, but it is not
No gcc warnings.
Attached diff /usr/include/bits/byteswap-16.h fixed issue for me.
I can see similar pattern also in /usr/include/bits/byteswap.h
but function ntohl and htonl used different part of header with optimisation
(__bswap_32). But I can prepare patch if you want.
Created attachment 1133368 [details]
I believe this was a GCC bug. I no longer get a -Wall warning for the following test program with gcc-6.0.0-0.20.fc24.x86_64.
main(int argc, char **argv)
int x = atoi (argv);
printf ("%d\n", ntohs (x));
I'm sorry but I can still reproduce this bug.
Please try to reproduce with attached C file and try to follow steps in description of this ticket.
(In reply to Lukas Slebodnik from comment #3)
> I'm sorry but I can still reproduce this bug.
> Please try to reproduce with attached C file and try to follow steps in
> description of this ticket.
Ah, the culprit is -ftrack-macro-expansion=0. Why do you use it?
due to another bug in gcc BZ986923
Fair enough, reassigning to gcc. We cannot fix this on the glibc side; the macro definition is fine as-is.
I'm not sure what the right solution for this problem is. Maybe indentation warnings in macros need to be disabled with -ftrack-macro-expansion=0.
Macro definition is fine but after expansion it is on single line.
and therefore there will be something like
else __asm__ (....); __v;
and it's misleading indentation :-)
I thought that proposed change for glibc [ attachment 1133368 [details] ] is a reasonable compromise.
(In reply to Lukas Slebodnik from comment #7)
> I thought that proposed change for glibc [ attachment 1133368 [details] ] is
> a reasonable compromise.
We would have to rewrite many more macros in a way which is not conforming to the GNU coding style. I don't think this is an option.
With -ftrack-macro-expansion=0 you really don't know if you are from a macro expansion or not, that is the whole point of the option.
This message is a reminder that Fedora 24 is nearing its end of life.
Approximately 2 (two) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 24. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora 'version'
Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.
Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 24 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.
Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.
Filed as an upstream bug.