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
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.