<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - When _XOPEN_SOURCE is set,<cstdlib> and <ctime> started to fail on macOS, missing ::aligned_alloc and ::timespec_get"
href="https://bugs.llvm.org/show_bug.cgi?id=47208">47208</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>When _XOPEN_SOURCE is set,<cstdlib> and <ctime> started to fail on macOS, missing ::aligned_alloc and ::timespec_get
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>stephan.bergmann.secondary@googlemail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>ldionne@apple.com, llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>On macOS, with recent LLVM 12 trunk commit
<<a href="https://github.com/llvm/llvm-project/commit/67dfba96296b37f7bac9b4a68572288bc44b63b2">https://github.com/llvm/llvm-project/commit/67dfba96296b37f7bac9b4a68572288bc44b63b2</a>>
" [libc++] Provide std::aligned_alloc and std::timespec_get on Apple
platforms":
<span class="quote">> $ cat test.cc
> #include <cstdlib>
> #include <ctime></span >
<span class="quote">> $ .../llvm/inst/bin/clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++17 -fsyntax-only test.cc</span >
<span class="quote">> $ .../llvm/inst/bin/clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++17 -fsyntax-only test.cc -D_XOPEN_SOURCE=600
> In file included from test.cc:1:
> .../llvm/inst/bin/../include/c++/v1/cstdlib:158:9: error: no member named 'aligned_alloc' in the global namespace
> using ::aligned_alloc;
> ~~^
> In file included from test.cc:2:
> .../llvm/inst/bin/../include/c++/v1/ctime:76:9: error: no member named 'timespec_get' in the global namespace; did you mean 'timespec'?
> using ::timespec_get;
> ~~^
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/sys/_types/_timespec.h:33:1: note: 'timespec' declared here
> _STRUCT_TIMESPEC
> ^
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/sys/_types/_timespec.h:29:40: note: expanded from macro '_STRUCT_TIMESPEC'
> #define _STRUCT_TIMESPEC struct timespec
> ^
> 2 errors generated.</span >
...and similarly for other values of _XOPEN_SOURCE, like 700. I noticed that
when building ICU 67.1 as part of building recent master LibreOffice, where
some place in the ICU sources sets _XOPEN_SOURCE to 600.
* One approach to fix this would be to make the condition in libcxx match the
condition in Apple's SDK headers, with something like
<span class="quote">> diff --git a/libcxx/include/__config b/libcxx/include/__config
> index d7b6a2acaef..fb5ca54493b 100644
> --- a/libcxx/include/__config
> +++ b/libcxx/include/__config
> @@ -327,6 +327,10 @@
> # define _LIBCPP_USING_DEV_RANDOM
> #endif
>
> +#if defined(__APPLE__)
> +# include <sys/cdefs.h>
> +#endif
> +
> #if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
> # include <endian.h>
> # if __BYTE_ORDER == __LITTLE_ENDIAN
> @@ -383,7 +387,8 @@
> # elif defined(__APPLE__)
> // timespec_get and aligned_alloc were introduced in macOS 10.15 and
> // aligned releases
> -# if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500 || \
> +# if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && \
> + (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500 || \
> __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000 || \
> __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000 || \
> __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000)</span >
* Another approach could be to change Apple's SDK headers, so that for C++
::aligned_alloc and ::timespec_get would get declared regardless of any
_XOPEN_SOURCE?
* And yet another approach could be to declare that _XOPEN_SOURCE must not be
defined when compiling C++ source (after all, at least technically it is an
identifier that is reserved to the implementation), and instead fix ICU.
Thoughts how to proceed?</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>