[llvm-bugs] [Bug 44282] New: Diagnostic missing from -Wcast-qual in C++
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Dec 11 23:13:47 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=44282
Bug ID: 44282
Summary: Diagnostic missing from -Wcast-qual in C++
Product: clang
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: warren_ristow at playstation.sony.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
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 bug 23396, although not quite the same.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191212/b6fb6c24/attachment.html>
More information about the llvm-bugs
mailing list