This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/77367] New: Duck-typing error not detected when using CRTP


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77367

            Bug ID: 77367
           Summary: Duck-typing error not detected when using CRTP
           Product: gcc
           Version: 6.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yuhang_tang at brown dot edu
  Target Milestone: ---

The following code was able to pass compilation & linking, yet the Derived::B()
function is not defined. Since the cast is static I would expect that the
compiler could find that there is not a definition of
static_cast<Derived&>(*this).B() and raise an error.

template<class Derived>
struct Base {
    void A() { static_cast<Derived&>(*this).A(); }
    void B() { static_cast<Derived&>(*this).B(); }
};

struct Derived : Base<Derived> {
    void A() {}
    //void B() {}
};

int main() {
    Derived d;
    Base<Derived> &b = d;
    b.A();
    b.B();
}

This resulted in the compiled binary hanging forever in Fedora 24 Kernel 4.6.5.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]