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

            Bug ID: 111803
           Summary: Template deduction failure for baseclass member
                    pointer with template data type
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: grbrown93 at sbcglobal dot net
  Target Milestone: ---

Compiler error tested on versions 4.4, 6.1, 7.1, 10.1, 12.1, 13.2
Compiles fine on icpc and MSVC

> g++ test.cpp -o test
error: no matching function for call to 'Container<B>::print(float A::*)'

It should be trying to call 'Container<B>::print(float B::*)' but it's deducing
'A' from the 'data' member rather than 'B' from the 'ClassType' template arg.
Weirdly, it gets the correct call when using 'template print<float>' though
(guess that makes it follow a simpler logic path?).


Reproducible sample:

template<typename ClassType>
class Container
{
public:
        template<typename DataType>
        void print(DataType ClassType::*member)
        {
        }
};

class A
{
public:
        float data;

        template<typename ClassType>
        static void setup(Container<ClassType>& container)
        {
                container.print(&ClassType::data); // BROKEN IN GCC!
                container.template print<float>(&ClassType::data); //
WORKAROUND
                container.print((float ClassType::*)&ClassType::data); //
WORKAROUND
        }
};

class B : public A
{
public:
        double data2;

        template<typename ClassType>
        static void setup(Container<ClassType>& container)
        {
                A::setup(container);
                container.print(&ClassType::data2); // WORKS FINE
        }
};

int main()
{
        Container<B> container;
        B::setup(container);
        return 0;
}

Reply via email to