[PATCH] D118706: [clang-format] Correctly parse C99 digraphs: "<:", ":>", "<%", "%>", "%:", "%:%:".
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 2 01:25:42 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbc40b76b5b95: [clang-format] Correctly parse C99 digraphs: "<:", ":>", "<%", "%>", "%:", "%:%… (authored by curdeius).
Changed prior to commit:
https://reviews.llvm.org/D118706?vs=404945&id=405172#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118706/new/
https://reviews.llvm.org/D118706
Files:
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24219,6 +24219,16 @@
Style);
}
+TEST_F(FormatTest, UnderstandsDigraphs) {
+ verifyFormat("int arr<:5:> = {};");
+ verifyFormat("int arr[5] = <%%>;");
+ verifyFormat("int arr<:::qualified_variable:> = {};");
+ verifyFormat("int arr[::qualified_variable] = <%%>;");
+ verifyFormat("%:include <header>");
+ verifyFormat("%:define A x##y");
+ verifyFormat("#define A x%:%:y");
+}
+
} // namespace
} // namespace format
} // namespace clang
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3242,6 +3242,10 @@
LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
+ // Turning on digraphs in standards before C++0x is error-prone, because e.g.
+ // the sequence "<::" will be unconditionally treated as "[:".
+ // Cf. Lexer::LexTokenInternal.
+ LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
LangOpts.LineComment = 1;
bool AlternativeOperators = Style.isCpp();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118706.405172.patch
Type: text/x-patch
Size: 1354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220202/1f456e34/attachment.bin>
More information about the cfe-commits
mailing list