public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53211] New: range-based 'for' expression of type 'const int []' has incomplete type
@ 2012-05-03 13:01 i.nixman at gmail dot com
  2012-05-03 13:18 ` [Bug c++/53211] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: i.nixman at gmail dot com @ 2012-05-03 13:01 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: i.nixman@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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53211] range-based 'for' expression of type 'const int []' has incomplete type
  2012-05-03 13:01 [Bug c++/53211] New: range-based 'for' expression of type 'const int []' has incomplete type i.nixman at gmail dot com
@ 2012-05-03 13:18 ` redi at gcc dot gnu.org
  2012-05-03 16:04 ` i.nixman at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-03 13:18 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-05-03
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-03 13:17:27 UTC ---
Confirmed, that's a bug.

It works if the array bound is given explicitly:

   const int arr[sizeof...(Args)] = {args...};


Reduced:

template<typename A, typename B>
  struct is_same { static const bool value = false; };

template<typename A>
  struct is_same<A, A> { static const bool value = true; };

template<typename... Args>
void func(Args... args) {
  int arr[] = {args...};
  static_assert(is_same<decltype(arr), int[sizeof...(Args)]>::value,
                "complete type");
}

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


for.cc: In instantiation of 'void func(Args ...) [with Args = {int, int, int,
int}]':
for.cc:15:16:   required from here
for.cc:10:3: error: static assertion failed: complete type
   static_assert(is_same<decltype(arr), int[sizeof...(Args)]>::value,
   ^


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53211] range-based 'for' expression of type 'const int []' has incomplete type
  2012-05-03 13:01 [Bug c++/53211] New: range-based 'for' expression of type 'const int []' has incomplete type i.nixman at gmail dot com
  2012-05-03 13:18 ` [Bug c++/53211] " redi at gcc dot gnu.org
@ 2012-05-03 16:04 ` i.nixman at gmail dot com
  2013-06-17 15:59 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: i.nixman at gmail dot com @ 2012-05-03 16:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from niXman <i.nixman at gmail dot com> 2012-05-03 16:04:26 UTC ---
This code also works:

#include <iostream>

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

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


I'm confused...


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53211] range-based 'for' expression of type 'const int []' has incomplete type
  2012-05-03 13:01 [Bug c++/53211] New: range-based 'for' expression of type 'const int []' has incomplete type i.nixman at gmail dot com
  2012-05-03 13:18 ` [Bug c++/53211] " redi at gcc dot gnu.org
  2012-05-03 16:04 ` i.nixman at gmail dot com
@ 2013-06-17 15:59 ` paolo.carlini at oracle dot com
  2013-06-17 16:41 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-17 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
The original testcase (in Comment #0) is fixed in 4.8.1 and mainline as
duplicate of PR56794.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53211] range-based 'for' expression of type 'const int []' has incomplete type
  2012-05-03 13:01 [Bug c++/53211] New: range-based 'for' expression of type 'const int []' has incomplete type i.nixman at gmail dot com
                   ` (2 preceding siblings ...)
  2013-06-17 15:59 ` paolo.carlini at oracle dot com
@ 2013-06-17 16:41 ` paolo.carlini at oracle dot com
  2013-06-18 22:21 ` paolo.carlini at oracle dot com
  2013-06-21  8:44 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-17 16:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
For comment #1, it looks like there is something wrong in
instantiation_dependent_expression_p: when finish_decltype_type calls it for
arr it returns false, where it seems obvious that it should be true.

This static_assert succeeds:

static_assert(sizeof(arr) == sizeof(int) * sizeof...(Args), "complete type");


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53211] range-based 'for' expression of type 'const int []' has incomplete type
  2012-05-03 13:01 [Bug c++/53211] New: range-based 'for' expression of type 'const int []' has incomplete type i.nixman at gmail dot com
                   ` (3 preceding siblings ...)
  2013-06-17 16:41 ` paolo.carlini at oracle dot com
@ 2013-06-18 22:21 ` paolo.carlini at oracle dot com
  2013-06-21  8:44 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-18 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|i.nixman at gmail dot com          |
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Comment #1 fixed in mainline so far.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53211] range-based 'for' expression of type 'const int []' has incomplete type
  2012-05-03 13:01 [Bug c++/53211] New: range-based 'for' expression of type 'const int []' has incomplete type i.nixman at gmail dot com
                   ` (4 preceding siblings ...)
  2013-06-18 22:21 ` paolo.carlini at oracle dot com
@ 2013-06-21  8:44 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-21  8:44 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.8.2

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed for 4.8.2 too.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-06-21  8:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-03 13:01 [Bug c++/53211] New: range-based 'for' expression of type 'const int []' has incomplete type i.nixman at gmail dot com
2012-05-03 13:18 ` [Bug c++/53211] " redi at gcc dot gnu.org
2012-05-03 16:04 ` i.nixman at gmail dot com
2013-06-17 15:59 ` paolo.carlini at oracle dot com
2013-06-17 16:41 ` paolo.carlini at oracle dot com
2013-06-18 22:21 ` paolo.carlini at oracle dot com
2013-06-21  8:44 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).