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

Type Deduction Failure - Possible Bug

Alex_B_3
Beginner
270 Views

Hello,

I have found a possible type-deduction bug, reproducible in Intel 18.0.1, 18.0.2, and 19.0.0.046. Here is a small code snippet demonstrating the issue:

https://gist.github.com/abrooks98/020b3a499e2dbedd0c7cc81e50982152

#include <vector>
#include <utility>
#include <stdio.h>

template<typename T>
class myvector : public std::vector<T> {};

template<typename T>
struct check_for
{
  template<typename U>
  static constexpr bool _data(U*, decltype(std::declval<U>().data())* = nullptr) { return true; }
  template<typename U>
  static constexpr bool _data(...) { return false; }

  template<typename U>
  static constexpr bool _get_allocator(U*, decltype(std::declval<U>().get_allocator())* = nullptr) { return true; }
  template<typename U>
  static constexpr bool _get_allocator(...) { return false; }

  static constexpr bool data = _data<T>(nullptr);
  static constexpr bool get_allocator = _get_allocator<T>(nullptr);
};

int main(int argc, char** argv)
{
  printf("Check type 'bool'             for function 'data': %d\n", check_for<bool>::data);
  printf("Check type 'std::vector<int>' for function 'data': %d\n", check_for<std::vector<int>>::data);
  printf("Check type 'myvector<int>'    for function 'data': %d\n", check_for<myvector<int>>::data);

  printf("Check type 'bool'             for function 'get_allocator': %d\n", check_for<bool>::get_allocator);
  printf("Check type 'std::vector<int>' for function 'get_allocator': %d\n", check_for<std::vector<int>>::get_allocator);
  printf("Check type 'myvector<int>'    for function 'get_allocator': %d\n", check_for<myvector<int>>::get_allocator);

  decltype(std::declval<std::vector<int>>().get_allocator()) a;

  int* b = a.allocate(10);
  printf("%p\n", b);
  a.deallocate(b, 10);

  return 0;
}

The issue is that check_for<std::vector<int>>::get_allocator should return true, but it does not. The type-deduction does work for some functions, however. For example, check_for<std::vector<int>>::data returns true. This issue is not present in GCC (tested with 4.9.3 and 7.1.0) or Clang (tested with 3.9.0 and 4.0.0)

0 Kudos
3 Replies
Viet_H_Intel
Moderator
270 Views

Hi Alex,

Can you provide us your command line options?

Thanks,

Viet

0 Kudos
Alex_B_3
Beginner
270 Views

Hi Viet,

 

Of course. I am simply using:

icpc -std=c++11 main.cpp

That is also the only flag I used to test with other compilers as well.

Thanks,

Alex

0 Kudos
Viet_H_Intel
Moderator
270 Views

Thanks Alex,

I've filed a bug report with our developer. The internal tracking number is: CMPLRS-51086

Viet

0 Kudos
Reply