Fix adding unescaped slash token when splitting gcc case range. (#1987)

* Fix adding unescaped slash token when splitting gcc case range.

Construction like case '!'...'~' converted to a list of separate case
tokens. When slas '\' symbol appears as a part of this list it was added
"as is", but it should be escaped like '\\' to be valid c++ code.

* Add test for switch-case range with slash
This commit is contained in:
Denis 2019-07-15 10:29:31 +03:00 committed by Daniel Marjamäki
parent 8e4f0c2d89
commit 68e6a440ff
2 changed files with 7 additions and 1 deletions

View File

@ -2821,7 +2821,11 @@ void Tokenizer::simplifyCaseRange()
tok->next()->str("case");
for (char i = end - 1; i > start; i--) {
tok->insertToken(":");
if (i == '\\') {
tok->insertToken(std::string("\'\\") + i + '\'');
} else {
tok->insertToken(std::string(1, '\'') + i + '\'');
}
tok->insertToken("case");
}
}

View File

@ -7114,6 +7114,8 @@ private:
ASSERT_EQUALS("void f ( ) { switch ( x ) { case 'a' : case 'b' : case 'c' : ; } }", tokenizeAndStringify("void f() { switch(x) { case 'a' ... 'c': } }"));
ASSERT_EQUALS("void f ( ) { switch ( x ) { case 'c' . . . 'a' : ; } }", tokenizeAndStringify("void f() { switch(x) { case 'c' ... 'a': } }"));
ASSERT_EQUALS("void f ( ) { switch ( x ) { case '[' : case '\\\\' : case ']' : ; } }", tokenizeAndStringify("void f() { switch(x) { case '[' ... ']': } }"));
}
void prepareTernaryOpForAST() {