X-Bugzilla-Reason: CC This error happens in this case:
template <class T_> class SizeFor_{ public: enum {Size = 2}; }; template <class V_> class Test { public: template <class T_> void test_array(T_ tag, V_ (&arr)[SizeFor_<T_>::Size]) { } }; (Full test case in the end of the message) It happens when declaring an array, whose bounds is given by a static constant, in a template method that is inside a template method. The problem also happens when the static constant is a sizeof, or a static const size_t. Test case: class X {}; class Y {}; class Z {}; //template <class T_> class SizeFor_; //template<> class SizeFor_<X> { public: enum {Size = 1}; }; //template<> class SizeFor_<Y> { public: enum {Size = 2}; }; //template<> class SizeFor_<Z> { public: enum {Size = 3}; }; template <class T_> class SizeFor_ { public: enum {Size = 2}; }; // This works (template method of non-template class) /* class Test { public: template <class T_> void test_array(T_, int (&arr)[SizeFor_<T_>::Size]) { for (int i = 0; i < SizeFor_<T_>::Size; ++i) { arr[i] += 1; } } }; int main() { int y[2] = {2, 3}; Test p2; p2.test_array(Y(), y); return 0; } */ // This works: (non-template method of template clas) /* template <class V_> class Test { public: void test_array(Y tag, V_ (&arr)[SizeFor_<Y>::Size]) { for (int i = 0; i < SizeFor_<Y>::Size; ++i) { arr[i] += 1; } } }; int main() { int y[2] = {2, 3}; Test<int> p2; p2.test_array(Y(), y); return 0; } */ // This one does not compile (template method of template class): template <class V_> class Test { public: template <class T_> void test_array(T_ tag, V_ (&arr)[SizeFor_<T_>::Size]) { for (int i = 0; i < SizeFor_<T_>::Size; ++i) { arr[i] += 1; } } }; int main() { int y[2] = {2, 3}; Test<int> p2; p2.test_array(Y(), y); return 0; } The compiler output is: Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../Sources/configure --with-ld=/home/users/ama/Shared/amd64.redhat/binutils-2.17/bin/ld --disable-multilib --prefix=/home/users/ama/Build/gcc-4.2.1/Binaries-amd64.redhat : (reconfigured) ../Sources/configure --with-ld=/home/users/ama/Shared/amd64.redhat/binutils-2.17/bin/ld --disable-multilib --prefix=/home/users/ama/Build/gcc-4.2.1/Binaries-amd64.redhat Thread model: posix gcc version 4.2.1 ... cc1plus -fpreprocessed test3.ii -quiet -dumpbase test3.cpp -mtune=generic -auxbase test3 -version -o test3.s GNU C++ version 4.2.1 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.2.1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: b0e2ae18bf4812f9f66b45414d2388db test3.cpp: In instantiation of 'Test<int>': test3.cpp:81: instantiated from here test3.cpp:70: error: array bound is not an integer constant test3.cpp: In function 'int main()': test3.cpp:82: error: 'class Test<int>' has no member named 'test_array' -- Summary: Bogus "array bound is not an integer constant" for parameter in template method of template class Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: critical Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: e dot tadeu at gmail dot com GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33553