[clang] [clang-format] Don't re-annotate CaseLabelColon as ConditionalExpr (PR #114639)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 1 21:23:17 PDT 2024
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/114639
Fixes #114627.
>From 146969dc5c1b3fd02c783118664e9cdb74aabbdf Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Fri, 1 Nov 2024 21:18:03 -0700
Subject: [PATCH] [clang-format] Don't re-annotate CaseLabelColon as
ConditionalExpr
Fixes #114627.
---
clang/lib/Format/TokenAnnotator.cpp | 2 +-
clang/unittests/Format/FormatTest.cpp | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 13037b6d00604b..269cbef2720792 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1259,7 +1259,7 @@ class AnnotatingParser {
bool parseConditional() {
while (CurrentToken) {
- if (CurrentToken->is(tok::colon)) {
+ if (CurrentToken->is(tok::colon) && CurrentToken->is(TT_Unknown)) {
CurrentToken->setType(TT_ConditionalExpr);
next();
return true;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index cdb68b74ca79ff..250e51b5421664 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24393,6 +24393,8 @@ TEST_F(FormatTest, DisableRegions) {
TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
format("? ) =");
verifyNoCrash("#define a\\\n /**/}");
+ verifyNoCrash(" tst %o5 ! are we doing the gray case?\n"
+ "LY52: ! [internal]");
}
TEST_F(FormatTest, FormatsTableGenCode) {
More information about the cfe-commits
mailing list