这是我的代码,a.cpp
struct int2
{
int x, y;
};
struct Foo{
static constexpr int bar1 = 1;
static constexpr int2 bar2 = {1, 2};
};
int foo1(){
return Foo::bar1; // this is ok for both clang++ and g++
}
int2 foo2(){
return Foo::bar2; // undefined reference to `Foo::bar2' in clang++
}
int main(){ std::cout << foo2().x << std::endl; return 0; }
Run Code Online (Sandbox Code Playgroud)
用clang编译, clang++ -std=c++11 a.cpp
/tmp/a-0dba90.o: In function `foo2()':
a.cpp:(.text+0x18): undefined reference to `Foo::bar2'
clang-7: error: linker command failed with exit …Run Code Online (Sandbox Code Playgroud) 做
$<COMPILER_CXX_ID:Clang>
Run Code Online (Sandbox Code Playgroud)
将返回1和ClangAppleClang
根据医生的说法,我会说是的,但我不确定......
1如果 CXX 编译器的 CMake-id 与comp匹配,否则0
源代码:https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
源代码:https ://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html