Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Known Xcode/gcc bug with anonymous namespaces?



I've just come across a bug with anonymous namespaces -- anyone know whether this is a known issue already?

I have two cpp files. Each one has an anonymous namespace containing a class definition. The classes have the same name but are different. eg

File1.cpp
=======
namespace {
   class UnitTestStuff {
      int x;
   };
}

void DoSomething() {
   UnitTestStuff stuff;
}

File2.cpp
==========
namespace {
   class UnitTestStuff : public SomeOtherClass {
      string z;
   };
}

void DoSomethingElse() {
   UnitTestStuff stuff;
}

-------------------------
I then had a crash that occurred in File1 because the UnitTestStuff class that was instantiated was actually the one defined in File2 which was a totally different type. Stepping into the constructor with the debugger shows that it's resolving the wrong class. I'm using the DWARF debugging format for this. I think that we never noticed this problem with Xcode 2.2. Renaming one of the classes fixes the crash, but that shouldn't be necessary as the anonymous namespace should restrict the class definitions to file scope.


Paul

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.