public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56050] New: g++ compiler confused with virtual functions.
@ 2013-01-20 11:01 tristen_e at yahoo dot com
  2013-01-20 11:41 ` [Bug c++/56050] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: tristen_e at yahoo dot com @ 2013-01-20 11:01 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56050
           Summary: g++ compiler confused with virtual functions.
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tristen_e@yahoo.com


the following example code compiles cleanly when the second-and-third-last
lines in the main function are commented out, however when it's uncommented it
fails with:

a.cpp: In function ‘int main(int, const char**)’:
a.cpp:39:7: error: no matching function for call to ‘derived::to()’
a.cpp:39:7: note: candidate is:
a.cpp:30:7: note: virtual void derived::to(std::map<std::basic_string<char>,
std::basic_string<char> >)
a.cpp:30:7: note:   candidate expects 1 argument, 0 provided
a.cpp:40:27: error: no matching function for call to
‘derived::from(std::string)’
a.cpp:40:27: note: candidate is:
a.cpp:26:7: note: virtual void derived::from(std::map<std::basic_string<char>,
std::basic_string<char> >)
a.cpp:26:7: note:   no known conversion for argument 1 from ‘std::string {aka
std::basic_string<char>}’ to ‘std::map<std::basic_string<char>,
std::basic_string<char> >’

that was simply from a command line: g++ a.cpp

as you can see from the code below the compiler doesn't seem able to
differentiate between the virtual functions and the base functions, even though
the parameters differ. 

i think i was expecting the compiler to be able to differentiate between:

- "from" functions requiring std::string and std::map<std::string, std::string>
- "to" functions requiring void and std::map<std::string, std::string>

further, if the error is valid, i think i would expect the compilation to fail
regardless of whether the two lines in main are commented out or not, ie: the
compiler fails to detect the errors in the classes at compile-time.

regards
tristen

#include <map>
#include <string>
#include <iostream>

class base
{
    public:

    void from(std::string p_value)
    {
        std::cout << p_value << std::endl;
    }

    void to()
    {
    }

    virtual void from(std::map<std::string, std::string> p_map) = 0;
    virtual void to(std::map<std::string, std::string> p_map) = 0;
};

class derived : public base
{
    public:

    void from(std::map<std::string, std::string> p_map)
    {
    }

    void to(std::map<std::string, std::string> p_map)
    {
    }
};

int main(int, const char**)
{
    derived d;

//    d.to();
//    d.from(std::string("one"));

    return 0;
}


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

* [Bug c++/56050] g++ compiler confused with virtual functions.
  2013-01-20 11:01 [Bug c++/56050] New: g++ compiler confused with virtual functions tristen_e at yahoo dot com
@ 2013-01-20 11:41 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2013-01-20 11:41 UTC (permalink / raw)
  To: gcc-bugs


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-20 11:41:39 UTC ---
This is not a bug, it's called name hiding.

For d.to() the compiler does name lookup for  "to" in the scope of derived and
finds a name, so it stops looking. Then overload resolution tries to match the
arguments to the function and fails.

You need to re-declare the names in the derived class so all overloaded names
are visible in the derived class.

  using base::to;
  using base::from;


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

end of thread, other threads:[~2013-01-20 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-20 11:01 [Bug c++/56050] New: g++ compiler confused with virtual functions tristen_e at yahoo dot com
2013-01-20 11:41 ` [Bug c++/56050] " redi 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).