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

compiling with gcc 7 -> error on bool operator < #590

Closed
buffos opened this issue May 21, 2017 · 22 comments
Closed

compiling with gcc 7 -> error on bool operator < #590

buffos opened this issue May 21, 2017 · 22 comments
Assignees
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@buffos
Copy link

buffos commented May 21, 2017

when compiling i get

json.hpp:6395:66: error: wrong number of template arguments (1, should be 2) return *lhs.m_value.array < *rhs.m_value.array;

and

/usr/include/c++/7/array:94:12: note: provided for ‘template<class _Tp, long unsigned int _Nm> struct std::array’ struct array

@nlohmann
Copy link
Owner

Could you provide more information: what do you compile? Are there more error messages with other file locations?

@buffos
Copy link
Author

buffos commented May 21, 2017

@buffos
Copy link
Author

buffos commented May 21, 2017

here is the full output of the compilation

kostas@kostaslinuxlaptop:~/Code/carnd/CarND-MPC/build$ cmake .. && make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kostas/Code/carnd/CarND-MPC/build
Scanning dependencies of target mpc
[ 33%] Building CXX object CMakeFiles/mpc.dir/src/MPC.cpp.o
[ 66%] Building CXX object CMakeFiles/mpc.dir/src/main.cpp.o
In file included from /home/kostas/Code/carnd/CarND-MPC/src/main.cpp:10:0:
/home/kostas/Code/carnd/CarND-MPC/src/json.hpp: In function ‘bool nlohmann::operator<(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference)’:
/home/kostas/Code/carnd/CarND-MPC/src/json.hpp:6395:66: error: wrong number of template arguments (1, should be 2)
                         return *lhs.m_value.array < *rhs.m_value.array;
                                                                  ^~~~~
In file included from /usr/include/c++/7/tuple:39:0,
                 from /usr/include/c++/7/mutex:38,
                 from /usr/include/uWS/Epoll.h:11,
                 from /usr/include/uWS/Backend.h:12,
                 from /usr/include/uWS/Networking.h:69,
                 from /usr/include/uWS/WebSocketProtocol.h:5,
                 from /usr/include/uWS/WebSocket.h:4,
                 from /usr/include/uWS/Group.h:4,
                 from /usr/include/uWS/Hub.h:4,
                 from /usr/include/uWS/uWS.h:4,
                 from /home/kostas/Code/carnd/CarND-MPC/src/main.cpp:2:
/usr/include/c++/7/array:94:12: note: provided for ‘template<class _Tp, long unsigned int _Nm> struct std::array’
     struct array
            ^~~~~
CMakeFiles/mpc.dir/build.make:86: recipe for target 'CMakeFiles/mpc.dir/src/main.cpp.o' failed
make[2]: *** [CMakeFiles/mpc.dir/src/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mpc.dir/all' failed
make[1]: *** [CMakeFiles/mpc.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

@nlohmann
Copy link
Owner

Could you paste the complete error message? I compiled the test suite of this library with GCC7 without problems.

@buffos
Copy link
Author

buffos commented May 21, 2017

I just did above :)

@nlohmann
Copy link
Owner

It seems that the compiler tries to parse array as std::array. I can't install all the dependencies right now - can you try to create a smaller example with fewer dependencies?

To rule out a problem with your compiler: can you try to compile the unit tests for nlohmann/json (by just calling cmake/make after cloning nlohmann/json?

@buffos
Copy link
Author

buffos commented May 21, 2017

I tried cmake -DCMAKE_C_COMPILER="/usr/bin/gcc-6" -DCMAKE_CXX_COMPILER="/usr/bin/g++-6" .. && make and it builds fine
So its definitely an issue with the compiler. Probably due to dependencies.

@nlohmann
Copy link
Owner

So GCC6 works with your code, but GCC7 does not? This is strange. Then again, can you reproduce the error which fewer dependencies?

@buffos
Copy link
Author

buffos commented May 21, 2017

I will.

@whenov
Copy link

whenov commented Jun 1, 2017

I met the same problem, here's one way to produce it:

a.cc:

#include <string>
using namespace std;

#include "json.hpp"

Compiling it with g++ -c a.cc will produce the error.

@nlohmann
Copy link
Owner

nlohmann commented Jun 1, 2017

I cannot reproduce this issue with

  • g++-7 (Homebrew GCC 7.1.0) 7.1.0
  • g++ (GCC) 8.0.0 20170601 (experimental)

I can compile and run the complete test suite from the develop branch.

@whenov What is the OS/version of your compiler, and can you provide the error message?

@riccardolardi
Copy link

riccardolardi commented Jun 1, 2017

I'm having the exact same issue when compiling any OpenFrameworks app on Arch Linux since updating gcc to 7.1.1

/home/thinkpad2000/Downloads/of_v20170517_linux64_release/libs/json/include/json.hpp:5002:62: error: wrong number of template arguments (1, should be 2)
                   return *lhs.m_value.array < *rhs.m_value.array;
                                                            ^~~~~
In file included from /usr/include/c++/7.1.1/tuple:39:0,
               from /usr/include/c++/7.1.1/bits/unique_ptr.h:37,
               from /usr/include/c++/7.1.1/bits/locale_conv.h:41,
               from /usr/include/c++/7.1.1/locale:43,
               from /usr/include/c++/7.1.1/iomanip:43
...

@jebrosen
Copy link

jebrosen commented Jun 1, 2017

I tried to help @alberto2000 track this down in IRC earlier. In https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/utils/ofConstants.h#L435 -- 'using namespace std;' is present and indirectly ahead of the include for json.hpp, which seems to trigger the issue.

@buffos -- your code also has a 'using namespace std;' indirectly before json.hpp is included

@nlohmann -- I did the same as @whenov and had the same error message about template arguments, which goes away if 'using namespace std;' is commented out. The test suite built and ran fine.

@whenov
Copy link

whenov commented Jun 2, 2017

@nlohmann
OS: Arch Linux
Compiler: gcc version 7.1.1 20170516 (GCC)
Error message:

json.hpp: In function ‘bool nlohmann::operator<(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference)’:
json.hpp:6057:62: error: wrong number of template arguments (1, should be 2)
                     return *lhs.m_value.array < *rhs.m_value.array;
                                                              ^~~~~
In file included from json.hpp:33:0,
                 from a.cc:4:
/usr/include/c++/7.1.1/array:94:12: note: provided for ‘template<class _Tp, long unsigned int _Nm> struct std::array’
     struct array
            ^~~~~

@nlohmann
Copy link
Owner

nlohmann commented Jun 2, 2017

Ok, now I can also reproduce the error with the following code and GCC-7:

using namespace std;
#include <json.hpp>

int main()
{}

The error is

In file included from std.cpp:2:0:
src/json.hpp: In function 'bool nlohmann::operator<(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference)':
src/json.hpp:6384:62: error: wrong number of template arguments (1, should be 2)
                     return *lhs.m_value.array < *rhs.m_value.array;
                                                              ^~~~~
In file included from src/json.hpp:33:0,
                 from std.cpp:2:
/usr/local/Cellar/gcc/7.1.0/include/c++/7.1.0/array:94:12: note: provided for 'template<class _Tp, long unsigned int _Nm> struct std::array'
     struct array
            ^~~~~
make: *** [std] Error 1

It is very strange that the name array is mistaken as std::array. I wonder if this is a bug in GCC.

@nlohmann nlohmann added the state: help needed the issue needs help to proceed label Jun 2, 2017
@jebrosen
Copy link

jebrosen commented Jun 3, 2017

Changing the line in json.hpp to read

return (*lhs.m_value.array) < *rhs.m_value.array;

seems to fix the error using that simple test case. It's quite possible this is a GCC bug; I can't understand why .array< should be interpreted as template parameters to array with that . preceding it. Furthermore, clang compiles the snippet without issue in C++11 and in C++14 mode.

@jaredgrubb
Copy link
Contributor

Yes, definitely seems like a compiler bug, especially if it worked fine in other GCC7 versions, then it's probably a regression.

@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2017

@jebrosen Thanks for the fix. I shall implement it. I further try to get a GCC7 working in Travis so such errors can be detected automatically.

As for the bug - it would be great to boil the problem down to a size that is "digestible" by StackOverflow. Any help would be greatly appreciated.

@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: help needed the issue needs help to proceed labels Jun 4, 2017
@nlohmann nlohmann added this to the Release 3.0.0 milestone Jun 4, 2017
@nlohmann nlohmann self-assigned this Jun 4, 2017
nlohmann added a commit that referenced this issue Jun 4, 2017
@nlohmann
Copy link
Owner

nlohmann commented Jun 6, 2017

I opened an issue on StackOverflow, see https://stackoverflow.com/questions/44367859/using-stdarray-and-using-array-as-name

It is not sure yet whether this is an issue in the language or the compilers. Nevertheless, adding parentheses fixes the problem, so I close this issue.

@nlohmann nlohmann closed this as completed Jun 6, 2017
ihaveamac added a commit to ihaveamac/Themely that referenced this issue Sep 4, 2017
rafael1193 added a commit to laas/fire-rs-saop that referenced this issue Oct 25, 2017
facchinm added a commit to arduino/arduino-preprocessor that referenced this issue Jan 17, 2018
zupino added a commit to zupino/integratio that referenced this issue May 20, 2018
henrisve added a commit to henrisve/CarND-MPC-Project that referenced this issue Sep 2, 2018
jandrejk added a commit to jandrejk/ProductionFromNano that referenced this issue Feb 1, 2019
@niklas88
Copy link

This issue seems to have come back with the 3.6.0 release. I guess this was caused by some automatic reformatting: Here's the line that previously had parenthesis

https://github.com/nlohmann/json/blob/release/3.6.0/include/nlohmann/json.hpp#L5731

Also this problem still appears with GCC 8.2.1

@nlohmann
Copy link
Owner

Oh, that's a pity! I use GCC 7 and 8 in the CI, but did not catch this issue. Is it just the array comparison?

@niklas88
Copy link

@nlohmann I haven't tested the commit you linked but adding the parenthesis by hand locally fixes it for me.

danielhertenstein added a commit to PSC-PublicHealth/phil that referenced this issue May 10, 2019
bocon13 pushed a commit to pins/sonic-swss-common-public that referenced this issue Oct 11, 2021
* Add batch set/delete() to ProducerStateTable
* Add StatusCode enum and functions to convert between
  string and enum values.
* Allow exists() to check for whitespace.
  This is only to allow whitespace when we check for
  existence. We can already create entries with whitespace.
* Add SWSS return code SWSS_RC_UNIMPLEMENTED
* Fix json error, refer to nlohmann/json#590

Submission containing materials of a third party:
    Copyright Google LLC; Licensed under Apache 2.0

Co-authored-by: Akarsh Gupta <[email protected]>
Co-authored-by: Jay Hu <[email protected]>
Co-authored-by: Manali Kumar <[email protected]>
Co-authored-by: Robert J. Halstead <[email protected]>
Co-authored-by: Runming Wu <[email protected]>
Co-authored-by: Yilan Ji <[email protected]>

Signed-off-by: Don Newton [email protected]
bocon13 pushed a commit to pins/sonic-swss-common-public that referenced this issue Oct 22, 2021
* Add batch set/delete() to ProducerStateTable
* Add StatusCode enum and functions to convert between
  string and enum values.
* Allow exists() to check for whitespace.
  This is only to allow whitespace when we check for
  existence. We can already create entries with whitespace.
* Add SWSS return code SWSS_RC_UNIMPLEMENTED
* Fix json error, refer to nlohmann/json#590

Submission containing materials of a third party:
    Copyright Google LLC; Licensed under Apache 2.0

Co-authored-by: Akarsh Gupta <[email protected]>
Co-authored-by: Jay Hu <[email protected]>
Co-authored-by: Manali Kumar <[email protected]>
Co-authored-by: Robert J. Halstead <[email protected]>
Co-authored-by: Runming Wu <[email protected]>
Co-authored-by: Yilan Ji <[email protected]>

Signed-off-by: Don Newton [email protected]
bocon13 pushed a commit to pins/sonic-swss-common-public that referenced this issue Oct 22, 2021
* Add batch set/delete() to ProducerStateTable
* Add StatusCode enum and functions to convert between
  string and enum values.
* Allow exists() to check for whitespace.
  This is only to allow whitespace when we check for
  existence. We can already create entries with whitespace.
* Add SWSS return code SWSS_RC_UNIMPLEMENTED
* Fix json error, refer to nlohmann/json#590

Submission containing materials of a third party:
    Copyright Google LLC; Licensed under Apache 2.0

Co-authored-by: Akarsh Gupta <[email protected]>
Co-authored-by: Jay Hu <[email protected]>
Co-authored-by: Manali Kumar <[email protected]>
Co-authored-by: Robert J. Halstead <[email protected]>
Co-authored-by: Runming Wu <[email protected]>
Co-authored-by: Yilan Ji <[email protected]>

Signed-off-by: Don Newton [email protected]
donNewtonAlpha pushed a commit to pins/sonic-swss-common-public that referenced this issue Oct 27, 2021
* Add batch set/delete() to ProducerStateTable
* Add StatusCode enum and functions to convert between
  string and enum values.
* Allow exists() to check for whitespace.
  This is only to allow whitespace when we check for
  existence. We can already create entries with whitespace.
* Add SWSS return code SWSS_RC_UNIMPLEMENTED
* Fix json error, refer to nlohmann/json#590

Submission containing materials of a third party:
    Copyright Google LLC; Licensed under Apache 2.0

Co-authored-by: Akarsh Gupta <[email protected]>
Co-authored-by: Jay Hu <[email protected]>
Co-authored-by: Manali Kumar <[email protected]>
Co-authored-by: Robert J. Halstead <[email protected]>
Co-authored-by: Runming Wu <[email protected]>
Co-authored-by: Yilan Ji <[email protected]>

Signed-off-by: Don Newton [email protected]
donNewtonAlpha pushed a commit to pins/sonic-swss-common-public that referenced this issue Oct 28, 2021
* Add batch set/delete() to ProducerStateTable
* Add StatusCode enum and functions to convert between
  string and enum values.
* Allow exists() to check for whitespace.
  This is only to allow whitespace when we check for
  existence. We can already create entries with whitespace.
* Add SWSS return code SWSS_RC_UNIMPLEMENTED
* Fix json error, refer to nlohmann/json#590

Submission containing materials of a third party:
    Copyright Google LLC; Licensed under Apache 2.0

Co-authored-by: Akarsh Gupta <[email protected]>
Co-authored-by: Jay Hu <[email protected]>
Co-authored-by: Manali Kumar <[email protected]>
Co-authored-by: Robert J. Halstead <[email protected]>
Co-authored-by: Runming Wu <[email protected]>
Co-authored-by: Yilan Ji <[email protected]>

Signed-off-by: Don Newton [email protected]
donNewtonAlpha pushed a commit to pins/sonic-swss-common-public that referenced this issue Oct 28, 2021
* Add batch set/delete() to ProducerStateTable
* Add StatusCode enum and functions to convert between
  string and enum values.
* Allow exists() to check for whitespace.
  This is only to allow whitespace when we check for
  existence. We can already create entries with whitespace.
* Add SWSS return code SWSS_RC_UNIMPLEMENTED
* Fix json error, refer to nlohmann/json#590

Submission containing materials of a third party:
    Copyright Google LLC; Licensed under Apache 2.0

Co-authored-by: Akarsh Gupta <[email protected]>
Co-authored-by: Jay Hu <[email protected]>
Co-authored-by: Manali Kumar <[email protected]>
Co-authored-by: Robert J. Halstead <[email protected]>
Co-authored-by: Runming Wu <[email protected]>
Co-authored-by: Yilan Ji <[email protected]>

Signed-off-by: Don Newton [email protected]
donNewtonAlpha pushed a commit to pins/sonic-swss-common-public that referenced this issue Oct 29, 2021
* Add batch set/delete() to ProducerStateTable
* Add StatusCode enum and functions to convert between
  string and enum values.
* Allow exists() to check for whitespace.
  This is only to allow whitespace when we check for
  existence. We can already create entries with whitespace.
* Add SWSS return code SWSS_RC_UNIMPLEMENTED
* Fix json error, refer to nlohmann/json#590

Submission containing materials of a third party:
    Copyright Google LLC; Licensed under Apache 2.0

Co-authored-by: Akarsh Gupta <[email protected]>
Co-authored-by: Jay Hu <[email protected]>
Co-authored-by: Manali Kumar <[email protected]>
Co-authored-by: Robert J. Halstead <[email protected]>
Co-authored-by: Runming Wu <[email protected]>
Co-authored-by: Yilan Ji <[email protected]>

Signed-off-by: Don Newton [email protected]
donNewtonAlpha pushed a commit to pins/sonic-swss-common-public that referenced this issue Nov 9, 2021
* Add batch set/delete() to ProducerStateTable
* Add StatusCode enum and functions to convert between
  string and enum values.
* Allow exists() to check for whitespace.
  This is only to allow whitespace when we check for
  existence. We can already create entries with whitespace.
* Add SWSS return code SWSS_RC_UNIMPLEMENTED
* Fix json error, refer to nlohmann/json#590

Submission containing materials of a third party:
    Copyright Google LLC; Licensed under Apache 2.0

Co-authored-by: Akarsh Gupta <[email protected]>
Co-authored-by: Jay Hu <[email protected]>
Co-authored-by: Manali Kumar <[email protected]>
Co-authored-by: Robert J. Halstead <[email protected]>
Co-authored-by: Runming Wu <[email protected]>
Co-authored-by: Yilan Ji <[email protected]>

Signed-off-by: Don Newton [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

7 participants