[LLVMbugs] [Bug 22181] New: warn on c-style cast that changes meaning after definition

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jan 9 20:36:31 PST 2015


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: unassignedclangbugs at nondot.org
          Reporter: nlewycky at google.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150110/1c5020cc/attachment.html>


More information about the llvm-bugs mailing list