[PATCH] D140843: [clang-format] fix template closer followed by >

Zhikai Zeng via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 05:45:21 PST 2023


Backl1ght added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:169-171
+            CurrentToken->getStartOfNonWhitespace() ==
+                CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+                    -1)) {
----------------
MyDeveloperDay wrote:
> I was wondering this is actually saying....   
> 
> I think its saying... 2 tokens are next to each other ">>"  its not so much formatting but ensuring the existing formatting is maintained, is that what you understand?
> 
> Whilst this works it won't correct the case where the whitespace is wrong
> 
> i.e. I don't think
> 
> ```
> if (std::tuple_size_v < T >> 0) {
> }
> ```
> 
> will be corrected to be
> 
> ```
> if (std::tuple_size_v<T> > 0) {
> }
> ```
> 
> I'm a little wary of rules that use the existing whitespace, but I tend to agree that it might be ok without the extra check. 
> 
> It would be good to capture this as an annotator test (I like the verifyformat one you put in) but the annotator tests we can assert that its actually a templatecloser and binary operatror
> 
> 
> 
I think there should be more infomation to make the correction.

So far, we only know that `tuple_size_v` is an identifier, but the exact type of `tuple_size_v` is unknown. Maybe `tuple_size_v` is a type trait and in this case we should make the correction. Maybe `tuple_size_v` is an interger and in this case we should not make the correction.

To make the correction, we need at least one of:
1. is `tuple_size_v` a type trait?
2. is `T` a typename?
3. is `>>` a right shift?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140843/new/

https://reviews.llvm.org/D140843



More information about the cfe-commits mailing list