Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error in traits.hpp on OSX #341

Closed
astrodroid opened this issue Sep 7, 2016 · 5 comments
Closed

Compile error in traits.hpp on OSX #341

astrodroid opened this issue Sep 7, 2016 · 5 comments
Labels
Milestone

Comments

@astrodroid
Copy link

astrodroid commented Sep 7, 2016

Hi,

I am using cereal to load game scenario/map data from file. So far this was working very well. But a couple of days ago, I had to move the classes that cereal serialises away from the game project in a separate static library that is used to calculate the objects position etc..

However as soon as I reference the cereal headers within that static library I encounter a compile error on the traits.hpp file:

    namespace detail
    {
      struct shared_from_this_wrapper
      {
        template <class U>
        static auto **check**( U const & t ) -> decltype( ::cereal::access::shared_from_this(t), std::true_type() );  _//error: Expected member name or ';' after declaration specifiers_

        static auto **check**( ... ) -> decltype( std::false_type() ); _//error: Expected member name or ';' after declaration specifiers_

        template <class U>
        static auto get( U const & t ) -> decltype( t.shared_from_this() );
      };
    }

    //! Determine if T or any base class of T has inherited from std::enable_shared_from_this
    template<class T>
    struct has_shared_from_this : decltype(detail::shared_from_this_wrapper::**check**(std::declval<T>())) _//error: Expected unqualified-id_
    { };

The problem is a bit confusing as this only happens when compiling for OSX and not for iOS. If I understood what is happening correctly, it is not that the static check that is failing, but the compiler appears to be calling a macro called check contained within "AssertMacros.h" :

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
MacOSX10.11.sdk/usr/include/AssertMacros.h:1291:28: note: expanded from macro 'check'
        #define check(assertion)  __Check(assertion)

At the same time the same piece of code that doesn't work within the staticlibrary works fine if called from the main game project, for both iOS and OSX.

For now I have worked-around this issue by renaming the check methods within traits.hpp to "check_" which resolves the issue for me.

This is the full error log:
http://pastebin.com/6GPH6D50

@astrodroid astrodroid changed the title Runtime error in traits.hpp on OSX Compile error in traits.hpp on OSX Sep 7, 2016
@AzothAmmo
Copy link
Contributor

AzothAmmo commented Sep 7, 2016

See #273 and #104 for similar issues. Can you try the macro listed in #104 (__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) and see if that prevents this error from occurring?

@AzothAmmo AzothAmmo added the OSX label Sep 7, 2016
@astrodroid
Copy link
Author

Ok thanks.

Yes, setting #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 in the prefix folder prevents the error from occurring.

Really odd naming choice for that C macro.

@erichkeane
Copy link
Contributor

@AzothAmmo : It seems that the XCode "check" macro is a function call macro, so only "check(" will cause a problem. It seems to me that we could very easily avert this issue by renaming the shared_from_this_wrapper functions to something else, even check_(...). Alternatively, we could change the usages of it to be surrounded with '('')', like we do with min/max (thanks to another stupid macro).

Would you accept either of those patches Shane? @astrodroid, if I were to put said patch together, could you validate it on OSX?

@AzothAmmo
Copy link
Contributor

Either of those solutions is fine. Alternatively check could be renamed test, which would also work unless there's another macro out there with that name too.

@AzothAmmo
Copy link
Contributor

merged #342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants