http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53211

             Bug #: 53211
           Summary: range-based 'for' expression of type 'const int []'
                    has incomplete type
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: i.nix...@gmail.com


This code compiles successfully:
#include <iostream>

template<typename... Args>
void func(Args... ) {
   const int arr[] = {1,2,3,4}; // !!!!!!!!!!!!!!!!!!!!!
   for (auto it: arr) {
      std::cout << it << std::endl;
   }
}

int main() {
   func(1,2,3,4);
}

http://liveworkspace.org/code/d7f2c44576fbf6854d113e29f976faa4

But if I change the initialization way of 'arr' like this, I get the following
error:
#include <iostream>

template<typename... Args>
void func(Args... args) {
   const int arr[] = {args...}; // !!!!!!!!!!!!!!!!!!!!!
   for (auto it: arr) {
      std::cout << it << std::endl;
   }
}

int main() {
   func(1,2,3,4);
}

http://liveworkspace.org/code/722f90c75ea3aa56310c24fd2abeea50

> source.cpp: In function 'void func(Args ...)':
> source.cpp:6:18: error: range-based 'for' expression of type 'const int []' 
> has incomplete type

Reply via email to