http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55535
Bug #: 55535 Summary: Call to default constructor with overloaded subscript operator is interpreted as declaring/using array Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: ni...@penneman.org gcc version: Using built-in specs. COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.0-alpha20121125/g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20121125/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-4.8.0_alpha20121125/work/gcc-4.8-20121125/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.0-alpha20121125 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20121125/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.0-alpha20121125 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.0-alpha20121125/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.0-alpha20121125/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20121125/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --with-ppl --with-cloog --disable-ppl-version-check --with-cloog-include=/usr/include/cloog-ppl --enable-lto --enable-nls --without-included-gettext --with-system-zlib --enable-obsolete --disable-werror --enable-secureplt --enable-multilib --with-multilib-list=m32,m64 --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.8.0-alpha20121125/python --enable-checking=release --disable-libgcj --disable-libquadmath --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.8.0_alpha20121125' Thread model: posix gcc version 4.8.0-alpha20121125 20121125 (experimental) (Gentoo 4.8.0_alpha20121125) ==================== Command and output: $ g++ -fsyntax-only -Wall -Wextra voodoo.cxx voodoo.cxx: In function ‘void func()’: voodoo.cxx:12:20: error: size of array has non-integral type ‘Empty’ (Voodoo()[Empty()]) | Empty(); ^ voodoo.cxx:12:20: error: ‘type name’ declared as function returning an array voodoo.cxx:12:20: error: size of array has non-integral type ‘Empty’ voodoo.cxx:12:20: error: ‘type name’ declared as function returning an array ==================== Full source code of 'voodoo.cxx': struct Empty {}; struct Voodoo { Empty operator [](Empty); }; void func() { (Voodoo()[Empty()]); } ==================== It looks like gcc sees the type name (call to default constructor) followed by the subscript operator as using or declaring an array. Without the parentheses around "Voodoo()[Empty()]" makes the error go away. I don't see why the parentheses should cause functionally different behaviour. Because of that, and because the code passes syntax checking with clang 3.1, icc 13 and armcc, I assume it's just something odd in g++. I am however not 100% sure that the above code conforms to the C++ standard, simply because I'm not sure where to start looking. While the above example looks useless the code has been extracted and simplified from a >100k LOC boost/spirit-based parser where it did make sense. Compiling this code also fails on 4.5.4, 4.6.3 and 4.7.2. Note: (ancient) bug #13503 came up in 'possible duplicates' and looks slightly related http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13503