Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vulptex opened this issue Jul 10, 2023 · 0 comments
Open

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

vulptex opened this issue Jul 10, 2023 · 0 comments

Comments

@vulptex
Copy link

vulptex commented Jul 10, 2023

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>()'?"));
    };
  };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant