llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang-16 regression in friend functions with concept-constrained template arguments

Open DeadlyRedCube opened this issue 2 years ago • 2 comments

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).

DeadlyRedCube avatar Jun 26 '23 23:06 DeadlyRedCube

@llvm/issue-subscribers-clang-frontend

llvmbot avatar Jun 27 '23 00:06 llvmbot

CC @erichkeane

shafik avatar Jun 27 '23 01:06 shafik

This also compiles fine in Clang trunk, probably fixed by 6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b.

zygoloid avatar Sep 20 '23 23:09 zygoloid

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).

brunodf-snps avatar Sep 26 '23 13:09 brunodf-snps