public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59579] New: Defaulted copy constructor of template class is instantiated even when not called (probably bug 57153)
@ 2013-12-22 17:30 Konstantin.Sadov at gmail dot com
  2013-12-22 21:30 ` [Bug c++/59579] " Konstantin.Sadov at gmail dot com
  2015-03-19  8:43 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: Konstantin.Sadov at gmail dot com @ 2013-12-22 17:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59579
           Summary: Defaulted copy constructor of template class is
                    instantiated even when not called (probably bug 57153)
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Konstantin.Sadov at gmail dot com

The following code

struct A{A()=default;A(A&)=default;};
template<typename B>struct C:B{C()=default;
#if 1
C(const C&)=default;//Fails
#else
C(const C&c):B(c){};//Works
#endif
};
C<A> d;
int main(){}

produces the following error

$g++ -std=c++11 main.cpp
main.cpp: In instantiation of 'struct C<A>':
main.cpp:9:6:   required from here
main.cpp:4:1: error: 'C<B>::C(const C<B>&) [with B = A]' declared to take const
reference, but implicit declaration would take non-const
 C(const C&)=default;//Fails
 ^

Looks like defaulted function is implicitly instantiated even if it's not used
(it's not so for user-defined functions).

GCC 4.4 worked well with this case.


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

* [Bug c++/59579] Defaulted copy constructor of template class is instantiated even when not called (probably bug 57153)
  2013-12-22 17:30 [Bug c++/59579] New: Defaulted copy constructor of template class is instantiated even when not called (probably bug 57153) Konstantin.Sadov at gmail dot com
@ 2013-12-22 21:30 ` Konstantin.Sadov at gmail dot com
  2015-03-19  8:43 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin.Sadov at gmail dot com @ 2013-12-22 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Konstantin Sadov <Konstantin.Sadov at gmail dot com> ---
Similar programs with defaulted default and move constructors work, so the
problem is for copy constructor only.

struct A{A()=delete;A(A&)=default;};
template <typename B>
struct C:B{C()=default;C(C&)=default;};
C<A> d(d);
int main(){}


struct A{A()=default;A(A&&)=delete;};
template <typename B>
struct C:B{C()=default;C(C&&)=default;};
C<A> d;
int main(){}


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

* [Bug c++/59579] Defaulted copy constructor of template class is instantiated even when not called (probably bug 57153)
  2013-12-22 17:30 [Bug c++/59579] New: Defaulted copy constructor of template class is instantiated even when not called (probably bug 57153) Konstantin.Sadov at gmail dot com
  2013-12-22 21:30 ` [Bug c++/59579] " Konstantin.Sadov at gmail dot com
@ 2015-03-19  8:43 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-19  8:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59579

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

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

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Not a bug. By the way EDG and clang reject the testcase with the same
diagnostic.


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

end of thread, other threads:[~2015-03-19  8:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-22 17:30 [Bug c++/59579] New: Defaulted copy constructor of template class is instantiated even when not called (probably bug 57153) Konstantin.Sadov at gmail dot com
2013-12-22 21:30 ` [Bug c++/59579] " Konstantin.Sadov at gmail dot com
2015-03-19  8:43 ` paolo.carlini at oracle 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).