Skip to content

Crash when inheriting with local_storage #1

@ArekPiekarz

Description

@ArekPiekarz

The following usage of derived te::poly with local_storage ends with a crash instead of printing "Circle":

#include "external/te/include/te.hpp"
#include <iostream>

struct Drawable : te::poly<Drawable, te::local_storage<16>> {
  using te::poly<Drawable, te::local_storage<16>>::poly;

  void draw(std::ostream &out) const {
    te::call([](auto const &self, auto &out) { self.draw(out); }, *this, out);
  }
};

struct Circle {
  void draw(std::ostream &out) const {
    out << "Circle\n";
  }
};

void draw(Drawable const &drawable) { drawable.draw(std::cout); }

int main() {
  draw(Circle{});
}

When we modify Circle to print its copy constructor:

struct Circle {
    Circle() = default;
    Circle(const Circle&) { std::cout << "Circle(const Circle&) ctor\n"; }
  void draw(std::ostream &out) const {
    out << "Circle\n";
  }
};

we get spammed with Circle(const Circle&) ctor in the console until it crashes.

Am I doing something wrong or is there a bug in te?

Environment
OS: Ubuntu 17.10 x64
Compiler: GCC 7.2 x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions