The following code snipped causes an internal compiler error: === #include <algorithm> #include <iostream> #include <iterator> #include <memory> #include <string> using namespace std; class Distribution { public: Distribution() { } virtual ~Distribution() { } virtual double sample(); }; double Distribution::sample() { return rand(); } typedef double (Distribution::* Pstd_mem)(); int main() { Distribution* rng(new Distribution()); Pstd_mem ptr = &Distribution::sample; cout << (rng->*ptr)() << endl; // works generate_n(ostream_iterator<double>(cout, "\n"), 100, mem_fun(rng->*ptr)); // BUG return 0; } === Best wishes, Matthias
Created attachment 10937 [details] Source code This was compiled as follows: g++ -v -save-temps smalltest.cc Using built-in specs. Target: i686-pc-linux-gnu Configured with: /tmp/gcc-4.0.2/configure --prefix=/home/heiler/server/gcc --enable-threads Thread model: posix gcc version 4.0.2 /server/projekte/heiler/gcc/bin/../libexec/gcc/i686-pc-linux-gnu/4.0.2/cc1plus -E -quiet -v -iprefix /server/projekte/heiler/gcc/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/ -D_GNU_SOURCE smalltest.cc -mtune=pentiumpro -fpch-preprocess -o smalltest.ii ignoring nonexistent directory "/server/projekte/heiler/gcc/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../i686-pc-linux-gnu/include" ignoring duplicate directory "/home/heiler/server/gcc/lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../include/c++/4.0.2" ignoring duplicate directory "/home/heiler/server/gcc/lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../include/c++/4.0.2/i686-pc-linux-gnu" ignoring duplicate directory "/home/heiler/server/gcc/lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../include/c++/4.0.2/backward" ignoring duplicate directory "/home/heiler/server/gcc/lib/gcc/i686-pc-linux-gnu/4.0.2/include" ignoring nonexistent directory "/home/heiler/server/gcc/lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /server/projekte/heiler/gcc/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../include/c++/4.0.2 /server/projekte/heiler/gcc/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../include/c++/4.0.2/i686-pc-linux-gnu /server/projekte/heiler/gcc/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../include/c++/4.0.2/backward /server/projekte/heiler/gcc/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/include /usr/local/include /home/heiler/server/gcc/include /usr/include End of search list. /server/projekte/heiler/gcc/bin/../libexec/gcc/i686-pc-linux-gnu/4.0.2/cc1plus -fpreprocessed smalltest.ii -quiet -dumpbase smalltest.cc -mtune=pentiumpro -auxbase smalltest -version -o smalltest.s GNU C++ version 4.0.2 (i686-pc-linux-gnu) compiled by GNU C version 3.3.2 20031022 (Red Hat Linux 3.3.2-1). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 smalltest.cc: In function 'int main()': smalltest.cc:37: internal compiler error: in gimplify_expr, at gimplify.c:4186 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Created attachment 10938 [details] Source code after preprocessing.
Hmm, in 4.0.3 I get: t.cc: In function ‘int main()’: t.cc:35: error: no matching function for call to ‘mem_fun(double (Distribution::)())’
(In reply to comment #3) > Hmm, in 4.0.3 I get: > t.cc: In function ‘int main()’: > t.cc:35: error: no matching function for call to ‘mem_fun(double > (Distribution::)())’ > Interesting. What happens if you remove the mem_fun call: === generate_n(ostream_iterator<double>(cout, "\n"), 100, rng->*ptr); === my gcc still reports an internal compiler error. Matthias
> Interesting. What happens if you remove the mem_fun call: > === > generate_n(ostream_iterator<double>(cout, "\n"), 100, rng->*ptr); > === > my gcc still reports an internal compiler error. Yes I can reproduce it then, reducing.
Confirmed, reduced testcase: template< typename _Generator> int generate_n(_Generator __gen); struct Distribution { }; typedef double (Distribution::* Pstd_mem)(); int main(void) { Distribution* rng; Pstd_mem ptr; generate_n(rng->*ptr); }
Subject: Bug 26496 Author: mmitchel Date: Wed May 31 20:03:12 2006 New Revision: 114278 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114278 Log: PR c++/27801 * call.c (perform_implicit_conversion): Do not actually perform conversions in templates. PR c++/26496 * call.c (resolve_args): Check for invalid uses of bound non-static member functions. * init.c (build_offset_ref): Return error_mark_node for errors. PR c++/27385 * decl.c (reshape_init): Robustify. (reshape_init_array_1): Likewise. PR c++/27801 * g++.dg/template/cond6.C: New test. PR c++/26496 * g++.dg/template/crash51.C: New test. * g++.old-deja/g++.mike/net36.C: Tweak error markers. PR c++/27385 * g++.dg/init/array20.C: New test. Added: trunk/gcc/testsuite/g++.dg/init/array20.C trunk/gcc/testsuite/g++.dg/template/cond6.C trunk/gcc/testsuite/g++.dg/template/crash51.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c trunk/gcc/cp/decl.c trunk/gcc/cp/init.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.old-deja/g++.mike/net36.C
Subject: Bug 26496 Author: mmitchel Date: Wed May 31 20:03:27 2006 New Revision: 114279 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114279 Log: PR c++/27801 * call.c (perform_implicit_conversion): Do not actually perform conversions in templates. PR c++/26496 * call.c (resolve_args): Check for invalid uses of bound non-static member functions. * init.c (build_offset_ref): Return error_mark_node for errors. PR c++/27385 * decl.c (reshape_init): Robustify. (reshape_init_array_1): Likewise. PR c++/27801 * g++.dg/template/cond6.C: New test. PR c++/26496 * g++.dg/template/crash51.C: New test. * g++.old-deja/g++.mike/net36.C: Tweak error markers. PR c++/27385 * g++.dg/init/array20.C: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/g++.dg/init/array20.C branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/cond6.C branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/crash51.C Modified: branches/gcc-4_1-branch/gcc/cp/call.c branches/gcc-4_1-branch/gcc/cp/decl.c branches/gcc-4_1-branch/gcc/cp/init.c branches/gcc-4_1-branch/gcc/testsuite/g++.old-deja/g++.mike/net36.C
Subject: Bug 26496 Author: mmitchel Date: Wed May 31 20:07:35 2006 New Revision: 114280 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114280 Log: PR c++/27801 * call.c (perform_implicit_conversion): Do not actually perform conversions in templates. PR c++/26496 * call.c (resolve_args): Check for invalid uses of bound non-static member functions. * init.c (build_offset_ref): Return error_mark_node for errors. PR c++/27385 * decl.c (reshape_init): Robustify. (reshape_init_array_1): Likewise. PR c++/27801 * g++.dg/template/cond6.C: New test. PR c++/26496 * g++.dg/template/crash51.C: New test. * g++.old-deja/g++.mike/net36.C: Tweak error markers. PR c++/27385 * g++.dg/init/array20.C: New test. Modified: branches/gcc-4_1-branch/gcc/cp/ChangeLog branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Fixed in 4.1.2, 4.2.0.
Fixed in GCC-4.1.2