[llvm-bugs] [Bug 39114] New: Default value for template parameter ignored due to friend declaration (where default is not allowed)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 28 06:12:37 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39114

            Bug ID: 39114
           Summary: Default value for template parameter ignored due to
                    friend declaration (where default is not allowed)
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: duvan.llvm at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Created attachment 20936
  --> https://bugs.llvm.org/attachment.cgi?id=20936&action=edit
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180928/806b0e17/attachment.html>


More information about the llvm-bugs mailing list