Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Enum members are not visible to template specialization

ivan_d_
Beginner
958 Views

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
Viet_H_Intel
Moderator
958 Views

Hi Ivan,

What kind of error are you seeing?

Thanks,

Viet

0 Kudos
ivan_d_
Beginner
958 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
Melanie_B_Intel
Employee
958 Views

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

 

 

0 Kudos
Reply