[llvm-bugs] [Bug 38601] New: static cast a derived class to base class with defined type case operators

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 16 09:46:01 PDT 2018


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

            Bug ID: 38601
           Summary: static cast a derived class to base class with defined
                    type case operators
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: luyi0619 at gmail.com
                CC: llvm-bugs at lists.llvm.org

#include <iostream>
#include <tuple>

using Base = std::tuple<int,int>;

struct Derived : Base {

    template <class ...Ts>
    Derived(int x, Ts&&... ts): Base(std::forward<Ts>(ts)...), x(x) {
    }

    operator int () const {
        return x;
    }

    int x;
};

int main() {


    Derived d(1, 2, 3);

    Base b = static_cast<Base>(d);

    // he output is 0 1 in clang++, but the expected output is 2 3
    std::cout << std::get<0>(b) << " " << std::get<1>(b) << std::endl;

    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/20180816/4e393b05/attachment.html>


More information about the llvm-bugs mailing list