编辑器中出现“错误:类型名称不允许”消息但编译时不出现

问题描述:

我正在使用MSVS2013,并且我自己推出了​​宏,该宏只接受TCHAR数组。作为参考,这里是代码:编辑器中出现“错误:类型名称不允许”消息但编译时不出现

// Helper struct for _tcountof() macro 
template <typename T, size_t N> 
struct _tcountof_struct_helper; 

// Helper partially specialized struct for _tcountof() macro 
template <size_t N> 
struct _tcountof_struct_helper<TCHAR, N> 
{ 
    static size_t const value = N; 
}; 

// Helper function for _tcountof() macro. It's never called so no body is required. 
template <typename T, size_t N> 
auto _tcountof_function_helper(T(&)[N])->_tcountof_struct_helper<T, N>; 

// _tcountof(x) gets the size of a TCHAR array. 
// Will fail to compile if x is not of type TCHAR array. 
#define _tcountof(x) (decltype(_tcountof_function_helper(x))::value) 

现在这工作得很好。它编译并且不允许除1D数组之外的任何类型(不同于extent,MSVS实现的允许指针和数组,这当然应该是无效的)。它只允许TCHAR数组,并且我也可以稍后修改它接受一个数字来说明要查询n​​D数组的哪个维度),并像编译时间常数那样工作。然而,编辑正在烦恼,红色的波浪线出现在我的_tcountof()宏的调用下,当我将它悬停在它上面时,它说:Error: type name is not allowed

这只是编辑器故障的一个实例,跟不上编译器的发展?有没有办法阻止这个红色波浪出现这个错误或特定的宏?

(声明:我在DevDiv(Visual Studio中)队工作在微软)

Is this just an instance of a failure of the editor not keeping up with the compiler's development?

差不多:)好消息是它的固定在下一版本:Visual Studio的2015年,坏消息是您需要升级,而丑陋的消息是没有修复,甚至没有解决方法,可用于Visual Studio 2013.但这是一个完全无害的警告,可以安全地忽略。我在自己的产品代码中看到了很多,所以你并不孤单!

该修补程序已经在Visual Studio 2015的预览版本中,而且2015支持与VS的早期版本进行项目文件的往返操作,因此请试试! http://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx

Is there a way to stop this red squiggly from appearing for this error or for a particular macro?

的问题是由decltype表述不正确的处理造成的,所以解决方法是找到一种方法来避免使用decltype现在。

+0

是的,我发布这个错误,并得到相同的回应。我们仅在6个月前从2010年升级。升级编译器是一件棘手的事情,由于风险水平如此之高,所以我不确定我是否会很快看到此修复。 – Adrian