petehug / wjelement-cpp

WJElement-cpp - Lightweight C++ wrapper for WJElement with JSON Schema support
GNU Lesser General Public License v3.0
9 stars 3 forks source link

Changing order of includes causes error #2

Open julmayer opened 8 years ago

julmayer commented 8 years ago

Hi, I was trying to include your library in a project and was facing a lot of errors of the following type :

In file included from /usr/local/boost_1_42/include/boost/limits.hpp:19:0,
                 from /usr/local/boost_1_42/include/boost/regex/v4/regex_workaround.hpp:37,
                 from /usr/local/boost_1_42/include/boost/regex/v4/regex.hpp:32,
                 from /usr/local/boost_1_42/include/boost/regex.hpp:31,
                 from /usr/local/include/wjelement++.h:54,
                 from ../WJElementTest/main.cpp:2:
/usr/include/c++/4.8/limits:309:11: error: macro "min" requires 2 arguments, but only 1 given
       min() _GLIBCXX_USE_NOEXCEPT { return _Tp(); }

It's caused by the macros min and max from xpl.h of the wjelement library. After wondering why your example works I found out that I can fix/force the error by changing the order of the includes. You could force the error with the following code (it's your example but with changed order of the first two lines):

#include <iostream>
#include <wjelement++.h>

using namespace WJPP;
using namespace std;

int main(int argc, char** argv)
{
  Node people = Node::parseJson("[{\"name\":\"john\",\"male\":true,\"children\":[\"mary\",\"anna\",\"josh\"],\"age\":40,\"partner\":\"rosie\"},{\"name\":\"rosie\",\"male\":false,\"children\":[\"mary\",\"anna\",\"josh\"],\"age\":37,\"partner\":\"john\"}]");

  for (Node::iterator i = people.begin(); i != people.end(); i++)
  {
    Node person = *i;

    cout << "===============================================================================" << endl;
    cout << "Name:     " << person["name"] << endl;
    cout << "Age:      " << person["age"] << endl;
    cout << "Sex:      " << (person["male"].getBool() ? "male" : "female") << endl;
    cout << "Partner:  " << person["partner"] << endl;
    cout << "Kids:     ";

    Node kids = person["children"];

    for (Node::iterator j = kids.begin(); j != kids.end(); j++)
      cout << *j << " ";

    cout << endl;
  }

  people.discard(); // frees memory
}

Is this a known problem? Including the headers in the "correct" order works for me but maybe it's a safer to rename the macros to something more unique like XPL_MIN.

petehug commented 8 years ago

No it isn't a know problem. xpl.h is from the WJElement library which I forked for this project. I tried to keep changes to that library to those absolute necessary to support my JSON Schema 04 implementation.

Strange is that on my Centos 6.2 box the example compiles fine with GCC 4.4.7 regardless of the order of includes. So I presume this issue has something to do with the compiler version.

Since you have a work around I won't do anything about this but have raised the issue with the maintainers of WJElement.

julmayer commented 4 years ago

Hi everyone, the naming clash was fixed in WJElement in Pull Request #71. If I understand that compare correctly https://github.com/netmail-open/wjelement/compare/master...petehug:wjelement++ there is not more difference between your forked wjelement++ branch and original WJElement master so it should be save to use the WJElement master instead of your wlemenet++ branch. Am I correct or do you see any problems?