This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/69818] New: feature request: generate a warning for C++ functional cast expression on pointer or reference
- From: "cvs at cs dot utoronto.ca" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 14 Feb 2016 21:57:11 +0000
- Subject: [Bug c++/69818] New: feature request: generate a warning for C++ functional cast expression on pointer or reference
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69818
Bug ID: 69818
Summary: feature request: generate a warning for C++ functional
cast expression on pointer or reference
Product: gcc
Version: 5.2.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: cvs at cs dot utoronto.ca
Target Milestone: ---
We have -Wold-style-cast for C-style cast expressions, but there is no warning
for C++ functional cast expressions even though they are essentially equal in
their power and potential for problems. Consider this contrived example:
short x;
typedef long& R;
long& y = R(x);
typedef long* P;
long* z = P(&x);
Hopefully this pattern is not common with typedefs like this, but I have
encountered bugs in generic code where the typedefs are instead template
parameters bound to a pointer or reference type.
I am not proposing a simple warn on all uses warning like -Wold-style-cast, but
instead would like to suggest one of the following:
A) warn on all functional cast expressions where the destination is a pointer
or reference type, or
B) warn on all functional cast expressions where the destination is a pointer
or reference type and the equivalent static_cast<>() expression would produce
an error.
Personally, I think option B would provide the greatest bug finding benefit
with few false positives. Option B might be simplified to simply warn in all
cases where the equivalent static_cast<>() expression would produce an error.