【发布时间】:2015-04-09 14:10:00
【问题描述】:
考虑以下代码:
int a = 1;
const int& b = a;
std::cout << std::is_same<const decltype(b)&, const int&>();
它在 clang 3.5 上编译,而 GCC 4.9 给出以下错误:
error: 'const' qualifiers cannot be applied to 'const int&'
根据标准,哪一个是正确的?我的猜测是 GCC 是符合标准的,就像你做不到 int& const b = a;。
【问题讨论】:
-
哪一行会出错?
const int& b = a;还是下一个? -
FWIW,对于声明中的 decltype-specifier,引用上的 cv 限定符将被忽略(参见 [dcl.ref])。
-
const decltype(b)&与decltype(b)& const不同,所以我认为您与int& const的类比并不是特别合理。 -
@Aracthor:为什么会是
const int& b = a行? -
@Lightning Racis in Obrit:因为错误只是说“const int&”的“const”有问题,并且“const int& b = a”上有一个“const in&” " 行。
标签: c++ templates metaprogramming language-lawyer decltype