USCiLab / cereal

A C++11 library for serialization
BSD 3-Clause "New" or "Revised" License
4.22k stars 761 forks source link

Xcode9.0 compiler problem in RapidJson #440

Open puentev opened 7 years ago

puentev commented 7 years ago

Again json, xcode9.0 compiler (incorrectly) detect a private member in json.hpp as unused.

The compiler version is:

cigal cereal (master)$ 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.0.0 (clang-900.0.37) Target: x86_64-apple-darwin16.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

The workaraound is to tell clang to ignore that (with a couple of pragmas):

diff --git a/include/cereal/archives/json.hpp b/include/cereal/archives/json.hpp
index 9d57434..36adbc8 100644
--- a/include/cereal/archives/json.hpp
+++ b/include/cereal/archives/json.hpp
@@ -532,6 +532,8 @@ namespace cereal

         private:
           MemberIterator itsMemberItBegin, itsMemberItEnd; //!< The member iterator (object)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-private-field"
           ValueIterator itsValueItBegin, itsValueItEnd;    //!< The value iterator (array)
           size_t itsIndex;                                 //!< The current index of this iterator
           enum Type {Value, Member, Null_} itsType;        //!< Whether this holds values (array) or members (objects) or nothing
Yevgnen commented 6 years ago

Same here.

jhasse commented 6 years ago

Why is it incorrectly? I would simply remove the variable like this:

diff --git a/include/cereal/archives/json.hpp b/include/cereal/archives/json.hpp
index 102f86e..05a77a5 100644
--- a/include/cereal/archives/json.hpp
+++ b/include/cereal/archives/json.hpp
@@ -488,7 +488,7 @@ namespace cereal
           }

           Iterator(ValueIterator begin, ValueIterator end) :
-            itsValueItBegin(begin), itsValueItEnd(end), itsIndex(0), itsType(Value)
+            itsValueItBegin(begin), itsIndex(0), itsType(Value)
           {
             if( std::distance( begin, end ) == 0 )
               itsType = Null_;
@@ -543,7 +543,7 @@ namespace cereal

         private:
           MemberIterator itsMemberItBegin, itsMemberItEnd; //!< The member iterator (object)
-          ValueIterator itsValueItBegin, itsValueItEnd;    //!< The value iterator (array)
+          ValueIterator itsValueItBegin;                   //!< The value iterator (array)
           size_t itsIndex;                                 //!< The current index of this iterator
           enum Type {Value, Member, Null_} itsType;        //!< Whether this holds values (array) or members (objects) or nothing
       };
gouletr commented 6 years ago

Agreed with @jhasse just remove the member and its initialization, its not used.