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

Fix compilation error with Clang, C++17, libc++, ordered_json and NLOHMANN_JSON_SERIALIZE_ENUM #2624

Closed
wants to merge 3 commits into from

Conversation

alexezeder
Copy link

@alexezeder alexezeder commented Feb 5, 2021

Closes #2491.

Caused by the strange behavior (or maybe even a bug) of Clang described in the linked issue #2491 and also on LLVM bug tracker.

There are 2 commits - the first one is to add testing usage of ordered_json with enum (just like in the issue), the second resolves the problem for Clang with libc++ and C++17+. Since there is no CI workflow for that, I made a temporary workflow with Clang, C++17 and libc++ in my fork just to demonstrate the build results of these commits:

commit Ubuntu MacOS
add test for enum and ordered_json ❌ failed ❌ failed
guard instantiation of detail::detector in conversion operator of basic_json ✔️ successful ✔️ successful

P.S. I tried to reuse the existing Clang C++20 workflow for the temporary workflow with libc++, since there is no difference in Clang's behavior between C++17 and C++20 standards in this case, but libc++ of the used LLVM version does not provide <span> header, just for information.

Filled checklist here

Pull request checklist

Read the Contribution Guidelines for detailed information.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header file single_include/nlohmann/json.hpp. The whole process is described here.

Please don't

  • The C++11 support varies between different compilers and versions. Please note the list of supported compilers. Some compilers like GCC 4.7 (and earlier), Clang 3.3 (and earlier), or Microsoft Visual Studio 13.0 and earlier are known not to work due to missing or incomplete C++11 support. Please refrain from proposing changes that work around these compiler's limitations with #ifdefs or other means.
  • Specifically, I am aware of compilation problems with Microsoft Visual Studio (there even is an issue label for these kind of bugs). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
  • Please refrain from proposing changes that would break JSON conformance. If you propose a conformant extension of JSON to be supported by the library, please motivate this extension.
  • Please do not open pull requests that address multiple issues.

@alexezeder alexezeder requested a review from nlohmann as a code owner February 5, 2021 18:40
@coveralls
Copy link

coveralls commented Feb 5, 2021

Coverage Status

Coverage decreased (-99.8%) to 0.214% when pulling ae9cfb1 on alexezeder:issue2491 into 18a5f4c on nlohmann:develop.

@alexezeder alexezeder marked this pull request as draft February 6, 2021 09:30
@alexezeder alexezeder marked this pull request as ready for review February 6, 2021 10:12
@nlohmann
Copy link
Owner

nlohmann commented Mar 24, 2021

@ alexezeder Can you please update to the latest develop branch? I overworked the CI and added quite some checks.

@alexezeder
Copy link
Author

@nlohmann, finally, CI has done its job

Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change request, then it should be good to merge.

@alexezeder
Copy link
Author

I don't know what should I do with an error in Windows/mingw:

C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\test-conversions.dir\src\unit-conversions.cpp.obj: too many sections (32979)
C:\Users\RUNNER~1\AppData\Local\Temp\ccbxRRFM.s: Assembler messages:
C:\Users\RUNNER~1\AppData\Local\Temp\ccbxRRFM.s: Fatal error: can't write 300 bytes to section .text of CMakeFiles\test-conversions.dir\src\unit-conversions.cpp.obj: 'File too big'
[ 56%] Building CXX object test/CMakeFiles/test-inspection.dir/src/unit-inspection.cpp.obj
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\test-conversions.dir\src\unit-conversions.cpp.obj: too many sections (32979)
C:\Users\RUNNER~1\AppData\Local\Temp\ccbxRRFM.s: Fatal error: can't close CMakeFiles\test-conversions.dir\src\unit-conversions.cpp.obj: File too big

@nlohmann
Copy link
Owner

Maybe https://digitalkarabela.com/mingw-w64-how-to-fix-file-too-big-too-many-sections/ can help. I will try to add that flag to the CI.

@nlohmann
Copy link
Owner

Can you please change line 24 of file .github/workflows/windows.yml

from

        run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On

to

        run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS=-Wa,-mbig-obj

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compilation error when using NLOHMANN_JSON_SERIALIZE_ENUM ordered_json on libc++
3 participants