<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - False positive -Wimplicit-fallthrough warning in flex-generated C code"
href="https://bugs.llvm.org/show_bug.cgi?id=43465">43465</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>False positive -Wimplicit-fallthrough warning in flex-generated C code
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>sean@rogue-research.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Consider this C code:
-------------------
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int x = random();
switch (x)
{
case 1:
printf("case1");
/*FALLTHROUGH*/
default:
printf("default");
}
return 0;
}
-------------------
clang trunk (but not the current release, 9.0) with -Wimplicit-fallthrough
warns:
-------------------
<source>:12:5: warning: unannotated fall-through between switch labels
[-Wimplicit-fallthrough]
default:
^
<source>:12:5: note: insert '__attribute__((fallthrough));' to silence this
warning
default:
^
__attribute__((fallthrough));
<source>:12:5: note: insert 'break;' to avoid fall-through
default:
^
break;
-------------------
gcc 7.x and later do *not* warn, because they detect the comment
"/*FALLTHROUGH*/" and take it as a cue that it's deliberately. This is
documented here:
<a href="https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough">https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough</a>
Compare on godbolt:
<a href="https://godbolt.org/z/UFpfNm">https://godbolt.org/z/UFpfNm</a>
It would be nice if clang did the same. Especially since the venerable flex
<<a href="https://github.com/westes/flex">https://github.com/westes/flex</a>> generates code that uses exactly that comment.
Without this, clang will start giving false positive warnings (that gcc does
not) on lots of flex-generated code out there.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>