llvm-project
llvm-project copied to clipboard
clang-16 regression in friend functions with concept-constrained template arguments
Godbolt link: https://godbolt.org/z/j86T8dzMY
In Clang 16 (tested in both 16.0.0 via Godbolt and 16.0.6 via the standard LLVM Ubuntu distro), if you friend a function with a template argument that is concept-constrained:
template <typename T> concept some_concept = true;
template <some_concept T>
class Foo
{
private:
Foo();
template <some_concept U> friend Foo<U> Friended(U a);
};
template <some_concept T>
Foo<T> Friended(T a)
{ return {}; }
void Bar()
{ Friended(1); }
it fails to compile with a spurious error:
<source>:13:12: error: calling a private constructor of class 'Foo<int>'
{ return {}; }
^
<source>:16:5: note: in instantiation of function template specialization 'Friended<int>' requested here
{ Friended(1); }
^
<source>:7:3: note: declared private here
Foo();
^
If the function uses typename instead of some_concept it compiles fine (the supplied Godbolt link has both versions)
This compiles fine in Clang 14 and 15 (as well as GCC and MSVC).
@llvm/issue-subscribers-clang-frontend
CC @erichkeane
This also compiles fine in Clang trunk, probably fixed by 6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b.
We encounter this issue but are still confined to clang-16 for the moment.
Are there any hopes to fix this regression on release/16.x ? @alexander-shaposhnikov is 6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b something suitable to cherry pick there?
The regression seems introduced during LLVM 16 development in commit babdef27c503c0bbbcc017e9f88affddda90ea4e (by @erichkeane).