https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124197

            Bug ID: 124197
           Summary: template-for doesn't compile with -Wshadow and -Werror
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: uchanahome8 at gmail dot com
  Target Milestone: ---

Hi, I am using the gcc-trunk on compiler explorer:
https://godbolt.org/z/Evqf8E946 and was able to reproduce this on local build
of master branch as well.

Code:
```
#include <iostream>
#include <utility>
#include <array>

template <std::size_t N>
consteval auto make_array() {
    std::array<std::size_t, N> arr;
    for (std::size_t i = 0; i < N; ++i)
        arr[i] = i;
    return arr;
}

int main() {
    template for (auto I: make_array<3>()) {
        std::cout << I << std::endl;
    }
    return 0;
}
```

Flags:
```
-std=c++26   -Werror -Wshadow
```

Compiler: `gcc trunk`

Error:
```
<source>: In function 'int main()':
<source>:14:24: error: declaration of 'I' shadows a previous local
[-Werror=shadow]
   14 |     template for (auto I: make_array<3>()) {
      |                        ^
<source>:14:24: note: shadowed declaration is here
<source>:14:24: error: declaration of 'I' shadows a previous local
[-Werror=shadow]
<source>:14:24: note: shadowed declaration is here
<source>:14:24: error: declaration of 'I' shadows a previous local
[-Werror=shadow]
<source>:14:24: note: shadowed declaration is here
cc1plus: all warnings being treated as errors
Compiler returned: 1
```

Reply via email to