小编xdo*_*dot的帖子

类定义静态constexpr结构的未定义引用,g ++ vs clang

这是我的代码,a.cp​​p

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)

c++ one-definition-rule c++11

5
推荐指数
1
解决办法
200
查看次数

CMAKE COMPILER_CXX_ID 行为

$<COMPILER_CXX_ID:Clang>
Run Code Online (Sandbox Code Playgroud)

将返回1ClangAppleClang

根据医生的说法,我会说是的,但我不确定......

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

c++ cmake

3
推荐指数
1
解决办法
2616
查看次数

标签 统计

c++ ×2

c++11 ×1

cmake ×1

one-definition-rule ×1