2

Anyone knows how I can fix this Cppcheck syntax error (no more information than "syntax error") or if it is a false positive (maybe due to options used), I looked at template tutorials and documentations and didn't find any similar usage, the code is:

template<typename T>
template<class Archive> // Here is the Cppcheck syntax error
void MyItemContainer<T>::serialize(Archive & ar, const unsigned int version)
{
    ....
}

I'm using :

  • g++ (SUSE Linux) 8.2.1 20180831 [gcc-8-branch revision 264010]
  • Cppcheck 1.82 (this is the last available version on openSUSE Leap 15), I have successfully build 1.89 version but I cannot run it, with same parameters as I do with 1.82 version I have "cppcheck: Failed to load library configuration file 'std.cfg'. File not found" error
  • Cppcheck command is: cppcheck MyItemContainer.h --force --platform=unix64 --enable=warning --xml-version=2 --verbose --error-exitcode=0 --std=c++11 --language=c++

Thanks

gluttony
  • 402
  • 6
  • 14

1 Answers1

3

This looks to be a problem/false positive with CppCheck. The code uses the correct syntax to define a templated (on Archive) member function of a templated (on T) class. The use of class or typename in the template signature makes no semantic difference here (but maybe CppCheck stumbles over that? Something to try...).

It could be that some preceding code is invalid and causes a syntax error in this location, but that seems pretty unlikely.

I can't find any useful mention of the word "template" in 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/.

Max Langhof
  • 23,383
  • 5
  • 39
  • 72
  • Thanks for your answer, I will add an exception in my ignore list (Cppcheck --suppressions-list option) for this one and try doing a small code that reproduces this to submit to them. NB: I would have upvote you but I have too few reputation :( – gluttony Dec 06 '19 at 06:55
  • 1
    I am a Cppcheck contributor, so I know a bit of what is going on there. Especially regarding `templates` there have been made many improvements and fixes in the last time. So I guess this is already fixed in a newer version. If your code compiles with g++ then it is very likely that Cppcheck has an issue with the code. I really can recommend switching to a newer version. If you do not have a Trac account you can also post in the forum: https://sourceforge.net/p/cppcheck/discussion/ – versat Dec 06 '19 at 07:29
  • Thanks @versat, I actually have posted a discussion as suggested by Max Langhof, here it is: https://sourceforge.net/p/cppcheck/discussion/development/thread/8bb5c73341/ – gluttony Dec 06 '19 at 07:56