<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Default value for template parameter ignored due to friend declaration (where default is not allowed)"
   href="https://bugs.llvm.org/show_bug.cgi?id=39114">39114</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Default value for template parameter ignored due to friend declaration (where default is not allowed)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>duvan.llvm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20936" name="attach_20936" title="Small testcase">attachment 20936</a> <a href="attachment.cgi?id=20936&action=edit" title="Small testcase">[details]</a></span>
Small testcase

When compiling the attached file bug.C,

  bash> clang++ -std=c++17 bug.C

it results in the following error:

bug.C:19:14: error: no viable constructor or deduction guide for deduction of
template arguments of 'ok'
  auto oth = ok(th);
             ^
bug.C:13:3: note: candidate template ignored: couldn't infer template argument
''
  ok(T& t) : obj(t) {}
  ^
bug.C:8:48: note: candidate template ignored: could not match 'ok<T,
type-parameter-0-1>' against 'Thing'
  template <typename T, typename> friend class ok;
                                               ^
1 error generated.

My analysis is as follows:

As the declaration

  template <typename T, typename> friend class ok;

does not have a default for the second type argument (in fact, that is not
allowed), the definition, where the default is specified is not considered even
if it was written prior to the usage, i.e. ok(th).

The error message is less than stellar and it seems that the compiler does have
the knowledge that the definition of the template does have a default value of
the second template type parameter.  As the original code where this was an
issue spanned 100+ files with 100000+ lines of code, tracking down the problem
was non-trivial.

It seems weird that the default argument is not allowed in the friend
declaration but still have an influence regarding "ignoring" the default
argument of the definition.

The code compiles fine with gcc 8.2.0.  Feel free to change to enhancement if
gcc is wrong here -- tentative wording would be "Unhelpful error message for
template declaration with parameter without default".  In the latter case, I
guess that the compiler knows about the default argument in the definition and
could point out that it was ignored.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>