C++ Logo

STD-DISCUSSION

Advanced search

Subject: Defect Report 115: Address of template-id
From: Maris Razvan (razvyboy2004_at_[hidden])
Date: 2019-07-23 11:42:46


Defect Report 115
(http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#115)
says that if a template-id identifies a single function template
specialization, it is considered to be an lvalue for that function
template specialization, even if template argument deduction (for the
template arguments of the function template named by the template-name
inside the template-id, I suppose) is not done, or it is done, but it
fails.

I believe that the purpose of this defect report is to allow programs such as:

    template <typename Fn>
    void f(Fn param);

    template <typename T>
    void g(T);

    int main()
    {
        f(g<int>);
    }

This is because in the call "f(g<int>)", the type of "param" ("Fn") is
a non-deduced context since its respective argument used to be (before
this defect report) a function template. This is covered by the "in
contexts where template argument deduction is not done" part of the
defect report.

What I have trouble understanding is why does the defect report also
mention situations where template argument deduction is done, but
fails. Why do these contexts need to be explicitly mentioned in the
defect report?

I came up with an example which may be covered by the "contexts in
which template argument deduction is done, but fails" part of the
defect report, however I highly doubt that this was the reason why
this part was added to the defect report. The example is shown below:

    template <int i>
    struct B {};

    template <short i = 0>
    void f(B<i>);

    int main()
    {
        void (*pf) (B<0> param);
        pf = f<>();
    }

In the above example template argument deduction fails because the
non-type template parameter "i" of function template "f" is of type
"short", while the non-type template parameter "i" of class template
"B" is of type "int", and this situation is explicitly forbidded by
the standard. However, the default template argument for the non-type
template parameter "i" of function template "f" is exactly the
required value, so this program should now be correct. However, as I
said before, I do not think this is the example the authors of this
defect report had in mind.

Why do contexts where deduction fails have to be mentioned explicitly
in the standard?
Thank you for your help!


STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups