Skip to content

Conversation

joankaradimov
Copy link
Contributor

@joankaradimov joankaradimov commented Oct 21, 2021

I get this compilation error on versions 0.21.1 and 22.0:

fs.cpp: In member function 'bool fsbridge::FileLock::TryLock()':
fs.cpp:123:89: error: 'numeric_limits' is not a member of 'std'
  123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
      |                                                                                         ^~~~~~~~~~~~~~
fs.cpp:123:109: error: expected primary-expression before '>' token
  123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
      |                                                                                                             ^
fs.cpp:123:112: error: '::max' has not been declared; did you mean 'std::max'?
  123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
      |                                                                                                                ^~~
      |                                                                                                                std::max
In file included from C:/dev/msys64/mingw64/include/c++/11.2.0/bits/char_traits.h:39,
                 from C:/dev/msys64/mingw64/include/c++/11.2.0/string:40,
                 from ./fs.h:9,
                 from fs.cpp:5:
C:/dev/msys64/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: 'std::max' declared here
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
fs.cpp:123:124: error: 'numeric_limits' is not a member of 'std'
  123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
      |                                                                                                                            ^~~~~~~~~~~~~~
fs.cpp:123:144: error: expected primary-expression before '>' token
  123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
      |                                                                                                                                                ^
fs.cpp:123:147: error: '::max' has not been declared; did you mean 'std::max'?
  123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
      |                                                                                                                                                   ^~~
      |                                                                                                                                                   std::max
In file included from C:/dev/msys64/mingw64/include/c++/11.2.0/bits/char_traits.h:39,
                 from C:/dev/msys64/mingw64/include/c++/11.2.0/string:40,
                 from ./fs.h:9,
                 from fs.cpp:5:
C:/dev/msys64/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: 'std::max' declared here
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~

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.

@theuni
Copy link
Member

theuni commented Oct 21, 2021

Looks like this only affects windows because it's in the #ifndef WIN32 #else case. So it makes sense to move this to only include this with the other windows defines.

Trivial ACK otherwise.

@joankaradimov
Copy link
Contributor Author

Looks like this only affects windows because it's in the #ifndef WIN32 #else case.

Yes, exactly. My guess is that <string> includes <limits> on Unix/gcc and <codecvt> includes <limits> on Windows/MSVC. But <codecvt> does not include <limits> on Windows/gcc. I haven't checked that, though.

it makes sense to move this to only include this with the other windows defines

Well, transitive includes are implementation-specific. I'd say - just always include <limits> to be on the safe side.

@theuni
Copy link
Member

theuni commented Oct 21, 2021

Only the windows code paths use std::numeric_limits. The transitivity is moot elsewhere.

Otherwise I'd agree :)

@joankaradimov
Copy link
Contributor Author

Oh, sorry 🤦‍♂️

I was looking at the ifndef WIN32 at the top of the file and I completely missed the one around the implementation of FileLock::TryLock.

Updated and force pushed.

@fanquake
Copy link
Member

Please write a more descriptive commit message title. i.e refactor: add missing <limits> header to fs.cpp

... needed for std::numeric_limits<T>::max on WIN32
@joankaradimov
Copy link
Contributor Author

Please write a more descriptive commit message title. i.e refactor: add missing <limits> header to fs.cpp

Updated and force pushed.

@fanquake fanquake changed the title Include a missing header refactor: include a missing <limits> header in fs.cpp Oct 22, 2021
Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

ACK 077a875 - Thanks.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK 077a875

FWIW, the <limits> header is also missed in multiple other places. This is another reason to consider #15442.

@maflcko maflcko merged commit 4833d1f into bitcoin:master Oct 22, 2021
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Oct 22, 2021
... needed for std::numeric_limits<T>::max on WIN32

Github-Pull: bitcoin#23335
Rebased-From: 077a875
@fanquake
Copy link
Member

Backported to 22.x in #23276.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 22, 2021
…s.cpp

077a875 refactor: include a missing <limits> header in fs.cpp (Joan Karadimov)

Pull request description:

  I get this compilation error on versions `0.21.1` and `22.0`:

  ```
  fs.cpp: In member function 'bool fsbridge::FileLock::TryLock()':
  fs.cpp:123:89: error: 'numeric_limits' is not a member of 'std'
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                         ^~~~~~~~~~~~~~
  fs.cpp:123:109: error: expected primary-expression before '>' token
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                             ^
  fs.cpp:123:112: error: '::max' has not been declared; did you mean 'std::max'?
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                                ^~~
        |                                                                                                                std::max
  In file included from C:/dev/msys64/mingw64/include/c++/11.2.0/bits/char_traits.h:39,
                   from C:/dev/msys64/mingw64/include/c++/11.2.0/string:40,
                   from ./fs.h:9,
                   from fs.cpp:5:
  C:/dev/msys64/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: 'std::max' declared here
    300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
        |     ^~~
  fs.cpp:123:124: error: 'numeric_limits' is not a member of 'std'
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                                            ^~~~~~~~~~~~~~
  fs.cpp:123:144: error: expected primary-expression before '>' token
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                                                                ^
  fs.cpp:123:147: error: '::max' has not been declared; did you mean 'std::max'?
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                                                                   ^~~
        |                                                                                                                                                   std::max
  In file included from C:/dev/msys64/mingw64/include/c++/11.2.0/bits/char_traits.h:39,
                   from C:/dev/msys64/mingw64/include/c++/11.2.0/string:40,
                   from ./fs.h:9,
                   from fs.cpp:5:
  C:/dev/msys64/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: 'std::max' declared here
    300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
        |     ^~~
  ```

  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.

ACKs for top commit:
  fanquake:
    ACK 077a875 - Thanks.
  hebasto:
    ACK 077a875

Tree-SHA512: 2289cb72fa3a28470f4250833be66079482d1392189b1e4679330dad109a8ae67b1d6d51cb635dbc1947c00c6c4cfbc4d7c9ae02269b932cfa1475583adaf73d
@joankaradimov joankaradimov deleted the include-missing-header branch October 22, 2021 21:27
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Feb 14, 2022
... needed for std::numeric_limits<T>::max on WIN32

Github-Pull: bitcoin#23335
Rebased-From: 077a875
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Feb 15, 2022
... needed for std::numeric_limits<T>::max on WIN32

Github-Pull: bitcoin#23335
Rebased-From: 077a875
fanquake added a commit that referenced this pull request Mar 1, 2022
269553f test: Call ceildiv helper with integer (Martin Zumsande)
2f60fc6 ci: Replace soon EOL hirsute with jammy (MarcoFalke)
801b0f0 build: patch qt to explicitly define previously implicit header include (Kittywhiskers Van Gogh)
c768bfa tests: Calculate fees more similarly to CFeeRate::GetFee (Andrew Chow)
f66bc42 tests: Test for assertion when feerate is rounded down (Andrew Chow)
bd7e08e fees: Always round up fee calculated from a feerate (Andrew Chow)
227ae65 wallet: fix segfault by avoiding invalid default-ctored `external_spk_managers` entry (Sebastian Falbesoner)
282863a refactor: include a missing <limits> header in fs.cpp (Joan Karadimov)
7febe4f consensus: don't call GetBlockPos in ReadBlockFromDisk without lock (Jon Atack)
c671c6f the result of CWallet::IsHDEnabled() was initialized with true. (Saibato)
a5a1538 build, qt: Fix typo in QtInputSupport check (Hennadii Stepanov)
c95b188 system: skip trying to set the locale on NetBSD (fanquake)
c1cdedd guix: Fix powerpc64(le) dynamic linker name (Carl Dong)
92d44ff doc: Add 23061 release notes (MarcoFalke)
db76db7 Fix (inverse) meaning of -persistmempool (MarcoFalke)
85c78e0 build: Restrict check for CRC32C intrinsic to aarch64 (W. J. van der Laan)

Pull request description:

  Collecting backports for the 22.1 release. Currently:
  * #23045
  * #23061
  * #23148
  * #22390
  * #22820
  * #22781
  * #22895
  * #23335
  * #23333
  * #22949
  * #23580
  * #23504
  * #24239

ACKs for top commit:
  achow101:
    ACK 269553f

Tree-SHA512: b3a57ea241be7a83488eeb032276f4cf82a0987aada906a82f94a20c4acf9f2397708249dcecbe1c7575e70d09c60b835233d4718af4013c7bc58896c618274c
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 3, 2022
…s.cpp

077a875 refactor: include a missing <limits> header in fs.cpp (Joan Karadimov)

Pull request description:

  I get this compilation error on versions `0.21.1` and `22.0`:

  ```
  fs.cpp: In member function 'bool fsbridge::FileLock::TryLock()':
  fs.cpp:123:89: error: 'numeric_limits' is not a member of 'std'
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                         ^~~~~~~~~~~~~~
  fs.cpp:123:109: error: expected primary-expression before '>' token
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                             ^
  fs.cpp:123:112: error: '::max' has not been declared; did you mean 'std::max'?
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                                ^~~
        |                                                                                                                std::max
  In file included from C:/dev/msys64/mingw64/include/c++/11.2.0/bits/char_traits.h:39,
                   from C:/dev/msys64/mingw64/include/c++/11.2.0/string:40,
                   from ./fs.h:9,
                   from fs.cpp:5:
  C:/dev/msys64/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: 'std::max' declared here
    300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
        |     ^~~
  fs.cpp:123:124: error: 'numeric_limits' is not a member of 'std'
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                                            ^~~~~~~~~~~~~~
  fs.cpp:123:144: error: expected primary-expression before '>' token
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                                                                ^
  fs.cpp:123:147: error: '::max' has not been declared; did you mean 'std::max'?
    123 |     if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
        |                                                                                                                                                   ^~~
        |                                                                                                                                                   std::max
  In file included from C:/dev/msys64/mingw64/include/c++/11.2.0/bits/char_traits.h:39,
                   from C:/dev/msys64/mingw64/include/c++/11.2.0/string:40,
                   from ./fs.h:9,
                   from fs.cpp:5:
  C:/dev/msys64/mingw64/include/c++/11.2.0/bits/stl_algobase.h:300:5: note: 'std::max' declared here
    300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
        |     ^~~
  ```

  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.

ACKs for top commit:
  fanquake:
    ACK 077a875 - Thanks.
  hebasto:
    ACK 077a875

Tree-SHA512: 2289cb72fa3a28470f4250833be66079482d1392189b1e4679330dad109a8ae67b1d6d51cb635dbc1947c00c6c4cfbc4d7c9ae02269b932cfa1475583adaf73d
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Jun 9, 2022
... needed for std::numeric_limits<T>::max on WIN32

Github-Pull: bitcoin#23335
Rebased-From: 077a875
@fanquake fanquake mentioned this pull request Jun 9, 2022
@fanquake
Copy link
Member

fanquake commented Jun 9, 2022

Backported to 0.21 in #25318.

fanquake added a commit that referenced this pull request Jun 10, 2022
efb9f00 build: Restrict check for CRC32C intrinsic to aarch64 (W. J. van der Laan)
cfb08c3 refactor: include a missing <limits> header in fs.cpp (Joan Karadimov)

Pull request description:

  There might not be another 0.21.x release, however these are both straight forward changes. If this isn't merged, then the pulls can remain untagged for needing backport.

  Backports:
  - #23045
  - #23335

ACKs for top commit:
  laanwj:
    ACK efb9f00
  LarryRuane:
    utACK efb9f00

Tree-SHA512: 09be8f8ce90f862e2d408c5707a8387ca828fdd05a9814cfed5236030a3b33012e7d7a557c2ee3989db26922ad45cb8a307bdeba7ac8e34b5f21f0d46eda1955
delta1 added a commit to delta1/elements that referenced this pull request May 14, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Jun 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants