PrismTech/opensplice — pull request #11 by wjwwood (2014-09-19 01:37:00+00:00)
Title: Fix compile error on OS X

Hi, I was building 6.4.0 on my macbook using `x86_64.darwin10_clang-release` (but also affects `x86_64.darwin10_clang-dev`) and I ran into three separate compile issues, all of which can be generalized to this:

```
In file included from code/dds/domain/DomainParticipantListener.cpp:17:
In file included from include/dds/domain/DomainParticipantListener.hpp:22:
In file included from include/spec/dds/domain/DomainParticipantListener.hpp:22:
In file included from include/dds/pub/PublisherListener.hpp:22:
In file included from include/spec/dds/pub/PublisherListener.hpp:22:
In file included from include/dds/pub/AnyDataWriterListener.hpp:22:
In file included from include/spec/dds/pub/AnyDataWriterListener.hpp:22:
In file included from include/dds/pub/AnyDataWriter.hpp:22:
In file included from include/spec/dds/pub/AnyDataWriter.hpp:25:
In file included from include/dds/pub/detail/AnyDataWriter.hpp:24:
include/dds/pub/DataWriter.hpp:637:33: error: variable has incomplete type 'dds::pub::AnyDataWriter'
dds::pub::AnyDataWriter adw(*this);
^
include/dds/pub/DataWriter.hpp:34:7: note: forward declaration of 'dds::pub::AnyDataWriter'
class AnyDataWriter;
^
include/dds/pub/DataWriter.hpp:651:33: error: variable has incomplete type 'dds::pub::AnyDataWriter'
dds::pub::AnyDataWriter adr(*this);
^
include/dds/pub/DataWriter.hpp:34:7: note: forward declaration of 'dds::pub::AnyDataWriter'
class AnyDataWriter;
^
2 errors generated.
```

Basically this code is trying to use a forward declaration `class AnyDataWriter;` and then later instantiate the class (`dds::pub::AnyDataWriter adr(*this);`) using `*this`. This is not supported by clang, and really it shouldn't be supported on gcc and Linux, but it is for now...

The solution I came up with was to use a forward declared function which creates a (unique/scoped) pointer to the forward declared class and use that in the code which follows. Then I found the code where the constructor for this forward declared class was and implemented the forward declared function there. I think this should be performant and work across all compilers.

The only outstanding issue is that I am using `std::unique_ptr` and I guess if you want to support non-C++11 compilers you'll need to use your internal scoped or unique pointer equivalent. Another option is to use a raw pointer and manage deletion yourself, but I thought the unique pointer was more idiomatic.

This same problem came up for `AnyDataReader` and `AnyTopic`, and my patch addresses all occurrences, and after this patch OpenSplice 6.4.0 builds on OS X for me.