NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
toolchain/57723: -Wmisleading-indentation can warn incorrectly
>Number: 57723
>Category: toolchain
>Synopsis: -Wmisleading-indentation can warn incorrectly
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: toolchain-manager
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Nov 24 19:20:00 +0000 2023
>Originator: Mouse
>Release: NetBSD 9.1
>Organization:
Dis-
>Environment:
System: NetBSD sonar.credil.org 9.1 NetBSD 9.1 (GENERIC) #0: Sun Oct 18 19:24:30 UTC 2020 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
gcc -Wmisleading-indentation warns about certain
correctly-indented statements. To cite the example I noticed
this with:
buffer.c: In function 'DelBuf':
"buffer.c", line 462:5: error: this 'for' clause does not guard... [-Werror=misleading-indentation]
{ for (p=buffers;p&&(p->kind!=BUF_FILE);p=p->next) ;
^~~
"buffer.c", line 463:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
if (p == 0) p = buffers ? buffers : NewBf_c("main");
^~
See How-To_Repeat for a tiny example.
>How-To-Repeat:
$ cat ind.c
extern int foo(int n)
{
int i;
int s;
if (n > 1)
{ for (i=0,s=0;i<n;i++,s+=i) ;
if (s > 100) s = 100;
}
else
{ s = 0;
}
return(s);
}
$ cc -c -o ind.o ind.c -Wmisleading-indentation
ind.c: In function 'foo':
ind.c:7:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
{ for (i=0,s=0;i<n;i++,s+=i) ;
^~~
ind.c:8:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
if (s > 100) s = 100;
^~
$
(-Wall works instead of -Wmisleading-indentation.)
Notice that the claim that the for does not control ("guard" is
IMO a misleading word) the if is true, but the claim that the
if is misleadingly indented is false; the for and the if are in
fact indented to the same column. (I suspect it is incorrectly
using the indentation of the first nonblank character of the
line the for is on rather than the indentation of the for, even
though, as the ^~~ indicates, it knows where the for is.)
I haven't probed the envelope of this bug much, but I do not
see it manifest with
{ for (i=0,s=0;i<n;i++) s += i;
if (s > 100) s = 100;
>Fix:
Workaround: -Wno-misleading-indentation
Home |
Main Index |
Thread Index |
Old Index