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

Compilation errors when including <filesystem> and using --std=c++17 or above (MinGW/Win10) #3449

Closed
underscoren opened this issue Apr 21, 2022 · 3 comments
Labels
solution: invalid the issue is not related to the library

Comments

@underscoren
Copy link

underscoren commented Apr 21, 2022

Description

Including <filesystem> anywhere alongside "json.hpp" produces a massive amount of compilation errors.
This only occurs when --std=c++17 (or c++2a) flag is set.

Might be related to #3090 ?

Reproduction steps

  1. Install MinGW (IIRC, I used the MinGW-w64 installer from MingW-W64-builds)
  2. Write valid c++ code that includes <filesystem> and "json.hpp"
  3. Compile using g++, ensuring you have the --std=c++17 flag

Expected vs. actual results

Expected: Code should compile without errors
Results: Massive amount (800+ lines) of errors during compilation

Minimal code example

#include "json.hpp"
#include <filesystem> 
// errors regardless if included before or after

int main() {
    return 0;
}

Error messages

Sample of the top 30 lines:

In file included from C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from main.cpp:2:
C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')    || (__p.has_root_name() && __p.root_name() != root_name()))
                               ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/utility:70,
                 from C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/algorithm:60,
                 from json.hpp:46,
                 from main.cpp:1:
C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_pair.h:456:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^~~~~~~~
C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_pair.h:456:5: note:   template argument deduction/substitution failed:
In file included from C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from main.cpp:2:
C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:60: note:   'std::filesystem::__cxx11::path' is not derived from 'const std::pair<_T1, _T2>'
    || (__p.has_root_name() && __p.root_name() != root_name()))
                                                            ^
In file included from C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_algobase.h:67,
                 from C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/algorithm:61,
                 from json.hpp:46,
                 from main.cpp:1:
C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h:311:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
     operator!=(const reverse_iterator<_Iterator>& __x,
     ^~~~~~~~
C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h:311:5: note:   template argument deduction/substitution failed:
In file included from C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from main.cpp:2:
C:/bin/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:60: note:   'std::filesystem::__cxx11::path' is not derived from 'const std::reverse_iterator<_Iterator>'
    || (__p.has_root_name() && __p.root_name() != root_name()))
                                                            ^

... continues for 800+ lines. See errors.txt for full error log.



### Compiler and operating system

g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0 on Windows 10

### Library version

3.10.5 (from GitHub release)

### Validation

- [X] The bug also occurs if the latest version from the [`develop`](https://github.com/nlohmann/json/tree/develop) branch is used.
- [X] I can successfully [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests).
@nlohmann
Copy link
Owner

Can you please compile the following program with the develop version and post its output here:

#define JSON_TEST_KEEP_MACROS
#include <nlohmann/json.hpp>
#include <iostream>

int main() {
    std::cout << "JSON_HAS_FILESYSTEM = " << JSON_HAS_FILESYSTEM << std::endl;
    std::cout << "JSON_HAS_EXPERIMENTAL_FILESYSTEM = " << JSON_HAS_EXPERIMENTAL_FILESYSTEM << std::endl;
}

@underscoren
Copy link
Author

underscoren commented Apr 21, 2022

Output:

JSON_HAS_FILESYSTEM = 0
JSON_HAS_EXPERIMENTAL_FILESYSTEM = 0

Okay, I suppose I should have checked this first, but turns out MinGW-W64 8.1.0 from MinGW-W64-builds has a bug from 2018 when using <filesystem> that still hasn't been fixed. The apparent solution is to get MSYS2 and get the latest build from there, because support for it has been dropped.

Since this has nothing to do with this library, I'm going to close this.

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug labels Apr 21, 2022
@nlohmann
Copy link
Owner

Thanks for checking back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants