template<int sz>
struct xxx_t {
        char foo[sz];
        char bar[0];
};

int main(int argc, char *argv[])
{
        xxx_t<0> xyz;
}

gcc -Wall foo.cpp -o foo
foo.cpp: In instantiation of ‘xxx_t<0>’:
foo.cpp:9:   instantiated from here
foo.cpp:3: error: creating array with size zero (‘0’)
foo.cpp: In function ‘int main(int, char**)’:
foo.cpp:9: warning: unused variable ‘xyz’

Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-
checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-
exceptions --enable-libgcj-multifile --enable-
languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-
home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux
Thread model: posix
gcc version 4.0.0 20050519 (Red Hat 4.0.0-8)

explicit zero sized array 'bar' compiles correctly, the template 
parameter 'sz' causes a compilation error when 0 is passed.

-- 
           Summary: array dimensioned to zero via template parameter yields
                    parse error
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: guido at grumpy-cat dot com
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to