public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "e dot tadeu at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/33553] New: Bogus "array bound is not an integer constant" for parameter in template method of template class Date: Tue, 25 Sep 2007 15:02:00 -0000 [thread overview] Message-ID: <bug-33553-15147@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2007-09-25 15:02 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-09-25 15:02 e dot tadeu at gmail dot com [this message] 2007-09-25 15:04 ` [Bug c++/33553] " e dot tadeu at gmail dot com 2007-09-25 15:23 ` e dot tadeu at gmail dot com 2007-09-25 23:29 ` [Bug c++/33553] [4.2/4.3 Regression] " pinskia at gcc dot gnu dot org 2007-09-25 23:32 ` pinskia at gcc dot gnu dot org 2007-09-27 8:58 ` [Bug c++/33553] [4.1/4.2/4.3 " jakub at gcc dot gnu dot org 2007-09-28 4:15 ` mmitchel at gcc dot gnu dot org 2007-10-09 19:30 ` mmitchel at gcc dot gnu dot org 2008-01-25 15:48 ` rguenth at gcc dot gnu dot org 2008-01-30 18:26 ` ebotcazou at gcc dot gnu dot org 2008-01-30 21:55 ` bangerth at dealii dot org 2008-01-30 22:14 ` mmitchel at gcc dot gnu dot org 2008-02-01 17:04 ` jsm28 at gcc dot gnu dot org 2008-02-04 12:56 ` jakub at gcc dot gnu dot org 2008-02-04 15:48 ` jakub at gcc dot gnu dot org 2008-02-05 20:05 ` jakub at gcc dot gnu dot org 2008-02-05 20:08 ` [Bug c++/33553] [4.1/4.2 " jakub at gcc dot gnu dot org 2008-05-19 20:29 ` jsm28 at gcc dot gnu dot org 2008-07-04 22:51 ` [Bug c++/33553] [4.2 " jsm28 at gcc dot gnu dot org 2009-03-30 22:28 ` jsm28 at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-33553-15147@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).