具有带模板参数的函数的模板 class 上的 Cppcheck 语法错误
Cppcheck syntax error on Template class having a function with template paramter
任何人都知道我如何修复这个 Cppcheck 语法错误(没有比 "syntax error" 更多的信息)或者如果它是误报(可能是由于使用的选项),我查看了模板教程和文档并没有没找到类似的用法,代码是:
template<typename T>
template<class Archive> // Here is the Cppcheck syntax error
void MyItemContainer<T>::serialize(Archive & ar, const unsigned int version)
{
....
}
我正在使用:
- g++ (SUSE Linux) 8.2.1 20180831 [gcc-8-branch 修订版 264010]
- Cppcheck 1.82(这是 openSUSE Leap 15 上的最后一个可用版本),我已经成功构建了 1.89 版本,但我不能 运行 它,参数与我在 1.82 版本中所做的相同 "cppcheck: Failed to load library configuration file 'std.cfg'. File not found"错误
- cppcheck 命令为:cppcheck MyItemContainer.h --force --platform=unix64 --enable=warning --xml-version=2 --verbose --error-exitcode=0 - -std=c++11 --language=c++
谢谢
这似乎是 problem/false 对 CppCheck 的肯定。该代码使用正确的语法来定义模板化(在 T
上)class 的模板化(在 Archive
上)成员函数。在模板签名中使用 class
或 typename
在这里没有语义上的区别(但也许 CppCheck 绊倒了那个?可以尝试的东西......)。
可能是前面的某些代码无效并导致此位置出现语法错误,但这似乎不太可能。
我在 the manual. But given that CppCheck is still actively developed, you could consider building a small code sample reproducing this problem and submitting it to their bug tracker at https://trac.cppcheck.net/ 中找不到任何有用的词 "template"。
任何人都知道我如何修复这个 Cppcheck 语法错误(没有比 "syntax error" 更多的信息)或者如果它是误报(可能是由于使用的选项),我查看了模板教程和文档并没有没找到类似的用法,代码是:
template<typename T>
template<class Archive> // Here is the Cppcheck syntax error
void MyItemContainer<T>::serialize(Archive & ar, const unsigned int version)
{
....
}
我正在使用:
- g++ (SUSE Linux) 8.2.1 20180831 [gcc-8-branch 修订版 264010]
- Cppcheck 1.82(这是 openSUSE Leap 15 上的最后一个可用版本),我已经成功构建了 1.89 版本,但我不能 运行 它,参数与我在 1.82 版本中所做的相同 "cppcheck: Failed to load library configuration file 'std.cfg'. File not found"错误
- cppcheck 命令为:cppcheck MyItemContainer.h --force --platform=unix64 --enable=warning --xml-version=2 --verbose --error-exitcode=0 - -std=c++11 --language=c++
谢谢
这似乎是 problem/false 对 CppCheck 的肯定。该代码使用正确的语法来定义模板化(在 T
上)class 的模板化(在 Archive
上)成员函数。在模板签名中使用 class
或 typename
在这里没有语义上的区别(但也许 CppCheck 绊倒了那个?可以尝试的东西......)。
可能是前面的某些代码无效并导致此位置出现语法错误,但这似乎不太可能。
我在 the manual. But given that CppCheck is still actively developed, you could consider building a small code sample reproducing this problem and submitting it to their bug tracker at https://trac.cppcheck.net/ 中找不到任何有用的词 "template"。