Clang format does not remove spaces inside dependent nested name specifiers
Input:
template <typename T>
auto mem = &T :: member;
Expected output:
template <typename T>
auto mem = &T::member; // <-- No spaces here
Actual output:
template <typename T>
auto mem = &T ::member; // <-- Space before colons here
Live repro: https://godbolt.org/z/6oWK58Pzf
Interestingly, this does work as expected for non-dependent names: https://godbolt.org/z/G17d1ocqs
@llvm/issue-subscribers-clang-format
Author: Andy Soffer (asoffer)
Expected output:
template <typename T>
auto mem = &T::member; // <-- No spaces here
Actual output:
template <typename T>
auto mem = &T ::member; // <-- Space before colons here
Live repro: https://godbolt.org/z/6oWK58Pzf
Interestingly, this does work as expected for non-dependent names: https://godbolt.org/z/G17d1ocqs
I’d like to work on this issue. I’ll investigate and send a patch with tests if no one is already working on it.
Interestingly, this does work as expected for non-dependent names: https://godbolt.org/z/G17d1ocqs
You had no space in your input there, it is handled equally. We have (nearly) no knowledge what an identifier refers to.
I’d like to work on this issue. I’ll investigate and send a patch with tests if no one is already working on it.
Just assign yourself here in github. (I've done it for you this time.)
I’d like to work on this issue. I’ll investigate and send a patch with tests if no one is already working on it.
Just assign yourself here in github. (I've done it for you this time.)
It looks like I don't have permission to assign myself on GitHub. Thanks for assigning it to me. :-)
Hi @HazardyKnusperkeks, I sent a patch for this in #189024.
While investigating, I noticed we already have a similar macro-detection heuristic in clang/lib/Format/QualifierAlignmentFixer.cpp (isPossibleMacro), so I followed the same general idea here and narrowed the existing spacing heuristic for this case instead of removing it outright.
The change keeps the ALWAYS_INLINE ::std::string-style macro case conservative, while formatting ordinary identifiers like T :: member as T::member.