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

use of undeclared identifier 'SIZE_MAX' #460

Open
Andarwinux opened this issue Oct 10, 2024 · 6 comments
Open

use of undeclared identifier 'SIZE_MAX' #460

Andarwinux opened this issue Oct 10, 2024 · 6 comments

Comments

@Andarwinux
Copy link
Contributor

I'm sorry I couldn't find a smaller reproduction of this

mkdir test && cd test && export TEST=$(pwd)

git clone https://github.com/libssh2/libssh2.git && cd libssh2

cmake -GNinja -Bbuild -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-clang -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-clang++ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$TEST/install -DBUILD_SHARED_LIBS=OFF -DCRYPTO_BACKEND=WinCNG -DENABLE_ZLIB_COMPRESSION=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF

ninja -C build install

cd $TEST

git clone https://github.com/aria2/aria2.git && cd aria2

export PKG_CONFIG_LIBDIR=$TEST/install/lib/pkgconfig

autoreconf -fi

./configure --enable-static --with-libssh2 --host=x86_64-w64-mingw32 --prefix=$TEST/install --disable-shared

make -j16

In file included from SSHSession.cc:35:
In file included from ./SSHSession.h:39:
In file included from ./a2netcompat.h:94:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/string:648:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/string_view:958:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/algorithm:1851:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__algorithm/for_each.h:16:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__ranges/movable_box.h:21:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/optional:1297:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/memory:944:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__memory/inout_ptr.h:16:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__memory/shared_ptr.h:32:
/home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__memory/unique_ptr.h:379:88: error: use of undeclared identifier 'SIZE_MAX'
  379 |   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __unique_ptr_array_bounds_stored() : __size_(SIZE_MAX) {}
      |                                                                                        ^
  CXX      AnnounceList.lo
  CXX      AnnounceTier.lo
1 error generated.

This happens in llvm-mingw nightly, and is caused by llvm/llvm-project@18df9d2 to be exact, if I replace SIZE_MAX with __SIZE_MAX__ it doesn't cause a problem, but that commit itself doesn't look wrong. I don't know why SIZE_MAX isn't defined, cstdint should end up include stdint.h from mingw.

@mstorsjo
Copy link
Owner

Can you isolate the individual source file from the build, triggering the issue? And can you reduce the included headers from there, to only including libc++ headers, triggering the issue? I would guess that there's some either command line or source level define somewhere that triggers this. Not saying it isn't a libc++ and/or mingw bug though, but we'd need a smaller reproduction to be able to say for sure.

@Andarwinux
Copy link
Contributor Author

Can you isolate the individual source file from the build, triggering the issue? And can you reduce the included headers from there, to only including libc++ headers, triggering the issue? I would guess that there's some either command line or source level define somewhere that triggers this. Not saying it isn't a libc++ and/or mingw bug though, but we'd need a smaller reproduction to be able to say for sure.

I found a smaller reproduction
test.zip

[arch@wsl test]$ x86_64-w64-mingw32-clang++ -c -I -DHAVE_WINSOCK2_H -DHAVE_WS2TCPIP_H -DHAVE_INTTYPES_H SSHSession.cc
In file included from SSHSession.cc:35:
In file included from ./SSHSession.h:39:
In file included from ./a2netcompat.h:94:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/string:648:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/string_view:958:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/algorithm:1851:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__algorithm/for_each.h:16:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__ranges/movable_box.h:21:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/optional:1297:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/memory:944:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__memory/inout_ptr.h:16:
In file included from /home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__memory/shared_ptr.h:32:
/home/arch/workspace/toolchain/llvm-mingw/x86_64-w64-mingw32/include/c++/v1/__memory/unique_ptr.h:379:88: error: use of undeclared identifier 'SIZE_MAX'
  379 |   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __unique_ptr_array_bounds_stored() : __size_(SIZE_MAX) {}
      |                                                                                        ^
1 error generated.

@mstorsjo
Copy link
Owner

Ok, I've reproed that. But when I try the same, I'm also getting another error, which also is present when building with a release:

In file included from SSHSession.cc:35:
In file included from ./SSHSession.h:39:
./a2netcompat.h:117:3: error: unknown type name 'sockaddr_in6'; did you mean 'sockaddr_in'?
  117 |   sockaddr_in6 in6;
      |   ^~~~~~~~~~~~
      |   sockaddr_in
/home/martin/llvm-mingw-20240917-ucrt-ubuntu-20.04-x86_64/x86_64-w64-mingw32/include/psdk_inc/_ip_types.h:75:8: note: 'sockaddr_in' declared here
   75 | struct sockaddr_in {
      |        ^
In file included from SSHSession.cc:35:
In file included from ./SSHSession.h:39:
./a2netcompat.h:123:3: error: unknown type name 'socklen_t'
  123 |   socklen_t suLength;
      |   ^
2 errors generated.

I presume that's unrelated to the libcxx header issue anyway.

@mstorsjo
Copy link
Owner

I've reduced it down to a much smaller issue, and I would say that this isn't really the fault of libcxx. A minimal reproducer of the issue is this:

#include <limits.h>
#include <stdint.h>
#undef SIZE_MAX
#include <string>

Previously, <string> wouldn't include anything that needs SIZE_MAX, but after the linked libc++ commit, it now does. Both <limits.h> and <stdint.h> can provide a definition of SIZE_MAX if it isn't already defined, but by including both of them before we do #undef SIZE_MAX, we essentially make sure that we won't be getting a new definition of the type again.

When you look at it in this form, it obviously seems quite absurd, but this is that the attached example boils down to. See your gai_strerror.h which contains this bit:

#ifdef __MINGW32__
#  undef SIZE_MAX
#endif // __MINGW32__

And all the other headers around end up having the same effect as in the reduced example above.

@mstorsjo
Copy link
Owner

I've reduced it down to a much smaller issue, and I would say that this isn't really the fault of libcxx. A minimal reproducer of the issue is this:

#include <limits.h>
#include <stdint.h>
#undef SIZE_MAX
#include <string>

I guess it could, maybe, be argued that libcxx internally shouldn't be using SIZE_MAX, but should use __SIZE_MAX__ instead though.

Andarwinux added a commit to Andarwinux/aria2 that referenced this issue Oct 10, 2024
undef SIZE_MAX caused building aria2 with libc++20 to fail, because libc++ uses this definition internally.

ref:
mstorsjo/llvm-mingw#460
llvm/llvm-project#91798 (comment)
@Andarwinux
Copy link
Contributor Author

I've reduced it down to a much smaller issue, and I would say that this isn't really the fault of libcxx. A minimal reproducer of the issue is this:

#include <limits.h>
#include <stdint.h>
#undef SIZE_MAX
#include <string>

Previously, <string> wouldn't include anything that needs SIZE_MAX, but after the linked libc++ commit, it now does. Both <limits.h> and <stdint.h> can provide a definition of SIZE_MAX if it isn't already defined, but by including both of them before we do #undef SIZE_MAX, we essentially make sure that we won't be getting a new definition of the type again.

When you look at it in this form, it obviously seems quite absurd, but this is that the attached example boils down to. See your gai_strerror.h which contains this bit:

#ifdef __MINGW32__
#  undef SIZE_MAX
#endif // __MINGW32__

And all the other headers around end up having the same effect as in the reduced example above.

I will try to fix this in aria2 🤣.

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

No branches or pull requests

2 participants