[PATCH] D118921: [Format] Don't derive pointers right based on space before method ref-qualifiers
Ben Hamilton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 3 09:35:07 PST 2022
benhamilton requested changes to this revision.
benhamilton added inline comments.
This revision now requires changes to proceed.
================
Comment at: clang/lib/Format/Format.cpp:1949
continue;
+ // Don't treat space in `void foo() &&` as evidence.
+ if (const auto *Prev = Tok->getPreviousNonComment()) {
----------------
Do we also need to worry about `T && foo();` style declarations?
================
Comment at: clang/lib/Format/Format.cpp:1951
+ if (const auto *Prev = Tok->getPreviousNonComment()) {
+ if (Prev->is(tok::r_paren) && Prev->MatchingParen)
+ if (const auto *Func = Prev->MatchingParen->getPreviousNonComment())
----------------
If this is parsing a general function declaration, I think it's not safe to assume that the token immediately before the ref-spec is the close-paren.
It looks like `Prev` can be a few other things, including at least:
* `tok::kw_const`
* `tok::kw_volatile`
* `tok::kw_throw`
* `tok::kw_noexcept`
and probably C++ attribute(s) as well:
> noptr-declarator ( parameter-list ) cv(optional) ref(optional) except(optional) attr(optional)
* https://en.cppreference.com/w/cpp/language/function
* https://en.cppreference.com/w/cpp/language/declarations
I *think* they can also be in any order, so the ref-spec could come at the very end after cv-qualifier, an expection specification, and C++ attributes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118921/new/
https://reviews.llvm.org/D118921
More information about the cfe-commits
mailing list