In the transcript below, the program "problem.C", which does not include any
header files, shows a bug in gcc 3.4.0 under Linux (kernel version 2.6.11)
running on an Intel Pentium 4, which still exists in gcc 4.0.2 but does not
exist in gcc 3.3.2. I also enclose two slightly modified versions of
"problem.C", called "ok1.C" and "ok2.C", which both pass under the newer
compilers.
I have a very large software system in C++ which does not compile on the latest
compiler, and I spent a long time trying to reduce the code to this small
example which I enclose below in "problem.C". Unfortunately, the two
workarounds "ok1.C" and "ok2.C" are not an option in my large system, and any
real workaround would involve either a significant design change or a major
kludge, both of which I would rather avoid, so until I hear from you I cannot
migrate my system over to the latest compiler. Please help!
Sincerely,
Joseph Friedman, Ph.D.
Millennium Partners, L.P.
666 Fifth Avenue, 8th Floor
New York, NY 10103
(212) 841-4160
% /usr/local/gcc-3.3.2/bin/g++ -v
Reading specs from
/usr/local/gcc-3.3.2/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/specs
Configured with: ./configure --prefix=/usr/local/gcc-3.3.2
Thread model: posix
gcc version 3.3.2
% /usr/local/gcc-3.4.0/bin/g++ -v
Reading specs from
/apps/local.linux/gcc-3.4.0/bin/../lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: ./configure --prefix=/usr/local/gcc-3.4.0
Thread model: posix
gcc version 3.4.0
% /usr/local/gcc-4.0.2/bin/g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc-4.0.2
Thread model: posix
gcc version 4.0.2
% /usr/local/gcc-3.3.2/bin/g++ ok1.C
% /usr/local/gcc-3.3.2/bin/g++ ok2.C
% /usr/local/gcc-3.3.2/bin/g++ problem.C
% /usr/local/gcc-3.4.0/bin/g++ ok1.C
% /usr/local/gcc-3.4.0/bin/g++ ok2.C
% /usr/local/gcc-3.4.0/bin/g++ problem.C
problem.C: In constructor `s1::s1(const T&) [with T = pair]':
problem.C:35: instantiated from here
problem.C:14: error: cannot convert `const pair' to `double'
for argument `1' to `void ns1::f(double)'
% /usr/local/gcc-4.0.2/bin/g++ ok1.C
% /usr/local/gcc-4.0.2/bin/g++ ok2.C
% /usr/local/gcc-4.0.2/bin/g++ problem.C
problem.C: In constructor s1::s1(const T&) [with T = pair]:
problem.C:35: instantiated from here
problem.C:14: error: cannot convert const pair to double
for argument 1 to void ns1::f(double)
% cat problem.C
template
struct pair { pair(T1 x, T2 y) : first(x) {} T1 first; T2 second; };
template
pair make_pair(T1 x, T2 y) { return pair(x, y); }
namespace ns1 {
void f(double x) {}
}
template
struct s1 {
T a;
int i;
s1(const T& x) : a(x) { ns1::f(x); }
};
namespace ns1 {
template bool f(const pair& x) {
f(x.first);
}
}
template
struct s2 {
typedef pair pair_type;
};
template
struct s3 : public S {
typedef s1 t3;
};
int main() {
pair p = make_pair((double)5, (double)12);
s3< s2 >::t3 o = s3< s2 >::t3(p);
return 0;
}
% cat ok1.C
template
struct pair { pair(T1 x, T2 y) : first(x) {} T1 first; T2 second; };
template
pair make_pair(T1 x, T2 y) { return pair(x, y); }
namespace ns1 {
void f(double x) {}
}
namespace ns1 {
template bool f(const pair& x) {
f(x.first);
}
}
template
struct s1 {
T a;
int i;
s1(const T& x) : a(x) { ns1::f(x); }
};
template
struct s2 {
typedef pair pair_type;
};
template
struct s3 : public S {
typedef s1 t3;
};
int main() {
pair p = make_pair((double)5, (double)12);
s3< s2 >::t3 o = s3< s2 >::t3(p);
return 0;
}
% cat ok2.C
template
struct pair { pair(T1 x, T2 y) : first(x) {} T1 first; T2 second; };
template
pair make_pair(T1 x, T2 y) { return pair(x, y); }
void f(double x) {}
template
struct s1 {
T a;
int i;
s1(const T& x) : a(x) { f(x); }
};
template bool f(const pair& x) {
f(x.first);
}
template
struct s2 {
typedef pair pair_type;
};
template
struct s3 : public S {
typedef s1 t3;
};
int main() {
pair p = make_pair((double)5, (double)12);
s3< s2 >::t3 o = s3< s2 >::t3(p);
return 0;
}
--
Summary: g++ bug, possibly introduced around gcc 3.4.0
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcc_bugzilla at friedman dot to
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26148