Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
7568 Discussions

Enum members are not visible to template specialization

ivan_d_
Beginner
416 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
416 Views

Hi Ivan,

What kind of error are you seeing?

Thanks,

Viet

ivan_d_
Beginner
416 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"

Melanie_B_Intel
Employee
416 Views

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

 

 

Reply