simplecpp icon indicating copy to clipboard operation
simplecpp copied to clipboard

Wrong tokenization for template variable.

Open IOBYTE opened this issue 5 years ago • 3 comments

This code:

template <typename TElem>
constexpr bool IsMatrix<Matrix<TElem>> = true;

gets tokenized to:

$ ./cppcheck -E test.cpp 
template < typename TElem >
constexpr bool IsMatrix < Matrix < TElem >>= true ;

The three tokens >> = get combined into one token >>=.

Should this be fixed here or in cppcheck? Should simplecpp be language aware?

IOBYTE avatar Sep 22 '19 17:09 IOBYTE

I'm seeing a similar problem with:

static_assert(var<S1<11, 100>> == var<S1<199, 23>>/2
    && var<S1<50, 120>> == var<S1<150, var<S1<10, 10>>>>
    && var<S1<53, 23>> != 222, "");
$ ./cppcheck -E test.cpp 
static_assert ( var < S1 < 11 , 100 >>= = var < S1 < 199 , 23 >> / 2
&& var < S1 < 50 , 120 >>= = var < S1 < 150 , var < S1 < 10 , 10 >> >>
&& var < S1 < 53 , 23 >> != 222 , "" ) ;

IOBYTE avatar Sep 22 '19 18:09 IOBYTE

Should this be fixed here or in cppcheck? Should simplecpp be language aware?

That is a good question. Ideally I would like that simplecpp output was correct so it can be used to properly preprocess C++ code also. however if it would require much more code in simplecpp I think we should consider that. Do you have a feeling about how tricky this would be in simplecpp/cppcheck?

danmar avatar Sep 22 '19 19:09 danmar

I have a simple fix for the second problem that splits >>== into >> == rather than >>= =. Cppcheck also needs a simple fix to not give a syntax error on >> ==.

Splitting >> into > > here is harder. Cppcheck does it and we could do the same thing here but cppcheck has to guess and I doubt it guesses correctly all the time.

IOBYTE avatar Sep 23 '19 14:09 IOBYTE