Page MenuHomePhabricator

clang-format: Fix left pointer alignment after delctype/typeof

Authored by euhlmann on Jul 25 2017, 10:35 AM.



Change 272124* introduced a regression in spaceRequiredBetween for left aligned pointers to decltype and typeof expressions. This fix adds logic to fix this. The test added is based on a related test in determineStarAmpUsage. Also add test cases for the regression.

LLVM bug tracker:

Diff Detail


Event Timeline

euhlmann created this revision.Jul 25 2017, 10:35 AM
alexfh edited reviewers, added: krasimir; removed: alexfh.Jul 26 2017, 2:33 AM
krasimir added inline comments.Aug 3 2017, 7:02 AM
2206 ↗(On Diff #108112)

Please use FormatToken::getPreviousNonComment here and add a test like typedef typeof/*comment*/(int(int, int))* MyFuncPtr;

euhlmann updated this revision to Diff 109613.Aug 3 2017, 12:16 PM

This uses FormatToken::getPreviousNonComment and adds a test. This also fixes a bug in token annotation that was breaking the test (by also using getPreviousNonComment instead of Previous)

euhlmann marked an inline comment as done.Aug 3 2017, 12:17 PM
krasimir added inline comments.Aug 4 2017, 1:37 AM
1402 ↗(On Diff #109613)

It would be cool if you extract the calls to getPreviousNonComment to a variable, saving the double iteration.

euhlmann updated this revision to Diff 109785.Aug 4 2017, 11:32 AM

Pulled out getPreviousNonComment() into local variable to avoid calling twice.

euhlmann marked an inline comment as done.Aug 4 2017, 11:32 AM
euhlmann updated this revision to Diff 109805.Aug 4 2017, 12:59 PM

Fix bad formatting

krasimir accepted this revision.Aug 5 2017, 8:14 AM

Looks good! Please reformat the newly added code blocks with clang-format before submitting.

1402 ↗(On Diff #109805)

Please reformat this block with clang-format: PrevToken gets indented by two more columns to the right.

2212 ↗(On Diff #109805)

Pleasereformat this block with clang-format: when I run it, it produces:

if ( {
  if ( && Line.MightBeFunctionDecl) {
    if (!Left.MatchingParen)
      return true;
    FormatToken *TokenBeforeMatchingParen =
    if (!TokenBeforeMatchingParen ||
        !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
      return true;
  return (Left.Tok.isLiteral() ||
          ( && Left.Previous &&
           Left.Previous->is(tok::r_paren)) ||
          (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
           (Style.PointerAlignment != FormatStyle::PAS_Left ||
            (Line.IsMultiVariableDeclStmt &&
             (Left.NestingLevel == 0 ||
              (Left.NestingLevel == 1 && Line.First->is(tok::kw_for)))))));
This revision is now accepted and ready to land.Aug 5 2017, 8:14 AM
euhlmann updated this revision to Diff 110032.Aug 7 2017, 11:10 AM

Ran clang-format over changes and corrected formatting

euhlmann marked 2 inline comments as done.Aug 7 2017, 11:16 AM

I resolved the formatting issues. I apologize for not paying closer attention to formatting earlier.

I don't have commit access, so if this change looks good now, could someone with access please commit?

This revision was automatically updated to reflect the committed changes.