1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 45203. Fixed a bug and added test for function calls with reference

parameters.
This commit is contained in:
Sergey Prigogin 2013-08-06 15:26:49 -07:00
parent d9d69d49a2
commit d27cdd90ca
2 changed files with 20 additions and 3 deletions

View file

@ -216,6 +216,20 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
assertDeclared("f"); assertDeclared("f");
} }
// class A {};
// void f(const A& p);
// A& g();
// void test() {
// f(g());
// }
public void testFunctionCallWithReferenceParameter() throws Exception {
IPreferenceStore preferenceStore = getPreferenceStore();
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
assertDefined();
assertDeclared("f", "g");
}
// struct A { // struct A {
// A(const char* s); // A(const char* s);
// }; // };

View file

@ -165,16 +165,18 @@ public class BindingClassifier {
IParameter[] parameters = function.getParameters(); IParameter[] parameters = function.getParameters();
for (int i = 0; i < parameters.length && i < arguments.length; i++) { for (int i = 0; i < parameters.length && i < arguments.length; i++) {
IType parameterType = parameters[i].getType(); IType parameterType = parameters[i].getType();
parameterType = getNestedType(parameterType, REF | ALLCVQ);
IASTInitializerClause argument = arguments[i]; IASTInitializerClause argument = arguments[i];
if (parameterType instanceof IPointerType || parameterType instanceof ICPPReferenceType) { if (parameterType instanceof IPointerType || parameterType instanceof ICPPReferenceType) {
// The declared parameter type is a pointer or reference type. A declaration is // The declared parameter type is a pointer or reference type. A declaration is
// sufficient if it matches the actual parameter type. // sufficient if it matches the actual parameter type. We don't need to provide
// a parameter declaration since it is a responsibility of the header declaring
// the function.
if (argument instanceof IASTExpression) { if (argument instanceof IASTExpression) {
IType argumentType = ((IASTExpression) argument).getExpressionType(); IType argumentType = ((IASTExpression) argument).getExpressionType();
if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) { if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) {
continue; continue;
} }
parameterType = getNestedType(parameterType, REF | ALLCVQ);
argumentType = getNestedType(argumentType, REF | ALLCVQ); argumentType = getNestedType(argumentType, REF | ALLCVQ);
if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) { if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) {
@ -194,6 +196,7 @@ public class BindingClassifier {
} }
// As a matter of policy, a header declaring the function is responsible for // As a matter of policy, a header declaring the function is responsible for
// defining parameter types that allow implicit conversion. // defining parameter types that allow implicit conversion.
parameterType = getNestedType(parameterType, REF | ALLCVQ);
if (!(parameterType instanceof ICPPClassType) || if (!(parameterType instanceof ICPPClassType) ||
fAst.getDeclarationsInAST(function).length != 0 || fAst.getDeclarationsInAST(function).length != 0 ||
!hasConvertingConstructor((ICPPClassType) parameterType, argument)) { !hasConvertingConstructor((ICPPClassType) parameterType, argument)) {
@ -430,7 +433,7 @@ public class BindingClassifier {
return; return;
if (fAst.getDefinitionsInAST(binding).length != 0) if (fAst.getDefinitionsInAST(binding).length != 0)
return; // Defined locally return; // Defined locally.
List<IBinding> requiredBindings = getRequiredBindings(binding); List<IBinding> requiredBindings = getRequiredBindings(binding);
for (IBinding requiredBinding : requiredBindings) { for (IBinding requiredBinding : requiredBindings) {