This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Bugreport (+fix) for gcc-2.95.2 with -frepo
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Bugreport (+fix) for gcc-2.95.2 with -frepo
- From: Stefan Westerfeld <stefan at space dot twc dot de>
- Date: Fri, 21 Jan 100 20:33:32 +0100 (CET)
Hi!
I've got a bug report concerning template instantiation and -frepo. I
observed, that the following code
/*
* This source doesn't compile with
* - gcc-2.95.2 + binutils-2.9.5.0.22
* - egcs-1.1.1 + binutils-2.9.1
*
* compiling started with
*
* $ gcc -frepo -c repo-bug.cc
* $ gcc -o repo-bug repo-bug.o
*/
#include <vector>
#include <stack>
#include <string>
int main()
{
// this fails under egcs-1.1.1
vector<string> v;
v.push_back(string("Hello World"));
// this fails under gcc-2.95.2
stack<int> is;
is.push(4);
return 0;
}
doesn't compile with gcc-2.95.2 + binutils-2.9.5.0.22. The reason for that
is that the linker emits error messages like:
file.o: In function `User<int>::User(int const &)':
file.o: ... here comes the real error message, like undefined reference...
which causes tlink.c (in the collect phase) to consider the first line to
contain a symbol that needs to be tweaked (so it would tweak
`User<int>::User(int const &)', which is obviously not the template that
is causing the error). So it fails.
I assume that only nested templates will cause such errors.
/* Here is another, simpler example */
template<class T>
class Keep {
T foo;
public:
Keep(const T& t);
};
template<class T>
Keep<T>::Keep(const T& t)
{
foo = t;
}
template<class T>
class User {
Keep<T> *k1;
public:
User(const T& t);
};
template<class T>
User<T>::User(const T& t)
{
k1 = new Keep<T>(t); // that would give the error message above
}
int main()
{
User<int> k(2);
return 0;
}
The fix I did was kind of a "hack", since it will ignore the lines ending
with a colon when analyzing linker output. This will ignore the
"In function..." lines, and only tweak symbols of lines containing real
errors. After applying that fix, my C++ project compiled fine with -frepo.
However, this of course depends on linker output, and may not help for
any linker.
Cu... Stefan
Here's the diff:
--- tlink.c Tue Oct 12 08:39:14 1999
+++ tlink.c.new Fri Jan 21 18:27:33 2000
@@ -597,6 +597,19 @@
}
}
+static int
+ends_with_colon(p)
+ const char *p;
+{
+ int result = 0;
+ while(*p)
+ {
+ result = (*p == ':');
+ p++;
+ }
+ return result;
+}
+
/* Step through the output of the linker, in the file named FNAME, and
adjust the settings for each symbol encountered. */
@@ -615,6 +628,15 @@
while (*p && ISSPACE ((unsigned char)*p))
++p;
+
+ /*
+ * expect this to be a line like
+ *
+ * file.o: In function `User<int>::User(int const &)':
+ * which is not really talking about a symbol (but breaking everything)
+ */
+ if (ends_with_colon(p))
+ continue;
if (! *p)
continue;