template argument array size interpreted as 0 
Author Message
 template argument array size interpreted as 0

Hello again,

another compiler bug:

warning C4200: nonstandard extension used : zero-sized array in
struct/union
Cannot generate copy-ctor or copy-assignment operator when
UDT contains a zero-sized array
T.cpp(35) : see reference to class template instantiation 'B<n>'
         being compiled
        with
        [
            n=0
        ]
T.cpp(36) : see reference to class template instantiation 'D<T>'
                   being compiled
T.cpp(18) : error C2229: class 'B<n>' has an illegal zero-sized array
        with
        [
            n=0
        ]

Obviously n should not be 0.
BTW: If you remove member a from B the code still issues the
warning but the compiler copy exactly C::Size bytes from d1 to d2.
Surprisingly it still works if you make the B's copy ctor non-trivial
by adding virtual functions.

// The code [T.cpp]
#include <iostream>

class A
{
public:
 A(){}

 A( const A& )
 {
  std::cout << "A::A(const A&)" << std::endl;
 }

Quote:
};

template < int n >
class B
{
 char array[n];
 A a;

Quote:
};

class C
{
public:
 enum {  Size = 1 };

Quote:
};

template < class T = C > class D
{
public:
 B <T::Size> foo;

Quote:
};

int main()
{
 D <> d1;
 D <> d2 = d1;

Quote:
}

thanks
-hg


Fri, 21 Jan 2005 09:05:41 GMT  
 template argument array size interpreted as 0
Fixed in the release I commonly refer to as 7.1 (but which will not ship
with that name).

D:\Documents and Settings\ronaldl>cl /EHsc t.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.2212.1 for
80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

t.cpp
Microsoft (R) Incremental Linker Version 7.10.2212.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:t.exe
t.obj

D:\Documents and Settings\ronaldl>t
A::A(const A&)

Ronald Laeremans
Visual C++ compiler and libraries team


Quote:
> Hello again,

> another compiler bug:

> warning C4200: nonstandard extension used : zero-sized array in
> struct/union
> Cannot generate copy-ctor or copy-assignment operator when
> UDT contains a zero-sized array
> T.cpp(35) : see reference to class template instantiation 'B<n>'
>          being compiled
>         with
>         [
>             n=0
>         ]
> T.cpp(36) : see reference to class template instantiation 'D<T>'
>                    being compiled
> T.cpp(18) : error C2229: class 'B<n>' has an illegal zero-sized array
>         with
>         [
>             n=0
>         ]

> Obviously n should not be 0.
> BTW: If you remove member a from B the code still issues the
> warning but the compiler copy exactly C::Size bytes from d1 to d2.
> Surprisingly it still works if you make the B's copy ctor non-trivial
> by adding virtual functions.

> // The code [T.cpp]
> #include <iostream>

> class A
> {
> public:
>  A(){}

>  A( const A& )
>  {
>   std::cout << "A::A(const A&)" << std::endl;
>  }
> };

> template < int n >
> class B
> {
>  char array[n];
>  A a;
> };

> class C
> {
> public:
>  enum {  Size = 1 };
> };

> template < class T = C > class D
> {
> public:
>  B <T::Size> foo;
> };

> int main()
> {
>  D <> d1;
>  D <> d2 = d1;
> }

> thanks
> -hg



Fri, 21 Jan 2005 11:16:19 GMT  
 template argument array size interpreted as 0

Quote:
> Fixed in the release I commonly refer to as 7.1 (but which will not ship
> with that name).

Any hints on when this will be available (roughly)?  I'm trying to
decide whether to shell out money for the 6.0 Intel compiler (which is
highly compliant) or wait for "7.1".

Thanks,

John



Sat, 22 Jan 2005 04:48:53 GMT  
 template argument array size interpreted as 0




Quote:
> > Fixed in the release I commonly refer to as 7.1 (but which will not ship
> > with that name).

Ok, I put my money on ".NET 2003".

Quote:
> Any hints on when this will be available (roughly)?  I'm trying to
> decide whether to shell out money for the 6.0 Intel compiler (which is
> highly compliant) or wait for "7.1".

Do you need it this year?

Quote:
> Thanks,

> John

Bo Persson



Sat, 22 Jan 2005 05:15:53 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Passing sizes of arrays without a separate argument for the length

2. Checking size of array argument

3. Call interpreted variable argument list

4. Dynamicly retrieving the size of an template array URGENT

5. template arguments used within a template function - how?

6. Template parameter conflicts with typedef in template argument

7. explicit template arguments to function templates

8. Differences between char array[SIZE] and char *array

9. Arrays [256][256] --- error Array size too large!

10. typedef with template arguments...

11. Template Default argument lookup

12. Template argument dependant default parameter

 

 
Powered by phpBB® Forum Software