clang and libc++: compile error in json.h
For reasons I tried to compile a simple program with clang++ (13.0.1) and libc++ (13.0.1). I got a monster error message hinting at wvalue& operator=(object const& value) and wvalue& operator=(std::initializer_list<std::pair<std::string const, wvalue>> initializer_list), compiling with clang++ -stdlib=libc++ -I ./Crow/include/ main.cc -o main
The error refers to the assignments of value or initializer_list to (*o). wvalue contains unique_ptrs, which can't be copied. So I guess clang++ is right. Using the __APPLE__ or __MACH__ execution path unconditionally fixes the error in my experiments.
Is this a scenario (clang, libc++ on linux) crow should support? I could just "implement" the fix mentioned above. Or dig deeper and try to find out more about the cause of the error. I wonder why this is no problem with libstdc++. This lib should complain about copying unique_ptrs too. I suspect there's a flaw in my analysis so far :)
Is this a scenario (clang, libc++ on linux) crow should support?
It absolutely should, I'm guessing this is a problem with our CI process which I should address (that it doesn't test with libc++)
This issue seems to be the result of an oversight in #242. The workaround is already in place, but my guess is that MacOS uses libc++ by default, which is why I assumed the bug was related to the OS rather than the standard template library.
I'm sorry it took me this long to investigate.
The fix for this would be to change the macro from Apple related to libc++ related, and having a comment explaining what's going on.
I was busy with other things myself, so I had close to no time to dig deeper. For me this looks like: wvalue contains std::unique_ptrs. The code in question does assignments from wvalues. So the wvalues should be moved not copied. I don't see a move in the code in question. What am I missing?
Well the code in question does assignments from initializer_lists and objects. You might be correct in that the lists would need to be moved, but the objects already have an rvalue assignment operator that does the moving, for a normal lvalue assignment the data needs to be copied, the reason the macros are there is because I didn't want to construct a new object when I could use the existing object's assignment operator. I hope that made sense..