public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58022] New: Compiler rejects abstract class in template class with friend operator<<
@ 2013-07-29 20:03 scovich at gmail dot com
  2013-07-29 20:15 ` [Bug c++/58022] " paolo.carlini at oracle dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: scovich at gmail dot com @ 2013-07-29 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58022
           Summary: Compiler rejects abstract class in template class with
                    friend operator<<
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: scovich at gmail dot com

First, apologies for the vague subject line, I really don't know what to call
this bug...

Consider the following test case:

// <<<--- begin bug.cpp --->>>
#include <iostream>
using namespace std;
template <class T> class foo;
template <class T> ostream & operator<<(ostream& o, const foo<T>& l);
template <class T> class foo  {
    friend ostream& operator<< <T> (ostream& o, const foo<T>& l);
};
class bar;
foo<bar> fb;
class bar { virtual void baz()=0; };
// <<<--- end bug.cpp --->>>

The test case was isolated using multidelta on a large code base that compiles
cleanly with gcc-4.7 and earlier.

Compiling it with gcc-4.8.1 gives the error: "cannot allocate an object of
abstract type ‘bar’", and identifying this function in <ostream>:

  template<typename _CharT, typename _Traits>
    inline basic_ostream<_CharT, _Traits>&
    operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
    { return __ostream_insert(__out, &__c, 1); }

Replacing "using namespace std" with "std::ostream" everywhere allows it to
compile, as does moving the definition of bar above the friend declaration.

I'm not 100% certain the code is valid C++, seeing as how it instantiates a
template using an incomplete type, but there are still several issues:

1. The compiler gives no hint whatsoever where the real problem is, leaving the
user to infer the context in some other way; it took 2h with multidelta to
isolate the above test case and finally "see" what had happened.

2. The declaration of operator<< (which accepts a const ref) should not
interfere with the one in <ostream> (which accepts a value); without the const
ref declaration the compiler (rightfully!) complains that "template-id
‘operator<< <bar>’ for ‘std::ostream& operator<<(std::ostream&, const
foo<bar>&)’ does not match any template declaration"

3. At no point is bar actually instantiated, passed by value, or its members
accessed; even if operator<< did do one of those things, operator<< is never
actually called with foo<bar> as an argument, so the template shouldn't be
instantiated.

For now, the workaround seems to be ensuring that bar is fully defined before
any template class mentions it, but that's not going to be easy given how hard
it is to find the problem (and the fact that the foo template is in a utility
library and really should be included first under normal circumstances).
>From gcc-bugs-return-426928-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Jul 29 20:13:07 2013
Return-Path: <gcc-bugs-return-426928-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 28297 invoked by alias); 29 Jul 2013 20:13:07 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 28224 invoked by uid 48); 29 Jul 2013 20:13:03 -0000
From: "paolo.carlini at oracle dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/57948] internal compiler error: in initialize_reference, at cp/call.c:9285
Date: Mon, 29 Jul 2013 20:13:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords: ice-on-invalid-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: paolo.carlini at oracle dot com
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: paolo.carlini at oracle dot com
X-Bugzilla-Target-Milestone: 4.9.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: target_milestone bug_status resolution assigned_to
Message-ID: <bug-57948-4-h1Jc5F0WxC@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57948-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57948-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-07/txt/msg01435.txt.bz2
Content-length: 588

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW948

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.9.0
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed for 4.9.0.


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

* [Bug c++/58022] Compiler rejects abstract class in template class with friend operator<<
  2013-07-29 20:03 [Bug c++/58022] New: Compiler rejects abstract class in template class with friend operator<< scovich at gmail dot com
@ 2013-07-29 20:15 ` paolo.carlini at oracle dot com
  2013-07-29 20:18 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-29 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Please try to reduce the testcase further, no includes. You have a number of
options here: http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction


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

* [Bug c++/58022] Compiler rejects abstract class in template class with friend operator<<
  2013-07-29 20:03 [Bug c++/58022] New: Compiler rejects abstract class in template class with friend operator<< scovich at gmail dot com
  2013-07-29 20:15 ` [Bug c++/58022] " paolo.carlini at oracle dot com
@ 2013-07-29 20:18 ` paolo.carlini at oracle dot com
  2013-07-29 20:30 ` [Bug c++/58022] [4.8 Regression] " scovich at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-29 20:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
This compiles fine in mainline, doesn't with current 4_8-branch.


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

* [Bug c++/58022] [4.8 Regression] Compiler rejects abstract class in template class with friend operator<<
  2013-07-29 20:03 [Bug c++/58022] New: Compiler rejects abstract class in template class with friend operator<< scovich at gmail dot com
  2013-07-29 20:15 ` [Bug c++/58022] " paolo.carlini at oracle dot com
  2013-07-29 20:18 ` paolo.carlini at oracle dot com
@ 2013-07-29 20:30 ` scovich at gmail dot com
  2013-07-29 20:34 ` paolo.carlini at oracle dot com
  2013-07-30 16:59 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: scovich at gmail dot com @ 2013-07-29 20:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Ryan Johnson <scovich at gmail dot com> ---
(In reply to Paolo Carlini from comment #1)
> Please try to reduce the testcase further, no includes. You have a number of
> options here: http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction

Sorry, I thought <ostream> was an important part of the bug and did some work
to put it back in... Here's the fully reduced case:

// <<<--- begin bug.cpp --->>>
template<typename _CharT>
class basic_ostream;

typedef basic_ostream<char> ostream;

template<typename T>
basic_ostream<T>& operator<<(basic_ostream<T>&, T);

template <class T> class foo;

template <class T> ostream & operator<<(ostream&, const foo<T>&);

template <class T> class foo  {
    friend ostream& operator<< <T> (ostream&, const foo<T>&);
};

class bar;

foo<bar> fb;

class bar { virtual void baz()=0; };
// <<<--- end bug.cpp --->>>


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

* [Bug c++/58022] [4.8 Regression] Compiler rejects abstract class in template class with friend operator<<
  2013-07-29 20:03 [Bug c++/58022] New: Compiler rejects abstract class in template class with friend operator<< scovich at gmail dot com
                   ` (2 preceding siblings ...)
  2013-07-29 20:30 ` [Bug c++/58022] [4.8 Regression] " scovich at gmail dot com
@ 2013-07-29 20:34 ` paolo.carlini at oracle dot com
  2013-07-30 16:59 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-29 20:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-07-29
   Target Milestone|---                         |4.8.2
     Ever confirmed|0                           |1

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Thanks. Confirmed as a regression present only in 4_8-branch.


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

* [Bug c++/58022] [4.8 Regression] Compiler rejects abstract class in template class with friend operator<<
  2013-07-29 20:03 [Bug c++/58022] New: Compiler rejects abstract class in template class with friend operator<< scovich at gmail dot com
                   ` (3 preceding siblings ...)
  2013-07-29 20:34 ` paolo.carlini at oracle dot com
@ 2013-07-30 16:59 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2013-07-30 16:59 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 4.8.2


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

end of thread, other threads:[~2013-07-30 16:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-29 20:03 [Bug c++/58022] New: Compiler rejects abstract class in template class with friend operator<< scovich at gmail dot com
2013-07-29 20:15 ` [Bug c++/58022] " paolo.carlini at oracle dot com
2013-07-29 20:18 ` paolo.carlini at oracle dot com
2013-07-29 20:30 ` [Bug c++/58022] [4.8 Regression] " scovich at gmail dot com
2013-07-29 20:34 ` paolo.carlini at oracle dot com
2013-07-30 16:59 ` 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).