This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/54058] New: Injected friend functions are not considered when using contextual type info to take a function address


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

             Bug #: 54058
           Summary: Injected friend functions are not considered when
                    using contextual type info to take a function address
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: andy.m.jost@gmail.com


Created attachment 27851
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27851
Compiler output

When attempting to take a function address where contextual type info is
needed, injected friend functions are not properly considered.

Here is the source file:

    template<typename Derived> struct Injector
    {
      friend Derived const f(Derived const &) { return Derived(); }
    };

    struct A : Injector<A> {};
    struct B : Injector<B> {};

    int main()
    {
      A const (*fp)(A const &) = &f;
      (void)fp;
    }

The error given is particularly confusing: g++ reports no matching function,
but then proceeds to give a list of candidates that includes an exact match!

test.cpp: In function âint main()â:
test.cpp:11:31: error: no matches converting function âfâ to type âconst struct
A (*)(const struct A&)â
test.cpp:3:24: error: candidates are: const A f(const A&)
test.cpp:3:24: error:                 const B f(const B&)

The full output of "g++ -v -save-temps -Wall -Wextra test.cpp" is attached. 
Found with g++ 4.5.2.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]