<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56406>56406</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
OpenMP -fopenmp fails with structured binding defined outside of the parallel region
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aminya
</td>
</tr>
</table>
<pre>
When `-fopenmp` is used, the structured bindings cannot be used inside the parallel region. This doesn't happen with `-fopenmp=libgomp`.
Here is a full reproduction using Clang 14:
https://godbolt.org/z/1a1GG5jdq
```
#include <tuple>
int main() {
// Fails with Clang -fopenmp
const auto [a, b] = std::tuple{1, 2};
//
// should do this instead:
// const auto a = std::get<0>(std::tuple{1, 2});
// const auto b = std::get<1>(std::tuple{1, 2});
int sum = 0;
#pragma omp parallel for
for (int i = 1; i < 10; i++) {
#pragma omp critical
sum += a + b;
}
}
```
The errors are:
```
<source>:17:16: error: reference to local binding 'a' declared in enclosing function 'main'
sum += a + b;
^
<source>:5:17: note: 'a' declared here
const auto [a, b] = std::tuple{1, 2};
^
<source>:17:20: error: reference to local binding 'b' declared in enclosing function 'main'
sum += a + b;
^
<source>:5:20: note: 'b' declared here
const auto [a, b] = std::tuple{1, 2};
^
2 errors generated.
Compiler returned: 1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VVFv2yAQ_jXkBTXC2ImTBz80Sdu9TNvDpD1jc7apCGSAV3W_fgduEqeNtlWaarn0iOG77767g9rK5-p7D4aSJbtp7QHM_oAmVZ4OHiThWxp6oD64oQmDA0lrZaQynaeNMMYGWkNaSZXxSkJafRBOaA2aOuiUNXP6rUc8acEbwstAe3FAR_RJhf7Cb77Tqu5sYjAnbEfY7Th-AgeRkqDtoCPswVmJhBAcnSMbutUCx6wg-cuWPoSDjzN-j29nZW11mFvX4ewX_mUie3hYPMofUz_o9-UdpzxXptEDhkXybRgOGkh-N92gTKB7oTCsFeFrSsrN-DvFZ_RM74XSfox1JHkK97SyscYHKoZgKVlsRBS9JosdOt2h8jJGkd-O7stNFj9zUu5IPnX2yu0bGr63g5aYBMwQKonZCiDkSa7Jygs-4pJEBwGVYFEFvvoDNb6-ZHcFub6GnL0H-Ywf0-CHfUJkr75jEg9OdHtBsbDOpdlad96PE-S4ijAqgSCPTTK3NGPJJnyT3kmSL5Ebp4JqhD6jxiexwn2IKaKBib0QBiMasU7G1UJM4zdsLXDOOmwEB6fUXd-Rb70dXJMKNr_NyjgscRgRouGgxbYyDfaspdoi9WNvI9ESq7CkEhotXGpuiiu1Tb3WDmZsPVwyFn_5rqAnD1ncXeW7OHKmeMTEUN9S6pH8f22hf-GVOHH2Dh3rD9Hxb1qOlCda1h-n5ZQaPxZwBwacCCBfzvkttpDS4FBNvGYMRC_YhZelPZNVLtf5WsyCChqqL3iOfv56OlBpez5q315YGG2rEJjaIaSbyrbXLqvZ4HT16vJAwKGeN3aPE61_Hv_d4C30CE3AqfJ-AI_GYlmw5ayvVnVTFpIvWyhlzjIoFi0v2lWxyBnIelXPtKhB-woFJpwbeKIJAm1UeqYqzjhnJVuyFc_yfM7WkkPOJSxZIWDVkIIBloyeRx7xVpu5KlGqh87jR6188OePwnvVGYDkDvExt711ldgr8yxmyXOVmP8G0zlGDg">