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

clang++ 6.0 (Xcode 9.3) Error in CEREAL_RAPIDJSON_ASSERT macro #439

Open
puentev opened this issue Sep 13, 2017 · 9 comments
Open

clang++ 6.0 (Xcode 9.3) Error in CEREAL_RAPIDJSON_ASSERT macro #439

puentev opened this issue Sep 13, 2017 · 9 comments

Comments

@puentev
Copy link

puentev commented Sep 13, 2017

From current stable version i'm getting this warning (with -Wall):

../ext/cereal//include/cereal/external/rapidjson/document.h:597:9: error: 'GenericValue' has a non-throwing exception specification but can still throw [-Werror,-Wexceptions]
CEREAL_RAPIDJSON_ASSERT(type <= kNumberType);

With latest Xcode (9.3) this is no longer a warning but an error. As dirty workaround ...
replace in
cereal/include/cereal/archives/json.hpp

#define CEREAL_RAPIDJSON_ASSERT(x) if(!(x)){ 
throw ::cereal::RapidJSONException("rapidjson internal assertion failure: " #x); }

by

#ifndef CEREAL_RAPIDJSON_ASSERT
#ifdef __APPLE__
#define CEREAL_RAPIDJSON_ASSERT(x) if(!(x)){ assert(0 && "fallo json");};
#else
#define CEREAL_RAPIDJSON_ASSERT(x) if(!(x)){ \
throw ::cereal::RapidJSONException("rapidjson internal assertion failure: " #x); }
#endif
#endif
@puentev puentev changed the title Clan5 warning in rapidjson. Clang++5 .0 warning in rapidjson. Sep 13, 2017
@AzothAmmo
Copy link
Contributor

Make sure to report this upstream to rapidjson. For us the likely solution will be to temporarily disable that warning for any files in rapidjson that cause it.

@rahul-r
Copy link

rahul-r commented Feb 1, 2018

I don't think this warning is caused by rapidjson. The origin of the exception is line 45 & 46 of cereal/include/cereal/archives/json.hpp

#define CEREAL_RAPIDJSON_ASSERT(x) if(!(x)){
throw ::cereal::RapidJSONException("rapidjson internal assertion failure: " #x); }

@NuLL3rr0r
Copy link

We faced this issue when we upgrade our compiler to clang 5.0. Is there any fix for this issue?

@puentev puentev changed the title Clang++5 .0 warning in rapidjson. Xcode 9.3 Error in rapidjson. Apr 4, 2018
@puentev puentev changed the title Xcode 9.3 Error in rapidjson. Xcode 9.3 Error in CEREAL_RAPIDJSON_ASSERT macro Apr 4, 2018
@morbo84
Copy link

morbo84 commented Apr 13, 2018

The warning is present also with Clang++ 6.0 at it's not related to XCode or any other IDE (I'm running it on ArchLinux)

@puentev puentev changed the title Xcode 9.3 Error in CEREAL_RAPIDJSON_ASSERT macro clang++ 6.0 Error in CEREAL_RAPIDJSON_ASSERT macro Apr 13, 2018
@puentev puentev changed the title clang++ 6.0 Error in CEREAL_RAPIDJSON_ASSERT macro clang++ 6.0 (Xcode 9.3) Error in CEREAL_RAPIDJSON_ASSERT macro Apr 13, 2018
@puentev
Copy link
Author

puentev commented Apr 13, 2018

Xcode has its own "rebranded" clang++/LLVM ... I didn't know that was also in the regular 1

g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@johnwbyrd
Copy link

johnwbyrd commented May 19, 2018

This is still throwing warnings in XCode 9.3.1. puentev's workaround, or something like it, should go mainline until you get except vs. noexcept consistent between RapidJSON and cereal.

The bad boy here is cereal/external/rapidson/document.h . There are a lot of obects being constructed with the CEREAL_RAPIDJSON_NOEXCEPT modifier, but in those call stacks you have CEREAL_RAPIDJSON_ASSERTs declared. You can't have both.

For example, one bit of offending code is on line 755 of cereal/external/rapidson/document.h, where you've defined a function with the following prototype:

GenericValue &operator=(GenericValue &rhs) CEREAL_RAPIDJSON_NOEXCEPT {

Same thing on line 592:

explicit GenericValue( Type type ) CEREAL_RAPIDJSON_NOEXCEPT : data_() {

And that conflicts with at least the following code on line 597 of cereal/external/rapidjson/document.h:

CEREAL_RAPIDJSON_ASSERT( type <= kNumberType );

@mobileben
Copy link

I'm not using cereal, but this this same issue (using Xcode 9.3.1 with rapidjson).

The problem does indeed seem to lie with rapidjson as @johnwbyrd cites.

From what I can tell, cereal is just adding CEREAL_

But rapidjson has stuff like:

GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
    RAPIDJSON_ASSERT(this != &rhs);
    this->~GenericValue();
    RawAssign(rhs);
    return *this;
}

With RAPIDJSON_NOEXCEPT being controlled by

#ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
#if defined(__clang__)
#define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__))
//    (defined(_MSC_VER) && _MSC_VER >= ????) // not yet supported
#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
#else
#define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
#endif
#endif

I'm going to update to the latest, but I quick scan of the code has the same issues.

@pah
Copy link

pah commented Oct 19, 2018

Fixed upstream in Tencent/rapidjson#1329.

@dholl
Copy link

dholl commented Nov 20, 2018

Hello,
I'm trying out Cereal for the first time, and it is a nifty project! What steps are involved for me to incorporate a fixed rapidjson codebase from upstream? I noticed that rapidjson's code is included as copied files rather than as a git submodule.

Do I just need to git clone a new release of rapidjson directly into include/cereal/external/rapidjson and then run scripts/add_rapidjson_prefix.sh ?

Or is there a different set of steps I should try? (I found the customization script add_rapidjson_prefix.sh, but I didn't find any other scripts that run that script. So I'm unclear if there's some order I should follow.)

Thank you,
David

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

No branches or pull requests

9 participants