Skip to content

static inline T* error does not work @compile time #554

@vulptex

Description

@vulptex

Expected Behavior

See "detailed" not_bound errors

Actual Behavior

See nothing, only a linker error

gcc 12.2
clang 15

similar to:
#458

Question

I wonder myself why we have the following code (and why its so magic :-D)

template <class T>
struct abstract_type {
  struct is_not_bound {
    operator T*() const {
      using constraint_not_satisfied = is_not_bound;
      return constraint_not_satisfied{}.error();
    }
    // clang-format off
    static inline T*
 error(_ = "type is not bound, did you forget to add: 'di::bind<interface>.to<implementation>()'?");
    // clang-format on
  };
  template <class TName>
  struct named {
    struct is_not_bound {
      operator T*() const {
        using constraint_not_satisfied = is_not_bound;
        return constraint_not_satisfied{}.error();
      }
      // clang-format off
      static inline T*
   error(_ = "type is not bound, did you forget to add: 'di::bind<interface>.named(name).to<implementation>()'?");
      // clang-format on
    };
  };
};

How about replacing with a static_assert?

template <class T>
struct abstract_type {
  struct is_not_bound {
    static_assert(T::_,  "type is not bound, did you forget to add: 'di::bind<interface>.to<implementation>()'?");
  };
  template <class TName>
  struct named {
    struct is_not_bound {
     static_assert(T::_ || TName::_, "type is not bound, did you forget to add: 'di::bind<interface>.named(name).to<implementation>()'?"));
    };
  };
};

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