Topic: Can attempt to use =delete'd function be SFINAE failure ?


Author: Alexander Gutenev <gutenev@gmail.com>
Date: Thu, 19 Feb 2009 11:16:54 CST
Raw View
This was originally posted in "How = delete would work ?" discussion
in "comp.lang.c++.moderated". Reply by "Triple-DES" refer to
[dcl.fct.def]/10 and [dcl.fct.def]/10 of N2800, stating that it is not
very clear for this issue, so I'm reposting it here.

What should the following code print - "succeed", "failed" or compiler
diagnostic ?

template<void (*F)(void)>
struct check {};

struct no { char x; };
struct yes { no x[2]; };

template<typename T>
yes f(T t, check<&T::f> * = 0);
no f(...);

struct X
{
    static void f(void) = delete;
};

int main()
{
    if (sizeof(f(X())) == sizeof(yes))
      printf("succeed\n");
    else
      printf("failed\n");
    return 0;
}

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: doug.gregor@gmail.com
Date: Wed, 25 Feb 2009 10:03:31 CST
Raw View
On Feb 19, 9:16 am, Alexander Gutenev <gute...@gmail.com> wrote:
> This was originally posted in "How = delete would work ?" discussion
> in "comp.lang.c++.moderated". Reply by "Triple-DES" refer to
> [dcl.fct.def]/10 and [dcl.fct.def]/10 of N2800, stating that it is not
> very clear for this issue, so I'm reposting it here.

What's not clear? [dcl.fct.def]p10 says that referencing a deleted
function in any way makes the program ill-formed, and the note
clarifies that this includes the operand of sizeof():

   It applies even for references in expressions that are not
potentially-evaluated.

[temp.deduct]p7-8 of N2800 has the "extended" SFINAE rules that say
that any expression created by substituting the deduced template
arguments that would be ill-formed if written with the template
arguments causes a template argument deduction failure.

> What should the following code print - "succeed", "failed" or compiler
> diagnostic ?

"failed". The overload that would return "yes" fails during
substitution of the deduced template arguments.

   - Doug


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Triple-DES <DenPlettfrie@gmail.com>
Date: Thu, 26 Feb 2009 10:01:02 CST
Raw View
On 25 Feb, 17:03, doug.gre...@gmail.com wrote:
> On Feb 19, 9:16 am, Alexander Gutenev <gute...@gmail.com> wrote:
>
> > This was originally posted in "How = delete would work ?" discussion
> > in "comp.lang.c++.moderated". Reply by "Triple-DES" refer to
> > [dcl.fct.def]/10 and [dcl.fct.def]/10 of N2800, stating that it is not
> > very clear for this issue, so I'm reposting it here.
>
> What's not clear? [dcl.fct.def]p10 says that referencing a deleted
> function in any way makes the program ill-formed, and the note
> clarifies that this includes the operand of sizeof():
>
>    It applies even for references in expressions that are not
> potentially-evaluated.
>
> [temp.deduct]p7-8 of N2800 has the "extended" SFINAE rules that say
> that any expression created by substituting the deduced template
> arguments that would be ill-formed if written with the template
> arguments causes a template argument deduction failure.
>
> > What should the following code print - "succeed", "failed" or compiler
> > diagnostic ?
>
> "failed". The overload that would return "yes" fails during
> substitution of the deduced template arguments.
>
>    - Doug

Thanks for the clarification. The reason for my doubt was this:

"Only invalid types and expressions in the immediate context of the
function type and its template parameter
types can result in a deduction failure" ([temp.deduct]/8), and the
subsequent note that indicates that certain expressions created by
substitution may make the entire program ill-formed.


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: doug.gregor@gmail.com
Date: Fri, 27 Feb 2009 11:38:29 CST
Raw View
On Feb 26, 8:01 am, Triple-DES <DenPlettf...@gmail.com> wrote:
> On 25 Feb, 17:03, doug.gre...@gmail.com wrote:
>
>
>
> > On Feb 19, 9:16 am, Alexander Gutenev <gute...@gmail.com> wrote:
>
> > > This was originally posted in "How = delete would work ?" discussion
> > > in "comp.lang.c++.moderated". Reply by "Triple-DES" refer to
> > > [dcl.fct.def]/10 and [dcl.fct.def]/10 of N2800, stating that it is not
> > > very clear for this issue, so I'm reposting it here.
>
> > What's not clear? [dcl.fct.def]p10 says that referencing a deleted
> > function in any way makes the program ill-formed, and the note
> > clarifies that this includes the operand of sizeof():
>
> >    It applies even for references in expressions that are not
> > potentially-evaluated.
>
> > [temp.deduct]p7-8 of N2800 has the "extended" SFINAE rules that say
> > that any expression created by substituting the deduced template
> > arguments that would be ill-formed if written with the template
> > arguments causes a template argument deduction failure.
>
> > > What should the following code print - "succeed", "failed" or compiler
> > > diagnostic ?
>
> > "failed". The overload that would return "yes" fails during
> > substitution of the deduced template arguments.
>
> >    - Doug
>
> Thanks for the clarification. The reason for my doubt was this:
>
> "Only invalid types and expressions in the immediate context of the
> function type and its template parameter
> types can result in a deduction failure" ([temp.deduct]/8), and the
> subsequent note that indicates that certain expressions created by
> substitution may make the entire program ill-formed.

The intent here is to say that SFINAE does not extend into, e.g., the
instantiations of the definition of other class templates or the
bodies of function templates, which are outside of the immediate
context of the function type and its template parameter types.

   - Doug


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]