[PATCH] D115168: [clang-format] [PR49298] Sort includes pass will sort inside raw strings
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 8 01:34:49 PST 2021
curdeius requested changes to this revision.
curdeius added inline comments.
This revision now requires changes to proceed.
================
Comment at: clang/lib/Format/Format.cpp:2589
+ llvm::Regex RawStringRegex("R\"([A-Za-z]*)\\(");
+ SmallVector<StringRef, 2> RawStringMatches;
----------------
A raw string literal is:
```
prefix(optional) R"d-char-sequence(optional) (r-char-sequence(optional))d-char-sequence(optional)"
d-char-sequence - A sequence of one or more d-chars, at most 16 characters long
d-char - A character from the basic source character set (until C++23)basic character set (since C++23), except parentheses, backslash and spaces
```
So, you missed the digits and the characters: `_{}[]#<>%:;.?*+-/^&|~!=,'`.
Please add a test case.
Mind the need to escape the square brackets `[]` and the minus sign `-` in the regexp (the latter can be put at the beginning or at the end too).
Cf. https://en.cppreference.com/w/cpp/language/string_literal, https://godbolt.org/z/rb61WzMcs
================
Comment at: clang/lib/Format/Format.cpp:2605-2607
+ if (!CharSequence.empty()) {
+ RawStringTermination = ")" + CharSequence + "\"";
+ }
----------------
Since `CharSequence` is empty, you might want to remove the if altogether and create `RawStringTermination` unconditionally.
Oh, actually, as it's used in the for loop, you *have to* reassign `RawStringTermination`, otherwise the code like:
```
R"x(...
...)x"; // RawStringTermination is "x"
R"(...
...); // RawStringTermination would still be "x"
#include <b.h> // not sorted but it should
#include <a.h> // not sorted but it should
```
will misbehave.
Please create a test case for this.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115168/new/
https://reviews.llvm.org/D115168
More information about the cfe-commits
mailing list