0

I have a trait class that implements some interface depending on whether its template parameter type is defined or not:

template<class T, class=void>
struct traits {
   // impl for undefined types
};

template<class T>
struct traits<T, decltype(void(sizeof(T)))> {
   // impl for defined types
};

This works fine, however I get an error when the type is defined but has a member with incomplete type, for instance when passing an instance of some class template where the template parameter is itself undefined.

Therefore I would like to know if there exists some SFINAE-fu to detect defined types with incomplete fields.

max
  • 1,048
  • 10
  • 20
  • 2
    Unfortunately I'm pretty sure the answer is "no". Though I wonder what could be the use of knowing that a type is "partially" defined. – Quentin Nov 23 '18 at 12:31
  • Thanks. A bit of context: I have a class implementing recursive algebraic datatypes on top of some `std::variant`-like type. I use the trait class to automatically detect and box/unbox recursive types, which are undefined at the time of the ADT template instantiation. This works perfectly and I use it to represent an abstract syntax tree. But now I want to mix in CRTP in order to attach arbitrary info to my AST nodes and the above problem happens. – max Nov 23 '18 at 12:57
  • For some reason the specialization for defined types is selected, which triggers an error related to some field having undefined type. I would have thought this would be a substitution error and the specialization for undefined types would be selected instead, but this does not seems to be the case, at least with a recent clang. – max Nov 23 '18 at 13:00
  • `is_complete` traits is dangerous as it can easily break ODR (-> ill formed program NDR :-/). – Jarod42 Nov 23 '18 at 15:34
  • related: https://stackoverflow.com/questions/1625105/how-to-write-is-complete-template – max Nov 26 '19 at 06:40

0 Answers0