Foo::FOO1
是否使用ODR?
#include <iostream>
#include <map>
#include <string>
class Foo
{
public:
static constexpr auto FOO1 = "foo1";
void bar();
};
void Foo::bar()
{
const std::map<std::string, int> m = {
{FOO1, 1},
};
for (auto i : m)
{
std::cout << i.first << " " << i.second << std::endl;
}
}
int main()
{
Foo f;
f.bar();
return 0;
}
-O1
-O0
,我得到下面的错误(参见
coliru example
:
undefined reference to `Foo::FOO1'
这表明它是ODR使用的。是哪个?
a real (and more complex) case
:
-
代码编译并与-O2链接良好
-
代码得到了上面的结果
undefined reference
错误LinkTimeOptimization(
-O2 -flto
-O
)和链接时间优化(
-flto