On Tue, Mar 3, 2009 at 4:30 PM, Darin Fisher <da...@chromium.org> wrote:
> On Tue, Mar 3, 2009 at 3:55 PM, Scott Hess <sh...@chromium.org> wrote:
>> On the Mac, code like this:
>>
>> namespace {
>> class MyTest : public testing::Test {
>> };
>> }  // namespace
>>
>> TEST_F(MyTest, ATest) {
>> }
>>
>> generates errors like this:
>> warning: ‘MyTest_ATest_Test’ has a field
>> ‘MyTest_ATest_Test::<anonymous>’ whose type uses the anonymous
>> namespace
>> warning: ‘MyTest_ATest_Test’ has a base ‘<unnamed>::MyTest’ whose type
>> uses the anonymous namespace
>>
>> Removing the namespace fixes it, which is poor because we seem to want
>> to move towards more anonymous namespace use.  Putting the test case
>> inside the namespace also fixes it, but is incompatible with
>> FRIEND_TEST().  This seems to be a gcc 4.2 addition, per:
>>  http://gcc.gnu.org/gcc-4.2/changes.html
>>
>> "Members of the anonymous namespace are now local to a particular
>> translation unit, along with any other declarations which use them,
>> though they are still treated as having external linkage for language
>> semantics."
>>
>> At this point, I'm sort of at the bleeding edge of my knowledge.  For
>> FRIEND_TEST() cases, it seems like the anonymous namespace needs to
>> go, but elsewhere it can be changed to enclose the entire file.  Does
>> that seem reasonable for now?
>>
>> -scott
>
>
> Assuming that you really need to use TEST_F, then it would be unfortunate to
> lose the anonymous namespace.  The anonymous namespace has allowed us to
> have short names for helper classes used by tests without fear of colliding
> with other short names used by other tests.  (We have had those kinds of
> conflicts in the past.)
> We don't use FRIEND_TEST that much.  Maybe we can just use #ifdef UNIT_TEST
> to expose class APIs to unit tests?

To be clear, my example was a trivialized version of things in our code.

The other day I found myself wondering how FRIEND_TEST makes logical
sense when you're putting the friend in an anonymous namespace in a
different compilation unit.  Depending on the compiler implementation
it might work, but AFAICT, it's not correct because each file's
anonymous namespace should be distinct, so the file containing
FRIEND_TEST cannot name the anonymous namespace for the friend.  I
think.

-scott

--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to