-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
build failure on upcoming gcc-12: test/src/unit-regression1.cpp:392:22: error: ambiguous overload for 'operator=' #3138
Comments
I would like to test this in the CI - can you tell me how I can get a development snapshot of GCC, preferably for Ubuntu? |
Oh, that's a good question. Looking around ubuntu has https://launchpad.net/ubuntu/+source/gcc-snapshot. Looking at From superficial test in VM it's enough to install it as:
I personally build |
Thanks, I was not aware of package |
I can reproduce the issue with |
Same error occurred again in #3226 |
GCC 12 is now in Fedora Rawhide, if that helps with testing. (I found this bug because it’s causing https://github.com/monocasual/giada builds to fail in Fedora Rawhide.) |
I can confirm. All dependent packages are now FTBFS. |
That's too bad. I have not yet understood the reason for the error, let alone whether it's a bug in the library and how to fix it. |
https://jwakely.github.io/pkg-gcc-latest/ has GCC snapshots packages for Ubuntu, Fedora, RHEL/CentOS and Tumbleweed. The error is due to GCC 12 implementing P2166R1 "Prohibit std::basic_string and std::basic_string_view construction from nullptr", which is required by the C++23 draft. I made the change apply unconditionally to older standards too, because assigning |
As described in https://en.cppreference.com/w/cpp/23, we will have the same problem with Clang libc++ 13 and MSVC STL 19.30. What I have not understood is whether deleting |
I have found https://www.kitware.com/itk-informs-c-stl-development/ a while ago and from that I would say this is only deleted in C++23 builds. See also microsoft/STL#1995 (comment) from linked from there. |
The deleted Could you give a simplified example of what conversion is supposed to happen when constructing a |
I think this is probably an approximation of what you're doing, right? #include <string>
struct S
{
operator const char*() const { return ""; }
operator std::nullptr_t() const { return {}; }
};
std::string s{ S{} }; This is valid in C++20 and earlier, but ill-formed in C++23. And it demonstrates that the change should be limited to C++23. I'll change GCC. |
Filed as a GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104099 |
I've compiled latest gcc-trunk locally here diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 92308c557..8fd2b357f 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -19043,6 +19043,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template < typename ValueType, typename std::enable_if <
detail::conjunction <
detail::negation<std::is_pointer<ValueType>>,
+ detail::negation<std::is_same<ValueType, nullptr_t>>,
detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>,
detail::negation<std::is_same<ValueType, typename string_t::value_type>>,
detail::negation<detail::is_basic_json<ValueType>>, it compiles and all tests pass. The fix goes in the same direction as #3138 (comment). It would have helped me if I read the reply first before trying to fix it ;) EDIT: json/include/nlohmann/json.hpp Lines 1870 to 1890 in 293f67f
|
Thanks @t-b for the fix! I tried it, and it worked for GCC 12. Unfortunately, it does not work for any other compiler :-/ See #3226. The error is
Any idea? |
Should be |
Good catch! Totally overlooked that. :-/ |
Jeep |
The code compiles, but there is one test failing when compiling the code with C++20:
The same test succeeds with Clang (Linux, macOS) in C++20 mode. Any ideas? |
Looks like a change in how the default comparisons are happening in C++20 with the new generated comparisons. Looking at this in Compiler Explorer to see if I can track it down. |
Confirmed different behavior of comparing The former calls |
Would it make sense to implement |
If you have implicit conversions then yes, you should provide your own |
I dug into that and still couldn't get it to pass. It would be good to replace all the comparison and equality operators with |
Worse than "won't necessarily fix this issue", libcxx [1] doesn't fully implement three way comparison for various So, we'll have to solve/work around the underlying issue using the existing operators first, then optionally add the spaceship operator and guard that with Guess I know how I'll spend the weekend. 😉 |
* 🔧 use proper GCC binary * 🔧 add more GCC warning flags * ⚗️ try fix from #3138 (comment) * Fix custom allocator test build failures (C++20) Allocator tests fail to compile in C++20 mode with clang+MS STL due to missing copy constructors. * Fix test build failures due to missing noexcept (gcc-12) * alt_string has multiple member functions that should be marked noexcept. * nlohmann::ordered_map constructors can be noexcept. Compilation failures result from the warning flag -Werror=noexcept and gcc-12. * Disable broken comparison tests in C++20 mode Co-authored-by: Niels Lohmann <[email protected]>
On
gcc-12
(20211107 snapshot)std::string
amended it's constructors to a form that fails regression tests building:Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchThe text was updated successfully, but these errors were encountered: