[llvm-bugs] [Bug 46246] New: clang-cl allows dynamic_cast when /GR- is specified

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 8 18:30:00 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46246

            Bug ID: 46246
           Summary: clang-cl allows dynamic_cast when /GR- is specified
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zufuliu at 163.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

cl /GR- test.cpp produces a warning: warning C4541: 'dynamic_cast' used on
polymorphic type 'B' with /GR-; unpredictable behavior may result

clang-cl /GR- test.cpp produces no warnings, while clang -fno-rtti test.cpp
produces a error: use of dynamic_cast requires -frtti

Since compiling without RTTI doesn't produce runnable code (the program crashed
inside dynamic_cast), I think clang-cl should emit a warning or error.

this is related to https://bugs.llvm.org/show_bug.cgi?id=46230

test.cpp also at https://godbolt.org/z/C4HZtK

#include <cstdio>

class B {
public:
    virtual ~B() = default;
};

class D1 : public B {
public:
    ~D1() = default;
    static void f(B *b) noexcept {
        printf("enter D1::g()\n");
        if (auto d = dynamic_cast<D1 *>(b)) {
            printf("D1::g() after cast\n");
        }
        printf("exit D1::g()\n");
    }
};

class D2 : public B {
public:
    ~D2() = default;
};

int main() {
    B *b = new D1();
    D1::f(b);
    delete b;
    return 0;
}

-- 
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/20200609/6b5c4f6f/attachment.html>


More information about the llvm-bugs mailing list