public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58923] New: g++ does not use provided conversion function for implicit conversion to another type
@ 2013-10-30 11:49 andre.ritter at fau dot de
  2013-10-30 13:09 ` [Bug c++/58923] " daniel.kruegler at googlemail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: andre.ritter at fau dot de @ 2013-10-30 11:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58923
           Summary: g++ does not use provided conversion function for
                    implicit conversion to another type
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre.ritter at fau dot de

Created attachment 31112
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31112&action=edit
Source file with complete test case

g++ is not able to compile the following test case which you also can find in
the attachment (file: 'cast.cc').

struct A
{
    virtual void do_it() const = 0;
};

struct B :  A
{
    virtual void do_it() const {}
};

struct C
{
    operator B() const { return B(); }
};

void do_it(const A& a) { a.do_it(); }

int main()
{
    C c;
    do_it(c);
    return 0;
}


When compiling this test case with clang++ (version 3.3) or the intel c++
compiler (versions 12.1 and 13.1), compilation succeeds without errors. When
compiling the same test case with g++ (version 4.8.1 from MacPorts, running OSX
Mavericks) the following errors are shown:

cast.cc: In function 'int main()':
cast.cc:21:9: error: cannot allocate an object of abstract type 'A'
 do_it(c);
        ^
cast.cc:1:8: note:   because the following virtual functions are pure within
'A':
struct A
       ^
cast.cc:3:15: note:     virtual void A::do_it() const
 virtual void do_it() const = 0;

              ^

I get the same errors when i try to compile the test case with g++ (versions
4.8.1, 4.7.0, 4.6.1, 4.3.4, 3.3.6) running on SUSE Linux.

Basically I have an abstract base class A and some implementation B. Another
class C provides a conversion operator to B. When passing instances of C to
functions that take const references of A clang++ and icpc is able to find the
conversion to B and is then able to convert the temporary instance of B to a
const reference of A. I think, in the same case, g++ tries to make a temporary
instance of A initialized with the instance of C which is not possible. 

A workaround for this problem is to explicitly convert the instance of C to B
like this:

do_it((B)c);

But then it would be nice if this is not necessary.

Here is the output of gcc-mp-4.8 -v
Using built-in specs.
COLLECT_GCC=gcc-mp-4.8
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin13/4.8.1/lto-wrapper
Target: x86_64-apple-darwin13
Configured with:
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc48/gcc48/work/gcc-4.8.1/configure
--prefix=/opt/local --build=x86_64-apple-darwin13
--enable-languages=c,c++,objc,obj-c++,lto,fortran,java
--libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-4.8
--with-gxx-include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --with-cloog=/opt/local
--enable-cloog-backend=isl --disable-cloog-version-check
--enable-stage1-checking --disable-multilib --enable-lto
--enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld
--with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket
--with-pkgversion='MacPorts gcc48 4.8.1_3'
Thread model: posix
gcc version 4.8.1 (MacPorts gcc48 4.8.1_3)


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

* [Bug c++/58923] g++ does not use provided conversion function for implicit conversion to another type
  2013-10-30 11:49 [Bug c++/58923] New: g++ does not use provided conversion function for implicit conversion to another type andre.ritter at fau dot de
@ 2013-10-30 13:09 ` daniel.kruegler at googlemail dot com
  2015-03-24 17:20 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-10-30 13:09 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
This is related to the core language issues

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1650
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1604

See also bug 57610. It seems that after bringing forward the example code from
the submitter of bug 57610 that the committee decided to leave the current
wording and this would make the here discussed example well-formed.
>From gcc-bugs-return-433025-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Oct 30 13:10:56 2013
Return-Path: <gcc-bugs-return-433025-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 9886 invoked by alias); 30 Oct 2013 13:10:56 -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 9860 invoked by uid 48); 30 Oct 2013 13:10:53 -0000
From: "fanael4 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/58924] Non-member invocation of overload of operator<< when the first argument is a temporary of type std::stringstream
Date: Wed, 30 Oct 2013 13:10: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: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: fanael4 at gmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-58924-4-esO3DO8g7H@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58924-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58924-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-10/txt/msg02169.txt.bz2
Content-length: 214

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

--- Comment #2 from Fanael <fanael4 at gmail dot com> ---
Er, 'operator<<(basic_ostream<charT, traits>& os, const charT* x)', without the
r-value ref, of course.


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

* [Bug c++/58923] g++ does not use provided conversion function for implicit conversion to another type
  2013-10-30 11:49 [Bug c++/58923] New: g++ does not use provided conversion function for implicit conversion to another type andre.ritter at fau dot de
  2013-10-30 13:09 ` [Bug c++/58923] " daniel.kruegler at googlemail dot com
@ 2015-03-24 17:20 ` paolo.carlini at oracle dot com
  2015-03-24 17:45 ` paolo at gcc dot gnu.org
  2015-03-24 17:48 ` paolo.carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-24 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paolo.carlini at oracle dot com

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
And indeed current trunk accepts it. I'm adding the testcase and closing the
bug.


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

* [Bug c++/58923] g++ does not use provided conversion function for implicit conversion to another type
  2013-10-30 11:49 [Bug c++/58923] New: g++ does not use provided conversion function for implicit conversion to another type andre.ritter at fau dot de
  2013-10-30 13:09 ` [Bug c++/58923] " daniel.kruegler at googlemail dot com
  2015-03-24 17:20 ` paolo.carlini at oracle dot com
@ 2015-03-24 17:45 ` paolo at gcc dot gnu.org
  2015-03-24 17:48 ` paolo.carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-03-24 17:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Tue Mar 24 17:22:27 2015
New Revision: 221640

URL: https://gcc.gnu.org/viewcvs?rev=221640&root=gcc&view=rev
Log:
2015-03-24  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/58923
    * g++.dg/other/virtual3.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/other/virtual3.C
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/58923] g++ does not use provided conversion function for implicit conversion to another type
  2013-10-30 11:49 [Bug c++/58923] New: g++ does not use provided conversion function for implicit conversion to another type andre.ritter at fau dot de
                   ` (2 preceding siblings ...)
  2015-03-24 17:45 ` paolo at gcc dot gnu.org
@ 2015-03-24 17:48 ` paolo.carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-24 17:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|paolo.carlini at oracle dot com    |
         Resolution|---                         |FIXED
   Target Milestone|---                         |5.0

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

end of thread, other threads:[~2015-03-24 17:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-30 11:49 [Bug c++/58923] New: g++ does not use provided conversion function for implicit conversion to another type andre.ritter at fau dot de
2013-10-30 13:09 ` [Bug c++/58923] " daniel.kruegler at googlemail dot com
2015-03-24 17:20 ` paolo.carlini at oracle dot com
2015-03-24 17:45 ` paolo at gcc dot gnu.org
2015-03-24 17:48 ` 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).