0

I have a syntax error with cppcheck and using/typedef declarations. I have a struct that contains

struct inferior
{

    using visitor = int;

    template <typename T>
    bool operator()(const T &a, const T &b) const
    {
        return a < b;
    }
};

int main() { 
    return 0; 
}

when I run cppcheck file.cpp output is

[file.cpp:5]: (error) syntax error with no further output.

The error disappeared if I remove the using declaration.

I wonder if it's normal behaviour from cppcheck. the using declaration not being used directly. (It's a reduced example with a using redefining int).

Some context if needed: In my application, the using defines a specialisation of a visitor OnlyArithmetic like so: using visitor = OnlyArithmetic<inferior> that filters the non-arithmetic types using metaprogramming techniques, then I call std::visit on inferior::visitor(). I used this trick to not repeat the filtering part for all structures I need (inferior, superior, ...).

[EDIT] Using cppcheck 1.88

cppart
  • 1
  • 2
  • 2
    try adding `--std=c++11` to the command line, I don't know what cppcheck is using by default – local-ninja Aug 21 '19 at 11:22
  • 2
    A quick look at cppcheck's forum suggests that a bug has crept in recently; there are other reports about false syntax errors. If you have a recent version, I would try rolling back a bit. – molbdnilo Aug 21 '19 at 11:27
  • What version of cppcheck? – Lightness Races in Orbit Aug 21 '19 at 12:15
  • Thanks for you reply I tried with `--std=c++11` but same behaviour. I was using cppcheck 1.88 (latest homebrew formula). I built cppcheck from sources (1.89) but same problem but with a bit more output. I then downgraded to 1.76.1 (one of their [branches](https://github.com/danmar/cppcheck/)) and problem disappeared – cppart Aug 21 '19 at 12:22

2 Answers2

0

As molbdnilo suggested. Problem disappeared with cppcheck release 1.85.

cppart
  • 1
  • 2
0

This issue was introduced with Cppcheck 1.86 and was fixed in version 1.89.

Firewave
  • 336
  • 2
  • 11