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

icpc bug enable_if

asd__asdqwe
Beginner
543 Views

Hello,

The following code doesn't compile with icpc 15.0.0.090 Build 20140723, with -std=c++11.

#include <cstdlib>
#include <typeinfo>
#include <iostream>
#include <type_traits>

struct A {
    double** m;
};

struct B {
    double* m;
};

template<class T, typename std::enable_if<std::is_pointer<T>::value>::type* = nullptr>
static inline void foo(T* const& pt) {
    std::cout << "bar 1" << std::endl;
}
template<class T, typename std::enable_if<!std::is_pointer<T>::value>::type* = nullptr>
static inline void foo(T* const& pt) {
    std::cout << "bar 2" << std::endl;
}

int main() {
    A a;
    foo(a.m);
    B b;
    foo(b.m);
}

On the other hand, with g++ and clang++, I get the expected output:

bar 1
bar 2

Thank you in advance for looking into this.

 

0 Kudos
4 Replies
Feilong_H_Intel
Employee
543 Views

Hi there,

I reproduced the problem.  And I'm entering it to our problem-tracking database.

Thanks.

0 Kudos
Feilong_H_Intel
Employee
542 Views

Engineering team is looking into this issue.  Meanwhile, they provided a temporary workaround for you.  See the code snippet below.

//template<class T, typename std::enable_if<std::is_pointer<T>::value>::type* = nullptr>
template<class T, typename std::enable_if<std::is_pointer<T>::value>::type* = (void*)0>
static inline void foo(T* const& pt) {
    std::cout << "bar 1" << std::endl;
}
//template<class T, typename std::enable_if<!std::is_pointer<T>::value>::type* = nullptr>
template<class T, typename std::enable_if<!std::is_pointer<T>::value>::type* = (void*)0>
static inline void foo(T* const& pt) {
    std::cout << "bar 2" << std::endl;
}

 

0 Kudos
asd__asdqwe
Beginner
542 Views

Hello,

Thank you for the workaround.

 

0 Kudos
asd__asdqwe
Beginner
542 Views

This still doesn't compile properly with icpc 15.0.2.132.

0 Kudos
Reply