[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] errors with g++-4.5 not with g++-4.4



Axel Freyn wrote:
Hi Hugo,

Thanks Axel. It is stranger yet:
1. mutrec is defined in aa.cpp
2. It is used as extern in mc.cpp, grafrs.cpp and setfile.cpp
3. But g++-4.5 only finds undefined referenes in mc.cpp and grafrs.cpp, *not* in setfile.cpp
4. Yet the extern for mutrec is defined in all three the same way.
5. And previous compilers have found no errors.
6. The whole bunch is linked together via aa.pro that is used in 'qmake-qt4 -o Makefile aa.pro' to create a makefile for make.
Some updates from my checks:
a) I can't compile the code on amd64: in tranrs.cpp, lines 1789 and 1810
you convert "double *" to "int".  However, on amd64 "double *" is of
size 8 bytes, "int" is only 4 bytes ==> You loose precision and get
quite unpredictable results. In addition, g++ from squeeze and wheezy
(4.4 and 4.5) do NOT compile it. Chaning "int" to "long", it works
correctly (maybe the "correct" type would be std::ptrdiff_t?)

b) The linker error: There is a difference between mc.cpp grafrs.cpp AND
setfile.cpp:
 - setfile: you have "extern mutrc" OUTSIDE of all functions
 - mc and grafrs: the extern mutrc appears IN a function (drwts and
   weights)
Maybe that's the critical point?
I succeeded to create a testcase:
a.cc:
extern struct {int cnt;} mutrec;
int main(){
  mutrec.cnt = 2;
}

b.cc:
struct{  int cnt; } mutrec = { 0};

This compiles fine with g++-4.4, but not with g++-4.5
(just try "g++-4.4 a.cc b.cc" and "g++-4.5 a.cc b.cc")
g++-4.5 states:
/tmp/cc06Uy69.o: In function `f()':
a.cc:(.text+0x6): undefined reference to `mutrec'
collect2: ld returned 1 exit status


However, both versions mention the problem:

a.cc:2:28: warning: non-local variable ‘f()::<anonymous struct> mutrec’ uses anonymous type
b.cc:1:23: warning: non-local variable ‘<anonymous struct> mutrec’ uses anonymous type

So, it compiles & links fine if you give those structures a name (e.g.
call them "A"):

a.cc:
extern struct A {int cnt;} mutrec;
int main(){
  mutrec.cnt = 2;
}

b.cc:
struct A {  int cnt; } mutrec = { 0};

Then, both g++-4.4 and g++-4.5 succeed to link the code.

However, I'm not sure what the C++-standard says to this problem --
should it work with anonymous structures or not?



Hi Axel,

We got the workaround at the same time! The "fix" is to *not* make mutrec anonymous ( you called it 'A' ).
IMHO this is a bug, anonymous structures are valid structures...

There are some bugs that crept up in the code of Gpc-qt that I haven't uploaded yet:

1. You found the one with amd64 in transrs lines 1799 + 1812, I just left the typedefs off... 2 In grafrs mutrec is made named and placed outside of the function (lines 22 + 1235) 3 In application, line 1098 should be ...disable_button(8,... *not* 9, that causes segfaults in places.
4. In bpltw line 464 with tkbfillq... is commented out
5. mc gets mutrec named (line 109)
6. setfile gets mutrec named (line 41)

Thanks for your efforts Axel.

Hugo












Reply to: