acm*_*acm 5 c++ macos xcode abi clang
通过我对可用性宏和-mmacosx-version-min标志如何工作的理解,在针对OS X 10.10时,以下代码应该无法编译:
#include <Availability.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
#if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
#error
#endif
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
#error __MAC_OSX_VERSION_MIN_REQUIRED too low
#endif
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101000
#error __MAC_OSX_VERSION_MIN_REQUIRED too high
#endif
int main() {
size_t len = 0;
SSLContextRef x{};
auto status = SSLCopyRequestedPeerNameLength(x, &len);
return status != 0;
}
Run Code Online (Sandbox Code Playgroud)
因为该功能SSLCopyRequestedPeerNameLength在10.11中标记为可用SecureTransport.h:
$ grep -C5 ^SSLCopyRequestedPeerNameLength /System/Library/Frameworks//Security.framework/Headers/SecureTransport.h
/*
* Server Only: obtain the hostname specified by the client in the ServerName extension (SNI)
*/
OSStatus
SSLCopyRequestedPeerNameLength (SSLContextRef ctx,
size_t *peerNameLen)
__OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);
Run Code Online (Sandbox Code Playgroud)
然而,当我在命令行上编译时,-mmacosx-version-min=10.10我根本没有得到任何警告,尽管-Wall -Werror -Wextra:
$ clang++ -Wall -Werror -Wextra ./foo.cpp --std=c++11 -framework Security -mmacosx-version-min=10.10 --stdlib=libc++ ; echo $?
0
Run Code Online (Sandbox Code Playgroud)
是否需要提供一些额外的定义或特定警告,以确保我不会接受比10.10更新的API的依赖?我真的希望这-mmacosx-version-min=10.10会阻止使用标记有更高版本号的API.
我在这里误解了什么?
在macOS 10.13.6上使用XCode 10.0(10A255).
| 归档时间: |
|
| 查看次数: |
302 次 |
| 最近记录: |