This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Gcc 2.95.2 fails to compile legal (I hope) code
- To: bug-gcc at gnu dot org
- Subject: Gcc 2.95.2 fails to compile legal (I hope) code
- From: "Robert E. Nelson" <ren at tecomac dot com>
- Date: Tue, 15 Feb 2000 14:43:25 -0700
- Organization: TECOMAC, Inc.
Using G++ 2.95.2 on a Sun Solaris 7 machine (uname -a produces: SunOS
sun 5.7 Generic_106541-02 sun4u sparc SUNW,Ultra-4), the following code
fails to compile at the indicated line using the compile command:
g++ -v --save-temps vec.cc
-------- BEGIN CODE vec.cc -----------
#include <vector>
#include <list>
#include <string>
using namespace std;
// define a class which the list will contain
class a_class
{
public:
};
// define another class which we want to create a function pointer to
class b_class
{
public:
// the typedef of the list iterator
typedef list<a_class>::const_iterator& my_iter;
// the function we want to point to
void a_func9(string&, my_iter) const {} ;
};
// typedef of the function we want to point to
typedef void (b_class::* my_func_ptr)(string&, b_class::my_iter) const;
int main(int, char **)
{
// create a vector of function pointers
vector<my_func_ptr> obj; // <----------- THIS FAILS COMPILATION!
obj.push_back(&b_class::a_func9);
return 0;
}
----------- END CODE ----------
The output from g++ -v --save-temps vec.cc is:
---------- BEGIN OUTPUT ---------
Reading specs from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/cpp -lang-c++ -v
-D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dsparc
-Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__
-D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix)
-Asystem(svr4) -D__EXCEPTIONS -D__GCC_NEW_VARARGS__ -Acpu(sparc)
-Amachine(sparc) vec.cc vec.ii
GNU CPP version 2.95.2 19991024 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../include/g++-3
/usr/local/include
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../sparc-sun-solaris2.7/include
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/include
/usr/include
End of search list.
The following default directories have been omitted from the search
path:
End of omitted list.
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/cc1plus vec.ii
-quiet -dumpbase vec.cc -version -o vec.s
GNU C++ version 2.95.2 19991024 (release) (sparc-sun-solaris2.7)
compiled by GNU C version 2.95.2 19991024 (release).
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../include/g++-3/stl_alloc.h:
In instantiation of `allocator<void
(b_class::*)(basic_string<char,string_char_traits<char>,__default_alloc_template<false,0>
> &, _List_iterator<a_class,const a_class &,const a_class *> &) const>':
vec.cc:30: instantiated from here
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../include/g++-3/stl_alloc.h:750:
`allocator<void
(b_class::*)(basic_string<char,string_char_traits<char>,__default_alloc_template<false,0>
> &, _List_iterator<a_class,const a_class &,const a_class *> &) const>::address(void (b_class::* &)(string &, _List_iterator<a_class,const a_class &,const a_class *> &) const) const' has already been declared in `allocator<void (b_class::*)(basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> > &, _List_iterator<a_class,const a_class &,const a_class *> &) const>'
------------ END OUTPUT ---------
The code this example was derived from has compiled under g++ on Linux
(egcs-2.91.66), Sun's CC (CC: WorkShop Compilers 5.0 98/12/15 C++ 5.0),
and MS Developer Studio under Windows NT/2000, so I believe there is
nothing wrong with it. I use function pointers with maps (as opposed to
vectors) quite a bit in the other code this works with and have no
problems compiling them.
I have attached the preprocessed output file as a MIME attachment in
gzip form.
-ren
vec.ii.gz