<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 - Diagnostic missing from -Wcast-qual in C++"
href="https://bugs.llvm.org/show_bug.cgi?id=44282">44282</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Diagnostic missing from -Wcast-qual in C++
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>warren_ristow@playstation.sony.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>The test-case below has two functions in it, both of which cast a const pointer
to a 'void *', dropping the const qualifier. I believe they both should
produce a warning when compiled with '-Wcast-qual'. The function 'foo()'
(which casts a 'const float *' to a 'void *') does not produce the warning,
whereas the function 'bar()' (which casts a 'const void *' to a 'void *') does.
Tested this with llvm 9.0.
$ cat test.cpp
////////////////////////////////////////////////////////////
extern void usePtr(const void *ptr);
void foo(const float *pf_const)
{
// Casting away const-ness, but no warning appears here.
usePtr((void *) pf_const);
}
void bar(const void *pv_const)
{
// Casting away const-ness, and warning does appear here.
usePtr((void *) pv_const);
}
////////////////////////////////////////////////////////////
$ clang++ -c -Wcast-qual test.cpp
test.cpp:13:19: warning: cast from 'const void *' to 'void *' drops const
qualifier [-Wcast-qual]
usePtr((void *) pv_const);
^
1 warning generated.
$
I noticed that an appropriate diagnostic does appear on both of these cases if
the test is compiled as C, rather than C++. So maybe there is some C++ subtlety
that means the 'foo()' example above should not get a warning. That said, GCC
produces the warning for both cases, in both C and C++ mode (tested GCC 7.4.0).
This looks to be similar to <a class="bz_bug_link
bz_status_NEW "
title="NEW - -Wcast-qual doesn't work in C++"
href="show_bug.cgi?id=23396">bug 23396</a>, although not quite the same.</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>