[llvm-bugs] [Bug 40488] New: Clang does not notice default template parameters in class templates

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jan 27 10:44:59 PST 2019


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

            Bug ID: 40488
           Summary: Clang does not notice default template parameters in
                    class templates
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: andres.zhukov at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

tldr: If the class template has default parameters, but they are not declared
in the first forward declaration of that class, and when declaring an instance
of that class no angle brackets are specified, clang ignores the default
parameter and raises an error "no viable constructor or deduction guide for
deduction of template arguments of ...".

First found: 2019-01-24 on Windows 10 Education ver. 1803, using LLVM + Visual
Studio as well as normal clang toolchain.
Judging by godbolt showing same results, happens on linux as well.

This bug was documented on a StackOverflow question
(https://stackoverflow.com/q/54351543/9118363), where, aside from the things I
repeat here, there are good comments and discussion.

Example:

template <class T>
class Example;

template <class T = void>
class Example {};

int main() {
    Example e; // error: no viable constructor or deduction guide for deduction
of template arguments of 'Example'
}

Same example on godbolt (trunk): https://godbolt.org/z/OwjxDl
If you move "= void" to the forward-decl, it compiles. Also compiles if you
replace "Example e" with "Example<> e".

C++ standard says (http://eel.is/c++draft/temp.param#12):
    [temp.param]/12 - The set of default template-arguments available for use
is obtained by merging the default arguments from all prior declarations of the
template in the same way default function arguments are [ Example:

    template<class T1, class T2 = int> class A;
    template<class T1 = int, class T2> class A;
    is equivalent to

    template<class T1 = int, class T2 = int> class A;
    — end example ]

This would make my example code equivalent to

template <class T = void>
class Example {};

int main() {
    Example e;
}

which compiles as expected.

-- 
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/20190127/84fa65ba/attachment.html>


More information about the llvm-bugs mailing list