This is an archive of the discontinued LLVM Phabricator instance.

[Format] Make getFormattingLangOpts clear LS_Auto uses LS_Cpp11 lexing rule
ClosedPublic

Authored by MaskRay on Jul 24 2019, 2:01 AM.

Diff Detail

Event Timeline

MaskRay created this revision.Jul 24 2019, 2:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2019, 2:01 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

getFormattingLangOpts is called with unadjusted FormatStyle (deriveLocalStyle doesn't modify Style). For example, GoogleStyle uses FormatStyle::LS_Auto. We're relying on FormatStyle::LS_Auto being larger than FormatStyle::LS_Cpp11, which is brittle.

Below is a case getFormattingLangOpts is called with LS_Auto:

TEST_F(CleanUpReplacementsTest, InsertMultipleIncludesGoogleStyle) {
...
  Style = format::getGoogleStyle(format::FormatStyle::LanguageKind::LK_Cpp);
  EXPECT_EQ(Expected, apply(Code, Replaces));
sammccall accepted this revision.Jul 24 2019, 2:31 AM

Thanks! (Sorry for the comment arriving late, didn't expect you to be awake!)

This revision is now accepted and ready to land.Jul 24 2019, 2:31 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2019, 2:50 AM