<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - Static analyser doesn't respect #pragma GCC diagnostic ignored "-Wnonnull""
href="https://llvm.org/bugs/show_bug.cgi?id=28275">28275</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Static analyser doesn't respect #pragma GCC diagnostic ignored "-Wnonnull"
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>Static Analyzer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>kremenek@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>sgubmvll@mjt.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>I have a method that should not be passed a null pointer under normal
operation, so I have declared it like so (in C):
uint16_t CRC_xmodem(const uint8_t* data, const uint16_t length)
__attribute__((nonnull));
but in unit testing I want to pass it a null pointer to ensure it accepts it
gracefully. To avoid a compiler warning, I do this like so (in C++, using
catch.hpp if that's relevant):
TEST_CASE("CRC_xmodem null pointer produces zero, "[crc]") {
#pragma GCC diagnostic ignored "-Wnonnull"
CHECK( 0 == CRC_xmodem(NULL, 0) );
#pragma GCC diagnostic pop
}
This is sufficient to suppress the compile-time warnings, but scan-build still
produces a warning:-
snip/crc/crc_unittest.cpp:34:21: warning: Null pointer passed as an argument to
a 'nonnull' parameter
CHECK( 0 == CRC_xmodem(NULL, 0) );
^ ~~~~
Currently I'm suppressing the warning using #ifndef __clang_analyzer__ but it
would be tidier if the clang analyser respected the GCC pragma.</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>