如果我用clang++编译这个最小化的例子:
#include <system_error>
#include <vector>
namespace MyNamespace {
namespace ffi {
#include <sys/types.h>
}
void example() {
const ffi::errno_t savedErrno = errno;
ffi::uint uskip = static_cast<ffi::uint>(5);
throw std::system_error(savedErrno, std::generic_category());
}
}
我收到以下错误:
clang++ -pedantic-errors -Weverything -Wno-c++98-compat -Wno-pre-c++20-compat-pedantic -Wno-poison-system-directories --std=c++20 -O3 -Iinclude -I/usr/local/include -MMD -MP -c -fPIC src/test.cpp -o obj/test.o
src/test.cpp:10:11: error: no type named 'errno_t' in namespace 'MyNamespace::ffi'; did you mean simply 'errno_t'?
const ffi::errno_t savedErrno = errno;
^~~~~~~~~~~~
errno_t
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types/_errno_t.h:30:32: note: 'errno_t' declared here
typedef int errno_t;
^
src/test.cpp:11:5: error: no type named 'uint' in namespace 'MyNamespace::ffi'; did you mean simply 'uint'?
ffi::uint uskip = static_cast<ffi::uint>(5);
^~~~~~~~~
uint
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/types.h:93:33: note: 'uint' declared here
typedef unsigned int uint; /* Sys V compatibility */
^
src/test.cpp:11:35: error: no type named 'uint' in namespace 'MyNamespace::ffi'; did you mean simply 'uint'?
ffi::uint uskip = static_cast<ffi::uint>(5);
^~~~~~~~~
uint
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/types.h:93:33: note: 'uint' declared here
typedef unsigned int uint; /* Sys V compatibility */
^
但是,如果我不包括
<vector>
标题前
ffi
命名空间,然后编译工作。
本质上,为什么
<矢量>
标头阻止将类型包含到
ffi
命名空间?