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

            Bug ID: 106697
           Summary: error: range-based 'for' expression of type 'const int
                    []' has incomplete type
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johanneskauffmann at hotmail dot com
  Target Milestone: ---

Originally reported as https://bugreports.qt.io/browse/QTBUG-105227.

GCC 13 fails to compile this code, which was working fine in GCC 12 and 11:

```
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>

class tst_ContainerApiSymmetry
{
public:
    template <typename Container>
    void ranged_ctor_non_associative_impl() const;

    void ranged_ctor_std_vector_int() {
ranged_ctor_non_associative_impl<std::vector<int>>(); }
};

template <typename Container>
void tst_ContainerApiSymmetry::ranged_ctor_non_associative_impl() const
{
    using V = typename Container::value_type;
    const V values1[] = { V(0), V(1), V(2), V(0) };

    const Container c5 = [&] {
        {
            std::stringstream ss;
            for (auto &v : values1)
                ss << v << ' ';
            ss.seekg(0);
            return Container(std::istream_iterator<V>{ss},
                             std::istream_iterator<V>{});
        }
    }();
}

int main() {
    tst_ContainerApiSymmetry test;
    test.ranged_ctor_std_vector_int();
    return 0;
}
```

It fails with:
```
qttest.cpp: In instantiation of ‘void
tst_ContainerApiSymmetry::ranged_ctor_non_associative_impl() const [with
Container = std::vector<int>]’:
qttest.cpp:12:91:   required from here
qttest.cpp:24:13: error: range-based ‘for’ expression of type ‘const int []’
has incomplete type
   24 |             for (auto &v : values1)
      |             ^~~
```

Tested with:
```
Using built-in specs.
COLLECT_GCC=/opt/gcc-20220819/bin/g++
COLLECT_LTO_WRAPPER=/opt/gcc-20220819/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-src-git/configure --enable-languages=c,c++
--disable-multilib --enable-shared --prefix=/opt/gcc-20220819
--without-included-gettext --enable-threads=posix --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-default-pie --with-system-zlib
--with-target-system-zlib=auto --enable-cet --with-abi=m64
--without-cuda-driver --enable-lto --enable-ld=yes
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20220819 (experimental) (GCC)
```

It also wasn't working with GCC 13 20220627.
  • [Bug c++/106697] New: er... johanneskauffmann at hotmail dot com via Gcc-bugs

Reply via email to