Skip to content

Commit

Permalink
Add error checks for a few issues identified by re2c (boostorg#82)
Browse files Browse the repository at this point in the history
- "undefined" input sequences that should in theory never happen
- control characters in C++11 character and string literals
  • Loading branch information
jefftrull authored Mar 19, 2020
1 parent b68940a commit e95a014
Show file tree
Hide file tree
Showing 4 changed files with 1,723 additions and 1,626 deletions.
21 changes: 21 additions & 0 deletions include/boost/wave/cpplexer/re2clex/cpp.re
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ pp_number:
/*!re2c
"."? Digit (Digit | NonDigit | ExponentStart | ".")*
{ BOOST_WAVE_RET(T_PP_NUMBER); }
// because we reached this point, then reset the cursor,
// the pattern above should always match
* { BOOST_ASSERT(false); }
*/
}
else {
Expand All @@ -456,6 +460,9 @@ pp_number:
{ BOOST_WAVE_RET(T_FLOATLIT); }
Integer { goto integer_suffix; }
// one of the above patterns should always match
* { BOOST_ASSERT(false); }
*/
}
}
Expand All @@ -481,12 +488,21 @@ integer_suffix:
{ BOOST_WAVE_RET(T_INTLIT); }
*/
}
// re2c will complain about -Wmatch-empty-string above
// it's OK because we've already matched an integer
// and will return T_INTLIT
}
/* this subscanner is invoked for C++0x extended character literals */
extcharlit:
{
/*!re2c
* {
(*s->error_proc)(s, lexing_exception::generic_lexing_error,
"Invalid character in raw string delimiter ('%c')", yych);
}

((EscapeSequence | UniversalChar | any\[\n\r\\']) ['])
{ BOOST_WAVE_RET(T_CHARLIT); }

Expand All @@ -499,6 +515,11 @@ extcharlit:
extstringlit:
{
/*!re2c
* {
(*s->error_proc)(s, lexing_exception::generic_lexing_error,
"Invalid character in raw string delimiter ('%c')", yych);
}
((EscapeSequence | UniversalChar | any\[\n\r\\"])* ["])
{ BOOST_WAVE_RET(T_STRINGLIT); }
Expand Down
Loading

0 comments on commit e95a014

Please sign in to comment.