Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350345

Summary: Invalid overload using typedef (address of overloaded function)
Product: [Tools] CDT Reporter: Marc-AndrĂ© Laperle <malaperle>
Component: cdt-parserAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug
Version: 8.0   
Target Milestone: 8.0.1   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 241717    

Description Marc-André Laperle CLA 2011-06-25 03:06:01 EDT
Using 8.0

class Foo;

template<typename Arg>
class Callback
{
public:
    Callback(void (Foo::*function)(Arg arg))
    {
    }
};

typedef Callback<int> MyCallback;

void Subscribe(MyCallback callback)
{
}

class Foo
{
public:
    void Method(int) {}
    void Method() const {}
};

int main()
{
    Subscribe(MyCallback(&Foo::Method)); // Invalid overload of 'Foo::Method'
    return 0;
}

If I remove the typedef and replace MyCallback with Callback<int>, it works. If I declare a MyCallback outside the Subscribe call, it works.
Comment 1 Markus Schorn CLA 2011-06-29 10:30:34 EDT
Thanks, I can reproduce the issue.
Comment 2 Markus Schorn CLA 2011-07-04 05:44:09 EDT
Added testcase + fix.
Comment 3 Doug Schaefer CLA 2011-09-19 16:08:44 EDT
This fix may have broken the fix for 241717.
Comment 4 Markus Schorn CLA 2011-09-28 04:34:20 EDT
The current solution is inconsisent:

When the type id of an explicit type conversion in functional notation is a named type, then it is modelled as a function call. This is wrong but convenient. Otherwise we'd have to create an ambiguity node for every function call. In case the type-id is a class-type, the name is resolved to a constructor. When it is a cv-qualified class-type, then it is not. Also, in case the typedef is resolved to the constructor we loose information that is valuable for refactoring (see bug 241717).

--> Let's not resolve the type-id to a constructor, rather than that genereate an implicit name for it.
* We fail to compute the correct expression type:
    struct S {};

    void test() {
       func(const S
(3) As Doug figured out, the name is resolved to the constructor, therefore we
    loose the information about the typedef that is used to name the
class-type.

==> To solve the issue we probably have to resolve the name to the typedef (or
class-type in other cases). For the constructor we'd have to introduce an
implicit name.
Comment 5 CDT Genie CLA 2011-09-28 11:23:10 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 350345: Resolving explicit type conversions

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=645d8be5c61150069897447aafdf1a611e9c4e9a
Comment 6 Markus Schorn CLA 2011-09-29 02:14:16 EDT
Different fix in 8.0.2.