2

It seems to me that clang has some problems when using omp collapse in template function.

I've attached a minimal example. Clang (9, 10, 11) can't compile it, while gcc compiles it just fine. Is this a compiler error or is my code doing something illegal? Making this function non template or dropping the collapse clause makes it compile just fine.

#include <vector>
#include <iostream>

template <typename T>
void test(const std::vector<int> begin_vec) {
  #pragma omp parallel for collapse(2)
  for (int n = begin_vec.at(0); n < 0; n++) {
  for (int h = begin_vec.at(1); h < 1; h++) {
  for (int w = begin_vec.at(2); w < 2; w++) {
      std::cout << n + h + w << std::endl;
  }}}
}

int main() {
  test<int>({0,0,0});
}

To compile clang++-10 -fopenmp test.cpp

For me, clang produces the following error

test.cpp:9:16: error: 'this' argument to member function 'at' has type 'const std::vector<int>', but function is not marked const
  for (int h = begin_vec.at(1); h < 1; h++) {
               ^~~~~~~~~
test.cpp:16:3: note: in instantiation of function template specialization 'test<int>' requested here
  test<int>({0,0,0});
  ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:1092:7: note: 'at' declared here
      at(size_type __n)
      ^

(I've also tried to use libc++, but it didn't change anything)

S. Kaczor
  • 401
  • 3
  • 8

0 Answers0