Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350345 - Invalid overload using typedef (address of overloaded function)
Summary: Invalid overload using typedef (address of overloaded function)
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.0.1   Edit
Assignee: Markus Schorn CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 241717
  Show dependency tree
 
Reported: 2011-06-25 03:06 EDT by Marc-André Laperle CLA
Modified: 2011-09-29 02:14 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.