Skip to content

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

@underscoren

Description

@underscoren

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions