I get this compilation error on versions 0.21.1
and 22.0
:
0fs.cpp: In member function 'bool fsbridge::FileLock::TryLock()':
1fs.cpp:123:89: error: 'numeric_limits' is not a member of 'std'
2 123 | if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
3 | ^~~~~~~~~~~~~~
4fs.cpp:123:109: error: expected primary-expression before '>' token
5 123 | if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
6 | ^
7fs.cpp:123:112: error: '::max' has not been declared; did you mean 'std::max'?
8 123 | if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
9 | ^~~
10 | std::max
11In file included from C:/dev/msys64/mingw64/include/c++/11.2.0/bits/char_traits.h:39,
12 from C:/dev/msys64/mingw64/include/c++/11.2.0/string:40,
13 from ./fs.h:9,
14 from fs.cpp:5:
15C:/dev/msys64/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: 'std::max' declared here
16 300 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
17 | ^~~
18fs.cpp:123:124: error: 'numeric_limits' is not a member of 'std'
19 123 | if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
20 | ^~~~~~~~~~~~~~
21fs.cpp:123:144: error: expected primary-expression before '>' token
22 123 | if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
23 | ^
24fs.cpp:123:147: error: '::max' has not been declared; did you mean 'std::max'?
25 123 | if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
26 | ^~~
27 | std::max
28In file included from C:/dev/msys64/mingw64/include/c++/11.2.0/bits/char_traits.h:39,
29 from C:/dev/msys64/mingw64/include/c++/11.2.0/string:40,
30 from ./fs.h:9,
31 from fs.cpp:5:
32C:/dev/msys64/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: 'std::max' declared here
33 300 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
34 | ^~~
It appears that std::numeric_limits<T>::max
is used without the limits
header being included. Probably on other STL implementations it’s included transitively, but not in the one in MinGW. Including it fixes the compilation problem.
Environment: OS: Windows 10 Compiler: gcc 11.2.0 Qt: 5.15.2 (included in msys2) Using the latest mingw w64 shipped with msys2.