Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
145 Views

Enum members are not visible to template specialization

I have a code example which originates from llvm source code but modified to clearly provide the issue.

It compiles fine with clang but fails with icl. Here's the code:

#include <type_traits>

template <typename E, typename Enable = void>
struct is_valid : std::false_type {};

template <typename E>
struct is_valid<E, typename std::enable_if<sizeof(E::EnumMember) >= 0>::type> : std::true_type {};

template <typename E, typename = typename std::enable_if<is_valid<E>::value>::type>
void function(const E &myEnum) {
  return;
}

enum MyEnum {
  EnumMember = 0
};

int main() {
  MyEnum myEnum;
  function(myEnum);
}

 

Intel Compiler XE 2018, Windows

0 Kudos
3 Replies
Highlighted
Moderator
145 Views

Hi Ivan,

What kind of error are you seeing?

Thanks,

Viet

0 Kudos
Highlighted
Beginner
145 Views

With this example:

icl_error_template.cpp(20): error: no instance of function template "function" matches the argument list
            argument types are: (MyEnum)
    function(myEnum);
    ^
icl_error_template.cpp(10): note: this candidate was rejected because at least one template argument could not be deduced
  void function(const E &myEnum) {
       ^

compilation aborted for icl_error_template.cpp (code 2)

In general errors can be different but the source of them is that "sizeof(E::EnumMember)" is considered non-existent which is not true. Easy way to see that is to change condition to "sizeof(E::EnumMember) < 0"

0 Kudos
Highlighted
145 Views

I can reproduce this failure, I opened CMPLRS-49370 in our internal bug tracking database.  Thank you for reporting it!  --Melanie

 

 

0 Kudos