This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Diagnosing an intricate C++ problem
- To: gcc at gcc dot gnu dot org
- Subject: Diagnosing an intricate C++ problem
- From: Gerald Pfeifer <pfeifer at dbai dot tuwien dot ac dot at>
- Date: Tue, 25 Jul 2000 02:42:02 +0200 (CEST)
Consider the following two files, compiled as
g++ 1.cc 2.cc
and
g++ 2.cc 1.cc
respectively.
In the first case you'll get 2, in the second 4, instead of the
(originally) expected output of 3.
---- 1.cc ----
struct S {
int f() { return 1; }
};
int f1() { S s; return s.f(); }
---- 1.cc ----
---- 2.cc ----
struct S {
int f() { return 2; }
};
int f2() { S s; return s.f(); }
int f1();
#include <stdio.h>
main() { printf("%d\n",f1()+f2()); }
---- 2.cc ----
Of course this is a destilled example, but tracking this down in a large
code base took me quite some time and now that template/STL code gets more
and more popular, this is getting more and more likely to bite users.
Being able to issue a warning for such cases would be extremely valuable.
Thoughts?
Gerald
--
Gerald "Jerry" pfeifer@dbai.tuwien.ac.at http://www.dbai.tuwien.ac.at/~pfeifer/
Have a look at http://petition.eurolinux.org -- it's not about Linux, btw!