[clang-format] PR42434 Remove preprocessor and pragma lines from ObjectiveC guess

clang-format see the `disable:` in   __pragma(warning(disable:)) as ObjectiveC method call

Remove any line starting with `#` or __pragma line from being part of the ObjectiveC guess

https://bugs.llvm.org/show_bug.cgi?id=42434

Reviewed By: curdeius, krasimir

Differential Revision: https://reviews.llvm.org/D92922
This commit is contained in:
mydeveloperday 2020-12-10 11:13:22 +00:00
parent 254677e9ed
commit 7b2d62fd7f
2 changed files with 13 additions and 0 deletions

View File

@ -2032,6 +2032,10 @@ private:
};
for (auto Line : AnnotatedLines) {
if (Line->First && (Line->First->TokenText.startswith("#") ||
Line->First->TokenText == "__pragma" ||
Line->First->TokenText == "_Pragma"))
continue;
for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&

View File

@ -16713,6 +16713,15 @@ TEST_F(FormatTest, GuessLanguageWithCaret) {
guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
}
TEST_F(FormatTest, GuessLanguageWithPragmas) {
EXPECT_EQ(FormatStyle::LK_Cpp,
guessLanguage("foo.h", "__pragma(warning(disable:))"));
EXPECT_EQ(FormatStyle::LK_Cpp,
guessLanguage("foo.h", "#pragma(warning(disable:))"));
EXPECT_EQ(FormatStyle::LK_Cpp,
guessLanguage("foo.h", "_Pragma(warning(disable:))"));
}
TEST_F(FormatTest, FormatsInlineAsmSymbolicNames) {
// ASM symbolic names are identifiers that must be surrounded by [] without
// space in between: