[LLVMbugs] [Bug 19218] New: in-class initialization for this pointer doesn't work on CRTP.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Mar 20 21:30:30 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19218

            Bug ID: 19218
           Summary: in-class initialization for this pointer doesn't work
                    on CRTP.
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: littlekid87 at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

template <class Derived>
class base
{
    Derived* _ptr{static_cast<Derived*>(this)};
};

class test
    : public base<test>
{
};

The above code doesn't compile.

However if one is to write a custom constructor as follow it would work:

template <class Derived>
class base
{
public:
    base() : _ptr{static_cast<Derived>(this)} {}
private:
    Derived* _ptr{};
};

Not sure if true, but I vaguely remember that in-class initialization should
have the same side-effect as constructor initialization lists.

-- 
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/20140321/a02d8e52/attachment.html>


More information about the llvm-bugs mailing list