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:
parent
8e4f0c2d89
commit
68e6a440ff
|
@ -2821,7 +2821,11 @@ void Tokenizer::simplifyCaseRange()
|
||||||
tok->next()->str("case");
|
tok->next()->str("case");
|
||||||
for (char i = end - 1; i > start; i--) {
|
for (char i = end - 1; i > start; i--) {
|
||||||
tok->insertToken(":");
|
tok->insertToken(":");
|
||||||
|
if (i == '\\') {
|
||||||
|
tok->insertToken(std::string("\'\\") + i + '\'');
|
||||||
|
} else {
|
||||||
tok->insertToken(std::string(1, '\'') + i + '\'');
|
tok->insertToken(std::string(1, '\'') + i + '\'');
|
||||||
|
}
|
||||||
tok->insertToken("case");
|
tok->insertToken("case");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 '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 '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() {
|
void prepareTernaryOpForAST() {
|
||||||
|
|
Loading…
Reference in New Issue