public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49205] New: Default constructor with pack expansion parameter not detected
@ 2011-05-28  0:48 schaub.johannes at googlemail dot com
  2011-05-28  1:46 ` [Bug c++/49205] " coppro at users dot sourceforge.net
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-05-28  0:48 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Default constructor with pack expansion parameter not
                    detected
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: schaub.johannes@googlemail.com


This is rejected as "ambiguous" by GCC:

struct A { 
  template<typename ...T> A(T...); 
  A(initializer_list<short>); 
  A(initializer_list<long>); 
}; 

A a{};

But in fact, 8.5.4p3:

"If the initializer list has no elements and T is a class type with a default
constructor, the object is value-initialized."

And 12.1p5:

"A default constructor for a class X is a constructor of class X that can be
called without an argument."

So, there is no ambiguity. The default ctor is called, and "T" is deduced to
"<>"(empty pack).


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

* [Bug c++/49205] Default constructor with pack expansion parameter not detected
  2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
@ 2011-05-28  1:46 ` coppro at users dot sourceforge.net
  2011-05-28  1:55 ` [Bug c++/49205] [C++0x] " schaub.johannes at googlemail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: coppro at users dot sourceforge.net @ 2011-05-28  1:46 UTC (permalink / raw)
  To: gcc-bugs

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

Sean Hunt <coppro at users dot sourceforge.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |coppro at users dot
                   |                            |sourceforge.net

--- Comment #1 from Sean Hunt <coppro at users dot sourceforge.net> 2011-05-28 00:58:28 UTC ---
While this behavior is erroneous, consensus at clang was that WG21 made an
oversight in allowing this. Template constructors are banned from being copy or
move constructors, and historically this prohibition was not necessary for
default constructors since there was no special handling of them except when
implicit.


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

* [Bug c++/49205] [C++0x] Default constructor with pack expansion parameter not detected
  2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
  2011-05-28  1:46 ` [Bug c++/49205] " coppro at users dot sourceforge.net
@ 2011-05-28  1:55 ` schaub.johannes at googlemail dot com
  2011-05-28  2:06 ` scshunt at csclub dot uwaterloo.ca
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-05-28  1:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-05-28 01:45:29 UTC ---
(In reply to comment #1)
> While this behavior is erroneous, consensus at clang was that WG21 made an
> oversight in allowing this. Template constructors are banned from being copy or
> move constructors, and historically this prohibition was not necessary for
> default constructors since there was no special handling of them except when
> implicit.

That rationale makes sense. I wonder about the implications for value
initialization though. If that constructor is not a default constructor, then
"A();" appears to be ill-formed, because of the saying in 8.5p7 that we shall
call "the default constructor". 

Also, how should the rules be drawn? Is any template not a default constructor?
Then what about the following?

  template<typename T = int> A(T = 0); 

GCC appears to deem it a default constructor. Is the following rule acceptable?

- A default constructor is a constructor with zero parameters or that only has
parameters with default arguments and with an optional trailing ellipsis
("A(int, ...)").


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

* [Bug c++/49205] [C++0x] Default constructor with pack expansion parameter not detected
  2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
  2011-05-28  1:46 ` [Bug c++/49205] " coppro at users dot sourceforge.net
  2011-05-28  1:55 ` [Bug c++/49205] [C++0x] " schaub.johannes at googlemail dot com
@ 2011-05-28  2:06 ` scshunt at csclub dot uwaterloo.ca
  2011-05-28  3:22 ` schaub.johannes at googlemail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: scshunt at csclub dot uwaterloo.ca @ 2011-05-28  2:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Sean Hunt <scshunt at csclub dot uwaterloo.ca> 2011-05-28 01:55:07 UTC ---
I would expect that the initialization text would be amended appropriately. I
think that we should go for consistency and say non-templates only, the same as
for copy and move constructors.


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

* [Bug c++/49205] [C++0x] Default constructor with pack expansion parameter not detected
  2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
                   ` (2 preceding siblings ...)
  2011-05-28  2:06 ` scshunt at csclub dot uwaterloo.ca
@ 2011-05-28  3:22 ` schaub.johannes at googlemail dot com
  2011-06-20  1:53 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-05-28  3:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-05-28 02:06:07 UTC ---
(In reply to comment #3)
> I would expect that the initialization text would be amended appropriately. I
> think that we should go for consistency and say non-templates only, the same as
> for copy and move constructors.

Ah I see. That seems to make sense.


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

* [Bug c++/49205] [C++0x] Default constructor with pack expansion parameter not detected
  2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
                   ` (3 preceding siblings ...)
  2011-05-28  3:22 ` schaub.johannes at googlemail dot com
@ 2011-06-20  1:53 ` jason at gcc dot gnu.org
  2011-06-20 14:41 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-20  1:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.06.20 01:53:05
                 CC|                            |jason at gcc dot gnu.org
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug c++/49205] [C++0x] Default constructor with pack expansion parameter not detected
  2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
                   ` (4 preceding siblings ...)
  2011-06-20  1:53 ` jason at gcc dot gnu.org
@ 2011-06-20 14:41 ` jason at gcc dot gnu.org
  2011-06-20 14:46 ` jason at gcc dot gnu.org
  2011-06-20 15:57 ` schaub.johannes at googlemail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-20 14:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-20 14:40:15 UTC ---
Author: jason
Date: Mon Jun 20 14:40:10 2011
New Revision: 175214

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175214
Log:
    PR c++/49205
    * call.c (sufficient_parms_p): Allow parameter packs too.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/variadic-default.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/49205] [C++0x] Default constructor with pack expansion parameter not detected
  2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
                   ` (5 preceding siblings ...)
  2011-06-20 14:41 ` jason at gcc dot gnu.org
@ 2011-06-20 14:46 ` jason at gcc dot gnu.org
  2011-06-20 15:57 ` schaub.johannes at googlemail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-20 14:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.0

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-20 14:43:23 UTC ---
(In reply to comment #1)
> While this behavior is erroneous, consensus at clang was that WG21 made an
> oversight in allowing this. Template constructors are banned from being copy or
> move constructors, and historically this prohibition was not necessary for
> default constructors since there was no special handling of them except when
> implicit.

I disagree with this.  As Johannes points out, it is possible to have a
template default constructor in C++03, so changing this would be a significant
change.  We should just treat the variadic template as a default constructor.


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

* [Bug c++/49205] [C++0x] Default constructor with pack expansion parameter not detected
  2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
                   ` (6 preceding siblings ...)
  2011-06-20 14:46 ` jason at gcc dot gnu.org
@ 2011-06-20 15:57 ` schaub.johannes at googlemail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-06-20 15:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-06-20 15:56:42 UTC ---
(In reply to comment #6)
> (In reply to comment #1)
> > While this behavior is erroneous, consensus at clang was that WG21 made an
> > oversight in allowing this. Template constructors are banned from being copy or
> > move constructors, and historically this prohibition was not necessary for
> > default constructors since there was no special handling of them except when
> > implicit.
> 
> I disagree with this.  As Johannes points out, it is possible to have a
> template default constructor in C++03, so changing this would be a significant
> change.  We should just treat the variadic template as a default constructor.

To be fair to Sean, I should note that my example relied on a C++0x feature. If
we remove the template default argument:

    template<typename T> A(T = 0); 

This constructor cannot really be called "with arguments" anymore (there's no
deduction from default arguments), which is the condition under which a
constructor becomes a default constructor.


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

end of thread, other threads:[~2011-06-20 15:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-28  0:48 [Bug c++/49205] New: Default constructor with pack expansion parameter not detected schaub.johannes at googlemail dot com
2011-05-28  1:46 ` [Bug c++/49205] " coppro at users dot sourceforge.net
2011-05-28  1:55 ` [Bug c++/49205] [C++0x] " schaub.johannes at googlemail dot com
2011-05-28  2:06 ` scshunt at csclub dot uwaterloo.ca
2011-05-28  3:22 ` schaub.johannes at googlemail dot com
2011-06-20  1:53 ` jason at gcc dot gnu.org
2011-06-20 14:41 ` jason at gcc dot gnu.org
2011-06-20 14:46 ` jason at gcc dot gnu.org
2011-06-20 15:57 ` schaub.johannes at googlemail dot com

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).