[PATCH] D152242: [Clang] Allow omitting `typename` in befriended consstructors parameters

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 6 00:27:32 PDT 2023


cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes #63119


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152242

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CXX/temp/temp.res/p4.cpp


Index: clang/test/CXX/temp/temp.res/p4.cpp
===================================================================
--- clang/test/CXX/temp/temp.res/p4.cpp
+++ clang/test/CXX/temp/temp.res/p4.cpp
@@ -170,3 +170,14 @@
 
 template <typename T>
 C<T>::C(T::type) {}
+
+namespace GH63119 {
+struct X {
+    X(int);
+    void f(int);
+};
+template<typename T> struct S {
+  friend X::X(T::type);
+  friend void X::f(T::type);
+};
+}
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -5820,9 +5820,12 @@
   // therefore, we know that this is a constructor.
   // Due to an ambiguity with implicit typename, the above is not enough.
   // Additionally, check to see if we are a friend.
+  // If we parsed a scope specifier as well as friend,
+  // we might be parsing a friend constructor.
   bool IsConstructor = false;
-  if (isDeclarationSpecifier(IsFriend ? ImplicitTypenameContext::No
-                                      : ImplicitTypenameContext::Yes))
+  if (isDeclarationSpecifier(IsFriend && !SS.isSet()
+                                 ? ImplicitTypenameContext::No
+                                 : ImplicitTypenameContext::Yes))
     IsConstructor = true;
   else if (Tok.is(tok::identifier) ||
            (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::identifier))) {
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -521,6 +521,9 @@
   (`#62494 <https://github.com/llvm/llvm-project/issues/62494>`_)
 - Fix handling of generic lambda used as template arguments.
   (`#62611 <https://github.com/llvm/llvm-project/issues/62611>`_)
+- Allow omitting ``typename`` in the parameter declaration of a friend
+  constructor declaration.
+  (`#63119 <https://github.com/llvm/llvm-project/issues/63119>`_)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152242.528727.patch
Type: text/x-patch
Size: 2013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230606/45ae70b1/attachment.bin>


More information about the cfe-commits mailing list