Bellow是一个片段,可以使用g++
进行编译,但是clang
会生成警告。我真的很感谢一些家庭了解原因。
class A {
template <char N>
struct Foo {
static constexpr char Bar() { return 0; }
};
using PseudorangeConstants = Foo<1>;
char var = PseudorangeConstants::Bar();
};
这是我的clang版本以及如何构建(在Linux上):
$clang++ -v
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/8.1.1
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/8.1.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
$ clang++ -c temp.cpp
这是警告:
temp.cpp:4:27: warning: inline function 'A::Foo<'\x01'>::Bar' is not defined [-Wundefined-inline]
static constexpr char Bar() { return 0; }
^
temp.cpp:9:36: note: used here
char var = PseudorangeConstants::Bar();
^
1 warning generated.
警告非常令人困惑。删除constexpr
可修复警告(提示链接问题)。也许专业?