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

            Bug ID: 61089
           Summary: Misleading error message regarding inability to
                    convert pointers
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chrismonkie at gmail dot com

Problem:
Compiling the code below yields
t.cpp: In function ‘int main(int, char**)’:
t.cpp:14:14: error: cannot convert ‘boost::shared_ptr<derived>::element_type*
{aka derived*}’ to ‘base*’ for argument ‘1’ to ‘void func(base*)’

Derived and base are just forward declared so it makes sense that the compiler
won't convert one to the other. The issue is that the error message is
misleading. Normally if you forward declare and forget to include the header
and try to call something the compiler gives you a nice error message which
reminds you to include the appropriate header.
t.cpp:9:3: error: invalid use of incomplete type ‘struct base’
t.cpp:3:7: error: forward declaration of ‘struct base’

This seems like the same thing should happen. The compiler knows the types are
forward declared and needs to call an implicit conversion function so it needs
the complete types.


Version:
arm-linux-gnueabihf-gcc (crosstool-NG - Ambarella Linaro Multilib GCC [CortexA9
& ARMv6k] 2013.09) 4.8.2 20130902 (prerelease)

Commandline:
g++ -I PATH_TO_BOOST t.cpp

Code:
#include <boost/shared_ptr.hpp>

class base; // {};

class derived; // : public base {};

void func(base* p)
{
}

int main(int argc, char** argv)
{
    boost::shared_ptr<derived> p;
    func(p.get());

    return 0;
}

Reply via email to