Commit bc40b76
committed
[clang-format] Correctly parse C99 digraphs: "<:", ":>", "<%", "%>", "%:", "%:%:".
Fixes llvm#31592.
This commits enables lexing of digraphs in C++11 and onwards.
Enabling them in C++03 is error-prone, as it would unconditionally treat sequences like "<:" as digraphs, even if they are followed by a single colon, e.g. "<::" would be treated as "[:" instead of "<" followed by "::". Lexing in C++11 doesn't have this problem as it looks ahead the following token.
The relevant excerpt from Lexer::LexTokenInternal:
```
// C++0x [lex.pptoken]p3:
// Otherwise, if the next three characters are <:: and the subsequent
// character is neither : nor >, the < is treated as a preprocessor
// token by itself and not as the first character of the alternative
// token <:.
```
Also, note that both clang and gcc turn on digraphs by default (-fdigraphs), so clang-format should match this behaviour.
Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan
Differential Revision: https://reviews.llvm.org/D1187061 parent 8a12cae commit bc40b76
2 files changed
+14
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3242 | 3242 | | |
3243 | 3243 | | |
3244 | 3244 | | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
3245 | 3249 | | |
3246 | 3250 | | |
3247 | 3251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24219 | 24219 | | |
24220 | 24220 | | |
24221 | 24221 | | |
| 24222 | + | |
| 24223 | + | |
| 24224 | + | |
| 24225 | + | |
| 24226 | + | |
| 24227 | + | |
| 24228 | + | |
| 24229 | + | |
| 24230 | + | |
| 24231 | + | |
24222 | 24232 | | |
24223 | 24233 | | |
24224 | 24234 | | |
0 commit comments