Bug 26496 - [4.0 Regression] Pointer to member function
Summary: [4.0 Regression] Pointer to member function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.2
: P3 normal
Target Milestone: 4.1.2
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code, monitored
Depends on:
Blocks:
 
Reported: 2006-02-28 13:15 UTC by Matthias Heiler
Modified: 2007-02-03 16:19 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3 4.1.2 4.2.0
Known to fail: 3.4.0 4.0.0 4.1.0 4.1.1 4.0.3
Last reconfirmed: 2006-09-03 21:39:59


Attachments
Source code (303 bytes, text/plain)
2006-02-28 13:17 UTC, Matthias Heiler
Details
Source code after preprocessing. (90.47 KB, text/plain)
2006-02-28 13:18 UTC, Matthias Heiler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Heiler 2006-02-28 13:15:41 UTC
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
Comment 1 Matthias Heiler 2006-02-28 13:17:37 UTC
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.
Comment 2 Matthias Heiler 2006-02-28 13:18:28 UTC
Created attachment 10938 [details]
Source code after preprocessing.
Comment 3 Andrew Pinski 2006-02-28 13:30:50 UTC
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::)())’
Comment 4 Matthias Heiler 2006-02-28 13:42:29 UTC
(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
Comment 5 Andrew Pinski 2006-02-28 13:46:45 UTC
> 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.
Comment 6 Andrew Pinski 2006-02-28 17:16:24 UTC
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);
}
Comment 7 Mark Mitchell 2006-05-31 20:03:24 UTC
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

Comment 8 Mark Mitchell 2006-05-31 20:03:44 UTC
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

Comment 9 Mark Mitchell 2006-05-31 20:08:43 UTC
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

Comment 10 Mark Mitchell 2006-05-31 20:12:26 UTC
Fixed in 4.1.2, 4.2.0.
Comment 11 Gabriel Dos Reis 2007-02-03 16:19:23 UTC
Fixed in GCC-4.1.2