[英]Template shadow error with clang
如以下代码片段中的注释所述,这是gcc 4.4的一种解决方法。 错误,我现在应该删除。 有关此背景,请参见带有gcc 4.4的模板模板参数和可变参数模板 。
在任何情况下,这都会给从Debian Wheezy传来clang 3.4.2-4的错误,并从不稳定版本中反向移植。 这在gcc 4.9上也能正常工作,并且在Debian Wheezy上也从不稳定(和4.7)反向移植。
// Workaround for gcc 4.4 bug. See https://stackoverflow.com/q/8514633/350713
template <typename S, typename T,
template <typename S, typename T, typename... Args> class C,
typename... Args>
struct maptype
{
typedef C<S, T, Args...> type;
};
int main(void){}
错误是
clang++ -o shadow.ocl -c -ftemplate-depth-100 -fno-strict-aliasing -fno-common -ansi -Wextra -Wall -Werror -Wno-unused-function -Wc++0x-compat -Wpointer-arith -Wcast-qual -Wcast-align -std=c++11 -mtune=native -msse3 -O3 shadow.cc
shadow.cc:3:23: error: declaration of 'S' shadows template parameter
template <typename S, typename T, typename... Args> class C,
^
shadow.cc:2:20: note: template parameter is declared here
template <typename S, typename T,
^
shadow.cc:3:35: error: declaration of 'T' shadows template parameter
template <typename S, typename T, typename... Args> class C,
^
shadow.cc:2:32: note: template parameter is declared here
template <typename S, typename T,
^
2 errors generated.
我至少在SO上看到几个表面上类似的问题,即Clang VS VC ++:“错误:'T'阴影模板参数的声明”和用于旧gcc的C ++模板导致clang ++中的“阴影模板参数”错误但是对于我来说是不同的问题还是相同的问题对我来说并不明显。
感谢澄清。 我不定期编写C ++,自从我看过模板模板参数以来已经有一段时间了。
模板模板参数C
的名称S
, T
, Args
template <typename S, typename T, typename... Args> class C
是多余的,并且与maptype
的S
, T
, Args
具有相同的名称。 名称相同的事实在clang上产生阴影错误。
所以你可以写
template <typename S,
typename T,
template <typename, typename, typename...> class C,
typename... Args>
struct maptype;
或使用其他名称(出于文档目的,因为不能使用)
template <typename S,
typename T,
template <typename S_Type, typename T_Type, typename... Args_Type> class C,
typename... Args>
struct maptype;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.