Class template argument deduction and default template parameters

前端 未结 1 576
灰色年华
灰色年华 2021-02-13 12:13

The following stripped down code doesn\'t work with the latest clang++5 but is accepted by g++7:

template
struct wrapper;

te         


        
1条回答
  •  粉色の甜心
    2021-02-13 12:42

    This is not a quote of the Standard per se1, but I feel confident enough to consider it an answer.

    According to cppreference, on Default template arguments:

    Default template arguments that appear in the declarations and the definition are merged similarly to default function arguments:

    template class A;
    template class A;
    // the above is the same as the following:
    template class A;
    

    But the same parameter cannot be given default arguments twice in the same scope

    template class X;
    template class X {}; // error
    

    This implies an implicit rule: A template type argument can be given a default type in the template declaration or template definition interchangeably.

    The behavior clang++5 exhibits is definitly a bug.


    1) Provided by user Oliv:

    [temp.param]/10

    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 ([dcl.fct.default]). [ Example:

    template class A;
    template class A;
    

    is equivalent to

    template class A;
    

     — end example ]

    0 讨论(0)
提交回复
热议问题