public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50248] New: gcc confused, tries to use variadic template to copy itself when it should use default constructor
@ 2011-08-31 10:14 b.r.longbons at gmail dot com
  2011-08-31 10:31 ` [Bug c++/50248] [C++0x] tries to use variadic constructor " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: b.r.longbons at gmail dot com @ 2011-08-31 10:14 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50248
           Summary: gcc confused, tries to use variadic template to copy
                    itself when it should use default constructor
    Classification: Unclassified
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: b.r.longbons@gmail.com


Created attachment 25149
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25149
far smaller example than the 30000 lines where I first encountered the bug

GCC is trying to instantiate the variadic template as if to copy itself, but
the only thing it should be doing is calling the default constructor.

It only happens when it is constexpr and uses rvalue references.

It only happens when it the parent class has a deleted copy constructor that
takes a *nonconst* reference.

4.5.3 compiles it, but that's because it actually ignores the constexpr
keyword.
Known bad: 4.6.0, 4.6.1-4 debian, svn trunk as of 20110804

Workarounds:
1. Don't use rvalue references.
2. Add a fixed parameter before the variadic one.

Error message:

bug.cpp: In constructor 'constexpr earray<Elt, max>::earray(Elt2&& ...) [with
Elt2 = {earray<short int, 11u>&}, Elt = short int, unsigned int max = 11u]':
bug.cpp:25:30:   instantiated from here
bug.cpp:9:50: error: cannot convert 'earray<short int, 11u>' to 'short int' in
initialization
bug.cpp:9: confused by earlier errors, bailing out


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

* [Bug c++/50248] [C++0x] tries to use variadic constructor when it should use default constructor
  2011-08-31 10:14 [Bug c++/50248] New: gcc confused, tries to use variadic template to copy itself when it should use default constructor b.r.longbons at gmail dot com
@ 2011-08-31 10:31 ` redi at gcc dot gnu.org
  2011-08-31 14:00 ` [Bug c++/50248] [C++0x] unnecessary instantiation of constexpr constructor jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2011-08-31 10:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-08-31 10:24:07 UTC ---
Thanks for not posting an example of 30k lines :)


another workaround is to add these constructors:

    MapSessionData(const MapSessionData&) = delete;
    MapSessionData() = default;


The error does not come from failing to use the default constructor, it comes
from the implicit-definition of the MapSessionData copy constructor.

[class.copy]/8 says:

- earray has an implicitly-declared copy-constructor of the form earray(const
earray&),
- MapSessionData has an implicitly-declared copy constructor of the form
MapSessionData(MapSessionData&) because its base class has a copy-constructor
taking a non-const parameter.

The implicitly-declared MapSessionData(MapSessionData&) copy-ctor should only
be implicitly-defined if it is odr-used (p13) so I'm not sure why it is, but
that implicit definition attempts to initialize equip_index with a non-const
parameter, which selects the variadic template because the earray(const earray)
constructor is not viable.

(The workaround above prevents the implicit-declaration of the MapSessionData
copy-ctor, so it doesn't attempt to use the variadic template.)


Jason, is it correct that the copy ctor is implicitly-defined?


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

* [Bug c++/50248] [C++0x] unnecessary instantiation of constexpr constructor
  2011-08-31 10:14 [Bug c++/50248] New: gcc confused, tries to use variadic template to copy itself when it should use default constructor b.r.longbons at gmail dot com
  2011-08-31 10:31 ` [Bug c++/50248] [C++0x] tries to use variadic constructor " redi at gcc dot gnu.org
@ 2011-08-31 14:00 ` jason at gcc dot gnu.org
  2011-09-05  4:34 ` jason at gcc dot gnu.org
  2011-09-06 23:08 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-31 14:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011-08-31
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
            Summary|[C++0x] tries to use        |[C++0x] unnecessary
                   |variadic constructor when   |instantiation of constexpr
                   |it should use default       |constructor
                   |constructor                 |
     Ever Confirmed|0                           |1

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-08-31 13:29:33 UTC ---
The copy constructor isn't being defined, but the compiler is instantiating the
constexpr constructor to find out if it is really constexpr, and therefore
whether the implicitly-declared copy constructor should be declared constexpr.

We decided at Bloomington that we should just consider instantiations of
constexpr templates to be constexpr, not instantiate them to check.


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

* [Bug c++/50248] [C++0x] unnecessary instantiation of constexpr constructor
  2011-08-31 10:14 [Bug c++/50248] New: gcc confused, tries to use variadic template to copy itself when it should use default constructor b.r.longbons at gmail dot com
  2011-08-31 10:31 ` [Bug c++/50248] [C++0x] tries to use variadic constructor " redi at gcc dot gnu.org
  2011-08-31 14:00 ` [Bug c++/50248] [C++0x] unnecessary instantiation of constexpr constructor jason at gcc dot gnu.org
@ 2011-09-05  4:34 ` jason at gcc dot gnu.org
  2011-09-06 23:08 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-09-05  4:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-09-05 04:33:14 UTC ---
Author: jason
Date: Mon Sep  5 04:33:08 2011
New Revision: 178518

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178518
Log:
    PR c++/50248
    Core 1358
    * init.c (perform_member_init): Don't diagnose missing inits here.
    (emit_mem_initializers): Or here.
    * method.c (process_subob_fn): Don't instantiate constexpr ctors.
    * semantics.c (cx_check_missing_mem_inits): New.
    (explain_invalid_constexpr_fn): Call it.
    (register_constexpr_fundef): Likewise.  Leave
    DECL_DECLARED_CONSTEXPR_P set when the body is unsuitable.
    (cxx_eval_call_expression): Adjust diagnostics.
    (cxx_eval_constant_expression): Catch use of 'this' in a constructor.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-template1.C
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-template2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c
    trunk/gcc/cp/method.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C


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

* [Bug c++/50248] [C++0x] unnecessary instantiation of constexpr constructor
  2011-08-31 10:14 [Bug c++/50248] New: gcc confused, tries to use variadic template to copy itself when it should use default constructor b.r.longbons at gmail dot com
                   ` (2 preceding siblings ...)
  2011-09-05  4:34 ` jason at gcc dot gnu.org
@ 2011-09-06 23:08 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-09-06 23:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-09-06 22:53:30 UTC ---
Fixed for 4.7.


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

end of thread, other threads:[~2011-09-06 22:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-31 10:14 [Bug c++/50248] New: gcc confused, tries to use variadic template to copy itself when it should use default constructor b.r.longbons at gmail dot com
2011-08-31 10:31 ` [Bug c++/50248] [C++0x] tries to use variadic constructor " redi at gcc dot gnu.org
2011-08-31 14:00 ` [Bug c++/50248] [C++0x] unnecessary instantiation of constexpr constructor jason at gcc dot gnu.org
2011-09-05  4:34 ` jason at gcc dot gnu.org
2011-09-06 23:08 ` 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).