Posts

Post not yet marked as solved
0 Replies
690 Views
Hi all, I came across a strange compiler error that occurs when I use structured binding in combination with an OpenMP parallel region. A minimal example code is as follows: #include <tuple> #ifdef OPENMMP_ #include <omp.h> #endif auto create() {   int    a = 10;   double b = 1.0;   return std::tie(a,b); } int main() {   auto [a, b] = create();   double vector[100]; #pragma omp parallel for   for (int i=0; i<a; ++i)     vector[i] = b; } I am using Apple clang version: Apple clang version 14.0.0 (clang-1400.0.29.202) Target: arm64-apple-darwin22.2.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin When compiled with g++ -std=c++17 test.cxx I get no the compiler error and the executable works. When compiled with g++ -Xclang -fopenmp -std=c++17 test.cxx I get the compiler error: test.cxx:22:19: error: reference to local binding 'a' declared in enclosing function 'main'   for (int i=0; i<a; ++i)                   ^ test.cxx:17:9: note: 'a' declared here   auto [a, b] = create();         ^ test.cxx:23:17: error: reference to local binding 'b' declared in enclosing function 'main'     vector[i] = b;                 ^ test.cxx:17:12: note: 'b' declared here   auto [a, b] = create();            ^ 2 errors generated. This error does not occur when I compile the code with g++-12 from the Homebrew project. Any help is appreciated.
Posted
by mmoelle1.
Last updated
.