Skip to content

the following code (from README, use with boostext::di) does not compile (clang 17, gcc 11) #41

@ralphjzhang

Description

@ralphjzhang
#include <boost/di.hpp>
#include <boost/te.hpp>
#include <iostream>

namespace te = boost::te;
namespace di = boost::di;

struct Drawable : te::poly<Drawable> {
  using te::poly<Drawable>::poly;

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

struct Rect {
  void draw(std::ostream &out) const { out << "Rect" << std::endl; }
};

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

class Example {
public:
  Example(Drawable const drawable, std::ostream &out)
      : drawable{drawable}, out{out} {}

  void draw() { drawable.draw(out); }

private:
  Drawable const drawable;
  std::ostream &out;
};

int main() {
  const auto injector = di::make_injector(di::bind<Drawable>.to<Circle>(),
                                          di::bind<std::ostream>.to(std::cout));

  injector.create<Example>().draw(); // prints Circle
}

Expected Behavior

Actual Behavior

clang error:

poly.cpp:40:12: warning: 'create' is deprecated: creatable constraint not satisfied [-Wdeprecated-declarations]
40 | injector.create().draw(); // prints Circle
| ^
inc/boost/di.hpp:2778:3: note: 'create' has been explicitly marked deprecated here
2778 | create
| ^
poly.cpp:40:12: warning: 'create<Example, 0>' is deprecated: creatable constraint not satisfied [-Wdeprecated-declarations]
40 | injector.create().draw(); // prints Circle
| ^
inc/boost/di.hpp:2775:3: note: 'create<Example, 0>' has been explicitly marked deprecated here
2775 | __BOOST_DI_DEPRECATED("creatable constraint not satisfied")
| ^
inc/boost/di.hpp:33:38: note: expanded from macro '__BOOST_DI_DEPRECATED'
33 | #define _BOOST_DI_DEPRECATED(...) [[deprecated(VA_ARGS)]]
| ^
inc/boost/di.hpp:1241:4: error: inline function 'boost::di::concepts::type::has_to_many_constructor_parameters::max<10>::error' is not defined [-Werror,-Wundefined-inline]
1241 | error(
= "increase BOOST_DI_CFG_CTOR_LIMIT_SIZE value or reduce number of constructor parameters");
| ^
inc/boost/di.hpp:1237:43: note: used here
1237 | return constraint_not_satisfied{}.error();
| ^
2 warnings and 1 error generated.

gcc linking error:

/usr/bin/ld: /tmp/ccU8Y1RZ.o: in function boost::ext::di::v1_3_0::concepts::type<Example>::has_to_many_constructor_parameters::max<10>::operator Example*() const': poly.cpp:(.text._ZNK5boost3ext2di6v1_3_08concepts4typeI7ExampleE34has_to_many_constructor_parameters3maxILi10EEcvPS5_Ev[_ZNK5boost3ext2di6v1_3_08concepts4typeI7ExampleE34has_to_many_constructor_parameters3maxILi10EEcvPS5_Ev]+0x3b): undefined reference to boost::ext::di::v1_3_0::concepts::type::has_to_many_constructor_parameters::max<10>::error(boost::ext::di::v1_3_0::_)'
collect2: error: ld returned 1 exit status

Steps to Reproduce the Problem

Specifications

  • Version:
  • Platform:
  • Subsystem:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions