Page MenuHomePhabricator

[clang-format] [PR45942] [[nodiscard]] causes && to be miss interpreted as BinaryOperators
ClosedPublic

Authored by MyDeveloperDay on May 15 2020, 6:43 AM.

Details

Summary

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

With Chromium style (although that is not important) its just it defines PointerAligmment: Left

The following arguments S&& are formatted differently depending on if the class has an attribute between it and the class identifier

class S {
  S(S&&) = default;
};

class [[nodiscard]] S {
  S(S &&) = default;
};

The prescense of [[nodiscard]] between the class/struct and the { causes the { to be incorrectly seen as a TT_FunctionLBrace which in turn transforms all the && to be TT_BinaryOperators rather than TT_PointerOrReference, as binary operators other spacing rules come into play causing a miss format

This revision resolves this by allowing the parseRecord to consider the [[nodisscard]]

Diff Detail

Event Timeline

MyDeveloperDay created this revision.May 15 2020, 6:43 AM

pre-merge tests showed I wasn't quite rebased however it overlaps with D79354: [clang-format] [PR34574] Handle [[nodiscard]] attribute in class declaration

However I feel I made a mistake with the previous fix because the l_square and r_square haven't always been assigned to be of type TT_AttributeSquare yet.

Update this patch so the test from both revision still work.

Abpostelnicu accepted this revision.May 19 2020, 8:14 AM
This revision is now accepted and ready to land.May 19 2020, 8:14 AM
This revision was automatically updated to reflect the committed changes.