simplecpp
simplecpp copied to clipboard
Wrong tokenization for template variable.
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?
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 , "" ) ;
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?
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.