public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]"
@ 2011-05-18 20:20 schaub.johannes at googlemail dot com
  2011-05-18 22:18 ` [Bug c++/49051] [C++0x] " paolo.carlini at oracle dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-05-18 20:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49051

           Summary: Doesn't SFINAE away an invalid substitution into
                    toplevel parameter type "T[N]"
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: schaub.johannes@googlemail.com


GCC incorrectly fails to compile this code

template<typename T> void f(T[1]) = delete; 
template<typename T> void f(...); 
int main() { f<void>(0); }

The substitution into "T" should fail, because "T[1]" is an invalid type, and
hence the call should use the second template. 

Note that I think it's unspecified in the spec what happens when we tweak
things as follows

template<typename T> void f(T[1]) = delete; 
template<typename T> void f(T*);
template<typename T> void f(...); 
int main() { f<void>(0); }

The first two templates are equivalent, but behave different during
substitution. The spec doesn't specify what the outcome of this is, I think.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/49051] [C++0x] Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]"
  2011-05-18 20:20 [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]" schaub.johannes at googlemail dot com
@ 2011-05-18 22:18 ` paolo.carlini at oracle dot com
  2011-05-19 16:23 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-05-18 22:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49051

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.05.18 21:47:16
                 CC|                            |jason at gcc dot gnu.org
            Summary|Doesn't SFINAE away an      |[C++0x] Doesn't SFINAE away
                   |invalid substitution into   |an invalid substitution
                   |toplevel parameter type     |into toplevel parameter
                   |"T[N]"                      |type "T[N]"
     Ever Confirmed|0                           |1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/49051] [C++0x] Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]"
  2011-05-18 20:20 [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]" schaub.johannes at googlemail dot com
  2011-05-18 22:18 ` [Bug c++/49051] [C++0x] " paolo.carlini at oracle dot com
@ 2011-05-19 16:23 ` jason at gcc dot gnu.org
  2011-05-19 16:59 ` schaub.johannes at googlemail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-05-19 16:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49051

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> 2011-05-19 16:05:05 UTC ---
I disagree.  The transformation of array to pointer is done immediately at
declaration time (8.3.5/6), so there is no substitution into an array type.  In
resolving issue 1001, core agreed that the transformations in 8.3.5/6 are done
at template definition time, not deferred until the instantiation.

http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#1001
http://wiki.dinkumware.com/twiki/bin/view/Wg21batavia/CoreWorkingGroup#Core_issue_1001_Parameter_type_a


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/49051] [C++0x] Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]"
  2011-05-18 20:20 [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]" schaub.johannes at googlemail dot com
  2011-05-18 22:18 ` [Bug c++/49051] [C++0x] " paolo.carlini at oracle dot com
  2011-05-19 16:23 ` jason at gcc dot gnu.org
@ 2011-05-19 16:59 ` schaub.johannes at googlemail dot com
  2011-05-19 17:21 ` schaub.johannes at googlemail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-05-19 16:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49051

--- Comment #2 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-05-19 16:26:30 UTC ---
(In reply to comment #1)
> I disagree.  The transformation of array to pointer is done immediately at
> declaration time (8.3.5/6), so there is no substitution into an array type.  In
> resolving issue 1001, core agreed that the transformations in 8.3.5/6 are done
> at template definition time, not deferred until the instantiation.
> 
> http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#1001
> http://wiki.dinkumware.com/twiki/bin/view/Wg21batavia/CoreWorkingGroup#Core_issue_1001_Parameter_type_a

jason, the transformation is immediately done at declaration time. I agree:
That's why these two are equivalent:

    template<typename T> void f(T[1]);
    template<typename T> void f(T*);

For equivalence, both shall have identical parameter-type-lists, which these
have. But before argument deduction, explicit template arguments are
substituted, and those explicit arguments are substituted into the *unadjusted*
parameter type. See 14.8.2p3 (FDIS):

"After this substitution is performed, the function parameter type adjustments
described in 8.3.5 are performed."

The note that contains a list of substitution failures also has an example like
that at 14.8.2p8:

   template <class T> int f(T[5]);
   int I = f<int>(0);
   int j = f<void>(0); // invalid array


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/49051] [C++0x] Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]"
  2011-05-18 20:20 [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]" schaub.johannes at googlemail dot com
                   ` (2 preceding siblings ...)
  2011-05-19 16:59 ` schaub.johannes at googlemail dot com
@ 2011-05-19 17:21 ` schaub.johannes at googlemail dot com
  2011-05-19 18:01 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-05-19 17:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49051

--- Comment #3 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-05-19 16:56:07 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > I disagree.  The transformation of array to pointer is done immediately at
> > declaration time (8.3.5/6), so there is no substitution into an array type.  In
> > resolving issue 1001, core agreed that the transformations in 8.3.5/6 are done
> > at template definition time, not deferred until the instantiation.
> > 
> > http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#1001
> > http://wiki.dinkumware.com/twiki/bin/view/Wg21batavia/CoreWorkingGroup#Core_issue_1001_Parameter_type_a
> 
> jason, the transformation is immediately done at declaration time. I agree:
> That's why these two are equivalent:
> 
>     template<typename T> void f(T[1]);
>     template<typename T> void f(T*);
> 
> For equivalence, both shall have identical parameter-type-lists, which these
> have. But before argument deduction, explicit template arguments are
> substituted, and those explicit arguments are substituted into the *unadjusted*
> parameter type. See 14.8.2p3 (FDIS):
> 
> "After this substitution is performed, the function parameter type adjustments
> described in 8.3.5 are performed."
> 
> The note that contains a list of substitution failures also has an example like
> that at 14.8.2p8:
> 
>    template <class T> int f(T[5]);
>    int I = f<int>(0);
>    int j = f<void>(0); // invalid array

Ah I see now: The substitution for explicit arguments uses the *function type*,
not the parameter types (according to p6). So in the example above, it uses
"T*" and becomes "void*". It doesn't use "T[5]". p3 only applies when the
dependent type was adjusted and substitution made it a non-adjusted type.

So on a second read of this, I agree to you. The note at 14.8.2p8 and the
example of p3 were confusing me, both tricking me into thinking that for
substitution, the parameter types themselves somehow would be used.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/49051] [C++0x] Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]"
  2011-05-18 20:20 [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]" schaub.johannes at googlemail dot com
                   ` (3 preceding siblings ...)
  2011-05-19 17:21 ` schaub.johannes at googlemail dot com
@ 2011-05-19 18:01 ` jason at gcc dot gnu.org
  2011-06-26 13:40 ` schaub.johannes at googlemail dot com
  2011-08-30 22:45 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-05-19 18:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49051

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |SUSPENDED
         Resolution|INVALID                     |

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-05-19 17:20:44 UTC ---
Hmm, the example in 14.8.2p8 does seem to contradict my interpretation of the
normative wording.  I'll raise this with core.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/49051] [C++0x] Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]"
  2011-05-18 20:20 [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]" schaub.johannes at googlemail dot com
                   ` (4 preceding siblings ...)
  2011-05-19 18:01 ` jason at gcc dot gnu.org
@ 2011-06-26 13:40 ` schaub.johannes at googlemail dot com
  2011-08-30 22:45 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-06-26 13:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49051

--- Comment #5 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-06-26 13:40:34 UTC ---
(In reply to comment #4)
> Hmm, the example in 14.8.2p8 does seem to contradict my interpretation of the
> normative wording.  I'll raise this with core.

A related question, if in the end we in fact don't SFINAE or error out with
"T[N]" is, whether substitution for "N" is done at all. Because the type would
be "T*", not "T[N]" anymore. 

    template<typename T>
    void f(char[T::size]);

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

Does the substitution succeed?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/49051] [C++0x] Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]"
  2011-05-18 20:20 [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]" schaub.johannes at googlemail dot com
                   ` (5 preceding siblings ...)
  2011-06-26 13:40 ` schaub.johannes at googlemail dot com
@ 2011-08-30 22:45 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-30 22:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49051

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2011-08-30 21:56:42 UTC ---
This will eventually be issue 1322,

  http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#1322

but the issues list hasn't been updated yet.  In Bloomington we assigned it
priority 1 but didn't get to discussing it.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-08-30 21:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-18 20:20 [Bug c++/49051] New: Doesn't SFINAE away an invalid substitution into toplevel parameter type "T[N]" schaub.johannes at googlemail dot com
2011-05-18 22:18 ` [Bug c++/49051] [C++0x] " paolo.carlini at oracle dot com
2011-05-19 16:23 ` jason at gcc dot gnu.org
2011-05-19 16:59 ` schaub.johannes at googlemail dot com
2011-05-19 17:21 ` schaub.johannes at googlemail dot com
2011-05-19 18:01 ` jason at gcc dot gnu.org
2011-06-26 13:40 ` schaub.johannes at googlemail dot com
2011-08-30 22:45 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).