[PATCH] D116290: [clang-format] Add enforcement of consistent `class`/typename` keyword for template arguments

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 28 10:53:51 PST 2021


Quuxplusone added inline comments.


================
Comment at: clang/unittests/Format/TemplateArgumentKeywordFixerTest.cpp:119
+               Style);
+}
+
----------------
My personal recommended style is that the programmer uses `template<class>` consistently and therefore anytime you see the (more arcane) `typename` keyword it's probably necessary for (more arcane) reasons. You cover some arcane uses of `typename` above, but I think this one is conspicuously missing:
https://godbolt.org/z/fa9TM4nrr
```
template<class T, typename T::Nested V>
void f();
```
You can handle this by looking for `::` after the identifier, and if you find it, then `typename` should be kept as-is. In fact, if you find //any// token other than `,` `=` `>` after the identifier, something arcane might be happening and it'd be best to keep `typename` as-is.

Vice versa, `template<class C*>` can't be rewritten as `template<typename C*>`; again, I think the right approach is to leave the human's choice alone if you see anything other than `,` `=` `>` after the identifier.

In general, the problems of "Can this `typename` be rewritten as `class`" and vice versa are probably undecidable, so don't get too carried away with trying to be perfect as long as you hit all the most common cases anyone can think of. https://quuxplusone.github.io/blog/2019/12/27/template-typename-fun/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116290



More information about the cfe-commits mailing list