This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Bug when defining template constructor not in header.
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Bug when defining template constructor not in header.
- From: Jochen Hepp <jochen dot hepp at gmx dot de>
- Date: 22 Sep 2000 21:58:46 -0000
- MBOX-Line: From - Fri Sep 22 17:37:28 2000
Hi,
I think I found a bug in gcc-2.95.2.
When defining a template of class with a constructor
which has a pointer to a class member object
(e.g.: `int CLASSNAME::* const membername' ) as an argument,
it is only possible to define the constructor in the class
definition itself without a compiler error.
When the constructor is only declared in the header and defined
elsewhere after the header I get this compiler error:
`common_type called with uncommon member types (compiler error)'.
Maybe it`s me who makes the mistake -- but I don't think so.
I included a small testcase to show the bug. If it is compiled
with the symbol `IS_IN_HEADER' then everthing works but otherwise
the compilation fails.
I hope I could show you what I think is a bug,
Jochen
Some (maybe useful) information:
`gcc -v' shows:
gcc version 2.95.2 19991024 (release)
configure run with `--prefix=/opt/gcc-2.95.2-1'
`uname -a' shows:
Linux hostname 2.2.14 #1 kernalcompiletime i686 unknown
`ld -v' shows:
GNU ld version 2.9.5 (with BFD 2.9.5.0.24)
/*
* $ c++ test.cc -DIS_IN_HEADER
* $ ./a.out
* m1: 43
* m2: 9
* ma_member1: 43
* ma_member2: 9
* mb_member1: 43
* mb_member2: 9
*
* $ c++ test.cc
* test.cc:35: common_type called with uncommon member types (compiler error)
*
*/
// =========> test.cc <=========
#include <iostream>
struct V {
V(int v1, int v2) : value1(v1), value2(v2) { };
const int value1;
const int value2;
};
template <class S, class T>
class M {
public:
#ifdef IS_IN_HEADER
M(S& obj, T S::* const mem) : object(obj), member(mem) { };
#else
M(S& object, T S::* const mem);
#endif
ostream& print(ostream& s) {
return s << object.*member;
}
const T& get_member(T S::* const mem) {
return object.*mem;
}
private:
S& object;
T S::* const member;
};
#ifndef IS_IN_HEADER
template <class S, class T>
inline
M<S,T>::M(S& obj, T S::* const mem) : object(obj), member(mem) { }
#endif
template <class S, class T>
ostream& operator <<(ostream& s, M<S,T>& m) { return m.print(s); }
int main() {
V v(43, 9);
M<V,const int> ma(v,&V::value1);
M<V,const int> mb(v,&V::value2);
cout << "ma: " << ma << endl
<< "mb: " << mb << endl;
cout << "ma_member1: " << ma.get_member(&V::value1) << endl
<< "ma_member2: " << ma.get_member(&V::value2) << endl
<< "mb_member1: " << mb.get_member(&V::value1) << endl
<< "mb_member2: " << mb.get_member(&V::value2) << endl;
return 0;
}
// =========> end of test.cc <=========