The code below fails to compile and giving the indicated error message. Based on the C++ standard, is this a compiler bug or my code is invalid? Is this related to C++ bug #21903?
$ gcc -v -save-temps -Wall -Werror test/noinherit/09.cpp Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4) /usr/lib/gcc/i486-linux-gnu/4.2.4/cc1plus -E -quiet -v -D_GNU_SOURCE test/noinherit/09.cpp -mtune=generic -Wall -Werror -fpch-preprocess -o 09.ii ignoring nonexistent directory "/usr/local/include/i486-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../i486-linux-gnu/include" ignoring nonexistent directory "/usr/include/i486-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.2 /usr/include/c++/4.2/i486-linux-gnu /usr/include/c++/4.2/backward /usr/local/include /usr/lib/gcc/i486-linux-gnu/4.2.4/include /usr/include End of search list. /usr/lib/gcc/i486-linux-gnu/4.2.4/cc1plus -fpreprocessed 09.ii -quiet -dumpbase 09.cpp -mtune=generic -auxbase 09 -Wall -Werror -version -fstack-protector -fstack-protector -o 09.s GNU C++ version 4.2.4 (Ubuntu 4.2.4-1ubuntu4) (i486-linux-gnu) compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu4). GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129366 Compiler executable checksum: a9a6f696028630a438a334c3f20809c8 test/noinherit/09.cpp: In instantiation of const bool O::B<int>::sized: test/noinherit/09.cpp:9: instantiated from here test/noinherit/09.cpp:5: error: the default argument for parameter 1 of static bool O::B<T>::set(T, bool) [with T = int] has not yet been parsed struct O { template<typename T> struct B { static bool set(T x, bool b = true) { return b; } static const bool sized = sizeof(set(T())) == 0; // line 5 }; struct D: public B<int> {}; static const bool int_sized = B<int>::sized; // line 9 }; void x () { O::D d; d.set(1); } int main() { x(); return 0; } -- Summary: Default argument of nested template function causes a compile-time error Product: gcc Version: 4.2.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: lorcaminiti at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43561