Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Ctor name in a ctor call expression gets resolved to CPPClassType instead of CPPConstructor

Found an explanation why the ctor call _expression_ was resolved to the type instead of the ctor. It is in https://bugs.eclipse.org/bugs/show_bug.cgi?id=241717#c9. Markus wrote there:
Hmm, there are a couple of aspects to this problem:
(1) The refactoring cannot rely on IASTExpression.getType() to deliver a typedef
    in all cases where this may be expected. Where possible the typedef is
    returned, though.
    Example:
      typedef const int CINT;
      int x= CINT(1);   // _expression_ type of 'CINT(1)' is 'int', not 'CINT'.

(2) In the specific example the parser models what is acutally an explicit type
    conversion in functional notation as a function call. This is wrong but 
    convenient as otherwise we'd have to create an ambiguity node for every 
    function call.
(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.
Unfortunately resolving ctor call _expression_ to ctor breaks ExtractFunctionRefactoringTest.testTypedef_Bug241717.

One option is to give up on the idea to resolving "A" in "A(1)" to the ctor and rely on the binding associated with the implicit name for resolving bug 393068. This approach doesn't address bug 393084. Another option is flip the roles of the explicit and the implicit names and to resolve the implicit name to the type. Please let me know your opinion. 

-sergey


On Tue, Oct 30, 2012 at 2:36 PM, Sergey Prigogin <eclipse.sprigogin@xxxxxxxxx> wrote:
I've also discovered the convertClassToContructor method. I've tried to change it and encountered a half dosen broken tests. Will investigate the breakages.

-sergey


On Tue, Oct 30, 2012 at 9:34 AM, Schorn, Markus <Markus.Schorn@xxxxxxxxxxxxx> wrote:

Hi Sergey,

Primarily the name is resolved to the class-type, however in CPPSemantics.postResolution() an attempt is made to replace the class-type with a constructor where this is feasible.

It looks like the check whether the replacement shall  be made or not is incomplete. (this is done in method convertClassToContructor(IASTName)).

 

Note: By the c++ standard, ‘C(1)’ is actually an explicit type conversion in functional notation (5.2.3). In CDT we model it as a function call _expression_. (By doing that we avoid performing an ambiguity resolution on each and every function call.)

Markus.

 

 

 

From: sprigogin@xxxxxxxxxx [mailto:sprigogin@xxxxxxxxxx] On Behalf Of Sergey Prigogin
Sent: Monday, October 29, 2012 7:23 PM
To: Schorn, Markus


Cc: CDT General developers list.
Subject: Ctor name in a ctor call _expression_ gets resolved to CPPClassType instead of CPPConstructor

 

I've noticed that a constructor name in a constructor call _expression_ gets resolved to CPPClassType instead of CPPConstructor. In the following code select "A" in "A(1)". Notice that "A" gets highlighted in the first and the fourth lines, but not in the second line (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=393084).
 
struct A {
  A(int x);
};
 
A a = A(1);
 
This may seem like a minor annoyance, but it causes bug 393068.
 
Is it the expected behavior? If so, how to get the constructor being called?
-sergey



Back to the top