title: Private constructor of friend function's default argument in C++
body: <p>Recently a related question was asked <a href="https://stackoverflow.com/questions/68717308/can-a-friend-function-in-c-have-a-default-argument-whose-type-has-a-private-de">Can a friend function in C++ have a default argument whose type has a private destructor?</a> and received an excellent answer.
  It seems that private constructor of that type is not less interesting.</p>
  <p>Please consider the code:</p>
  <pre><code>class U { 
  public:
      U() {} 
      template&lt;typename T&gt;
      friend void foo(T, T = 1) {}
  private:
      U(int) {}
  };
  
  int main() { 
      foo(U{}); 
  }
  </code></pre>
  <p>Here template friend function <code>foo</code> has a default argument requiring to call private constructor <code>U(int)</code>.</p>
  <p>Since default arguments are bound at the point of declaration, and their access is checked at that point rather than at any points of use of the default argument, the program should be well formed. And GCC accepts the program, while both Clang and MSVC reject it with the error:</p>
  <pre><code>error: calling a private constructor of class 'U'
      friend void foo(T, T = 1) {}
                           ^
  &lt;source&gt;:11:5: note: in instantiation of default function argument expression for 'foo&lt;U&gt;' required here
      foo(U{}); 
      ^
  &lt;source&gt;:7:5: note: declared private here
      U(int) {}
      ^
  </code></pre>
  <p>Demo: <a href="https://gcc.godbolt.org/z/bPTGYvnx1" rel="nofollow noreferrer">https://gcc.godbolt.org/z/bPTGYvnx1</a></p>
  <p>Probably template friend functions behave somewhat differently as to access checking. Which of the compilers is right here?</p>