Skip to content

BUILD: fix missing include for std::ptrdiff_t for C++23 language mode#27416

Merged
charris merged 1 commit intonumpy:maintenance/2.1.xfrom
charris:backport-27361
Sep 18, 2024
Merged

BUILD: fix missing include for std::ptrdiff_t for C++23 language mode#27416
charris merged 1 commit intonumpy:maintenance/2.1.xfrom
charris:backport-27361

Conversation

@charris
Copy link
Member

@charris charris commented Sep 18, 2024

Backport of #27361.

This tiny PR fixes a failure happening when building numpy in C++23 language mode.

This issue is caused by the ongoing cleanup of C++ standard library from transitive includes, if they aren't explicitely allowed by the standard.

In particular, in string_fastsearch.h we rely on std::ptrdiff_t but don't explicitely include its header, cstddef, as prescribed bt the standard.

Before C++23, this worked fine as some other headers we included transitvely included cstddef.

Without this fix, both on Clang/LLVM and GCC upstreams the following error is observed:
../numpy/_core/src/umath/string_fastsearch.h:132:5: error: no type named 'ptrdiff_t' in namespace 'std'; did you mean simply 'ptrdiff_t'?

Please, find the attached logs with full details.
log.txt

@charris charris added 08 - Backport Used to tag backport PRs 36 - Build Build related PR labels Sep 18, 2024
@charris charris added this to the 2.1.2 release milestone Sep 18, 2024
@charris charris merged commit 5e314c7 into numpy:maintenance/2.1.x Sep 18, 2024
@sergiud
Copy link

sergiud commented Apr 18, 2025

Are there any plans backporting this fix to the maintenance/2.0.x branch? pypy 3.9 builds of NumPy 2.0.2 started failing recently on macOS 15 Clang 16.0.0 due to

FAILED: numpy/_core/_multiarray_umath.pypy39-pp73-darwin.so.p/src_umath_string_ufuncs.cpp.o
c++ -Inumpy/_core/_multiarray_umath.pypy39-pp73-darwin.so.p -Inumpy/_core -I../numpy/_core -Inumpy/_core/include -I../numpy/_core/include -I../numpy/_core/src/common -I../numpy/_core/src/multiarray -I../numpy/_core/src/npymath -I../numpy/_core/src/umath -I../numpy/_core/src/highway -I/Users/runner/work/hogpp/hogpp/.cibuildwheel/pypy3.9-v7.3.16-macos_arm64/include/pypy3.9 -I/private/var/folders/_d/l5rp6h1s2bnfkdsrc1wc54t00000gn/T/pip-install-luog790t/numpy_f604cee84c334f3ebc194bdadda2dee7/.mesonpy-u82k8a4a/meson_cpu -fvisibility=hidden -fvisibility-inlines-hidden -fdiagnostics-color=always -DNDEBUG -Wall -Winvalid-pch -std=c++17 -O3 -ftrapping-math -DNPY_HAVE_CLANG_FPSTRICT -DNPY_HAVE_NEON_VFPV4 -DNPY_HAVE_NEON_FP16 -DNPY_HAVE_NEON -DNPY_HAVE_ASIMD -flto=auto -DPYBIND11_DETAILED_ERROR_MESSAGES -F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework -idirafter/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Headers -DACCELERATE_NEW_LAPACK -DHAVE_CBLAS '-DBLAS_SYMBOL_SUFFIX=$NEWLAPACK' -DNPY_INTERNAL_BUILD -DHAVE_NPY_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -D__STDC_VERSION__=0 -fno-exceptions -fno-rtti -MD -MQ numpy/_core/_multiarray_umath.pypy39-pp73-darwin.so.p/src_umath_string_ufuncs.cpp.o -MF numpy/_core/_multiarray_umath.pypy39-pp73-darwin.so.p/src_umath_string_ufuncs.cpp.o.d -o numpy/_core/_multiarray_umath.pypy39-pp73-darwin.so.p/src_umath_string_ufuncs.cpp.o -c ../numpy/_core/src/umath/string_ufuncs.cpp
In file included from ../numpy/_core/src/umath/string_ufuncs.cpp:20:
../numpy/_core/src/umath/string_fastsearch.h:132:5: error: no type named 'ptrdiff_t' in namespace 'std'; did you mean simply 'ptrdiff_t'?
  132 |     std::ptrdiff_t
      |     ^~~~~~~~~~~~~~
      |     ptrdiff_t
/Applications/Xcode_16.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/include/__stddef_ptrdiff_t.h:18:26: note: 'ptrdiff_t' declared here
   18 | typedef __PTRDIFF_TYPE__ ptrdiff_t;
      |                          ^

The failure is not C++23 specific and arises when compiling using the C++17 language standard.

@charris
Copy link
Member Author

charris commented Apr 18, 2025

any plans backporting this fix to the maintenance/2.0.x branch

No, we are currently maintaining 2.2.x and 2.3.x will be out in June.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

08 - Backport Used to tag backport PRs 36 - Build Build related PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants