http://llvm.org/bugs/show_bug.cgi?id=22181
Bug ID: 22181
Summary: warn on c-style cast that changes meaning after
definition
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
Testcase from http://whatofhow.wordpress.com/2014/12/17/evil-casts/ :
struct S1 { int s1 = 2; };
struct S2;
S2 *f(S1 *s) { return (S2*) s; }
struct T { int t = 1; };
struct S2 : T, S1 {};
int main() { S2 s2; return f(&s2)->t; }
This code builds in -std=c++11 with no interesting warnings. The problem is in
the definition of 'f' which casts to a pointer to incomplete class type. The
std says "It is unspecified whether a static_cast or reinterpret_cast
interpretation is used, even if there is an inheritance relationship between
the two classes."
If we have a C-style cast to a point to an incomplete class type, then when we
see the definition of the class type we should check whether the static_cast
and reinterpret_cast interpretations would have had different semantics.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs