This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Don't put `noexcept` on empty line following constructor
ClosedPublic

Authored by rymiel on Aug 18 2022, 4:27 PM.

Details

Summary

With the AlwaysBreakTemplateDeclarations option, having a constructor
template for a type consisting of all-uppercase letters with a
noexcept specifier would put said noexcept specifier on its own blank
line.

This is because the all-uppercase type is understood as a macro-like
attribute (such as DEPRECATED()), and noexcept is seen as the
declaration. However, noexcept is a keyword and cannot be an
identifier on its own.

Fixes https://github.com/llvm/llvm-project/issues/56216

Diff Detail

Event Timeline

rymiel created this revision.Aug 18 2022, 4:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2022, 4:27 PM
rymiel requested review of this revision.Aug 18 2022, 4:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2022, 4:27 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rymiel added a project: Restricted Project.Aug 18 2022, 4:28 PM

Note for reviewing:
The criteria for reaching this misformat are extremely specific, requiring a single-character type or a type of a type consisting of all-uppercase letter, which are poor style on their own.
I am also unsure how often this all-uppercase macro-like attribute syntax is relied upon

I chose to simply add the keyword noexcept to the negative check for symbols, since, as far as I am aware, noexcept is the only legal specifier which can follow a constructor
However, I am unsure what the usual course of action is for version/language specific things, since I only use clang-format for modern C++, but it appears to be capable of a whole lot more than that.
I ask this because directly after my added line, there's mention of Objective-C, and technically noexcept itself wasn't always in C++. Should there be extra checks for these.

There could also possibly be a TokenAnnotatorTest checking for TT_FunctionAnnotationRParen, but there wasn't an existing one similar to it, so I was unsure if I should add one

There could also possibly be a TokenAnnotatorTest checking for TT_FunctionAnnotationRParen, but there wasn't an existing one similar to it, so I was unsure if I should add one

Always. :) In my opinion there are way too few annotator tests and one relies only on the formatting.

clang/unittests/Format/FormatTest.cpp
9619

Could you add a class with more than one character all upper case?

rymiel updated this revision to Diff 454191.Aug 20 2022, 3:37 AM

Extra tests, including token annotator tests

rymiel marked an inline comment as done.Aug 20 2022, 3:37 AM

This looks pretty good to me, but wait for @HazardyKnusperkeks

This revision is now accepted and ready to land.Aug 21 2022, 12:57 PM
owenpan accepted this revision.Aug 21 2022, 11:02 PM
curdeius accepted this revision.Sep 5 2022, 12:36 AM

@rymiel, please provide your name and email address for the commit message, so that we can land it for you.

Emilia Dreamer <emilia@rymiel.space>

Thank you!!

This revision was landed with ongoing or failed builds.Sep 5 2022, 3:36 AM
This revision was automatically updated to reflect the committed changes.