Bug 28360 - [4.2 regression] undefined reference when header contains additional namespace
Summary: [4.2 regression] undefined reference when header contains additional namespace
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure
: 28438 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-07-12 16:00 UTC by Martin Michlmayr
Modified: 2006-07-19 15:56 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Michlmayr 2006-07-12 16:00:41 UTC
I get an "undefined reference" error with a recent gcc 4.2 when linking to a class whose header contains an additional namespace that is references from that class.  This is a very recent error.  It started to occur between 20060626 and 20060709.

(sid)1690:tbm@reyes: ~/src/t] make
rm -f *.o
g++-4.1 -c t.cc ; g++-4.1 -c a.c ; g++-4.1  a.o t.o
rm -f *.o
g++-4.2 -c t.cc ; g++-4.2 -c a.c ; g++-4.2  a.o t.o
a.o: In function `main':
a.c:(.text+0x18): undefined reference to `test::MonitorHandle::MonitorHandle()'
collect2: ld returned 1 exit status
(sid)1691:tbm@reyes: ~/src/t] cat t.h
namespace test
{

namespace
{
class SignalProxy_Monitor;
}

class MonitorHandle
{
public:
  MonitorHandle();

private:
  SignalProxy_Monitor* proxy_;

};

}
(sid)1693:tbm@reyes: ~/src/t] cat t.cc
#include "t.h"

namespace test
{

MonitorHandle::MonitorHandle()
{}

}

(sid)1694:tbm@reyes: ~/src/t] cat a.c
#include "t.h"

int main(void) {
        test::MonitorHandle handle;
        return 0;
}
Comment 1 Martin Michlmayr 2006-07-12 16:51:48 UTC
This was caused by:

  r115086 | jason | 2006-06-30 03:15:56 +0200 (Fri, 30 Jun 2006) | 58 lines
Comment 2 Andrew Pinski 2006-07-12 17:05:53 UTC
The code is invalid as the anonymous namespace causes an ODR violation.
Comment 3 Andrew Pinski 2006-07-12 17:09:17 UTC
To better explain:
test::MonitorHandle references a class in an anonymous namespace which causes that class to be different in each TU.  Since ODR rules say the class needs to be the same across TUs so we declare test::MonitorHandle also a local class.
Comment 4 Andrew Pinski 2006-07-13 11:53:58 UTC
*** Bug 28370 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2006-07-19 15:45:35 UTC
*** Bug 28438 has been marked as a duplicate of this bug. ***