[clang] [clang-format] Handle templated elaborated type specifier in function… (PR #77013)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 11:17:42 PST 2024


================
@@ -3903,6 +3903,15 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
       parseParens();
   }
 
+  auto IsTemplate = [&] {
+    FormatToken *Tok = InitialToken.Previous;
+    while (Tok) {
+      if (Tok->is(tok::kw_template))
+        return true;
+      Tok = Tok->Previous;
+    }
+    return false;
+  };
   // Note that parsing away template declarations here leads to incorrectly
----------------
XDeme wrote:

Yes that comment would need to change a bit, I tested here again, and I noticed that a template method is still detected as a class declaration with this current patch:
```cpp
struct Foo {
   template<typename T>
   struct Goo<T> g() {}
};
```
The patch could be changed to check if the identifier before a `tok::l_paren` is a macro, and if it is, detect it as a class.
But I am not sure if this type of check is OK.

https://github.com/llvm/llvm-project/pull/77013


More information about the cfe-commits mailing list