mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Bug 45203. Added a test.
This commit is contained in:
parent
a9914d3620
commit
44dab709d9
2 changed files with 41 additions and 29 deletions
|
@ -208,13 +208,31 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
// void test() {
|
// void test() {
|
||||||
// f("");
|
// f("");
|
||||||
// }
|
// }
|
||||||
public void testFunctionCallWithTypeConversion() throws Exception {
|
public void testFunctionCallWithTypeConversion_1() throws Exception {
|
||||||
IPreferenceStore preferenceStore = getPreferenceStore();
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
|
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
|
||||||
|
// A header declaring the function is responsible for defining the parameter type that
|
||||||
|
// provides constructor that can be used for implicit conversion.
|
||||||
assertDefined();
|
assertDefined();
|
||||||
assertDeclared("f");
|
assertDeclared("f");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct A {};
|
||||||
|
// struct B { operator A(); };
|
||||||
|
// void f(A p);
|
||||||
|
|
||||||
|
// void test(B b) {
|
||||||
|
// f(b);
|
||||||
|
// }
|
||||||
|
public void testFunctionCallWithTypeConversion_2() throws Exception {
|
||||||
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
|
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
|
||||||
|
// A header declaring the function is not responsible for defining the parameter type since
|
||||||
|
// the implicit conversion from B to A is provided externally to parameter type.
|
||||||
|
assertDefined("A", "B");
|
||||||
|
assertDeclared("f");
|
||||||
|
}
|
||||||
|
|
||||||
// struct A {};
|
// struct A {};
|
||||||
// struct B {};
|
// struct B {};
|
||||||
|
|
||||||
|
|
|
@ -162,18 +162,22 @@ public class BindingClassifier {
|
||||||
IParameter[] parameters = function.getParameters();
|
IParameter[] parameters = function.getParameters();
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
IType parameterType = parameters[i].getType();
|
IType parameterType = parameters[i].getType();
|
||||||
IType argumentType = null;
|
parameterType = getNestedType(parameterType, REF | ALLCVQ);
|
||||||
|
IASTInitializerClause argument = null;
|
||||||
boolean canBeDeclared = false;
|
boolean canBeDeclared = false;
|
||||||
|
if (i >= arguments.length) {
|
||||||
|
// This is a default value parameter. The function call itself doesn't need
|
||||||
|
// a definition of this parameter type.
|
||||||
|
canBeDeclared = true;
|
||||||
|
} else {
|
||||||
|
// This argument is present within the function call expression.
|
||||||
|
// It's therefore not a default parameter.
|
||||||
|
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.
|
||||||
parameterType = getNestedType(parameterType, REF | ALLCVQ);
|
|
||||||
if (i < arguments.length) {
|
|
||||||
// This argument is present within the function call expression.
|
|
||||||
// It's therefore not a default parameter.
|
|
||||||
IASTInitializerClause argument = arguments[i];
|
|
||||||
if (argument instanceof IASTExpression) {
|
if (argument instanceof IASTExpression) {
|
||||||
argumentType = ((IASTExpression) argument).getExpressionType();
|
IType argumentType = ((IASTExpression) argument).getExpressionType();
|
||||||
argumentType = getNestedType(argumentType, REF | ALLCVQ);
|
argumentType = getNestedType(argumentType, REF | ALLCVQ);
|
||||||
|
|
||||||
if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) {
|
if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) {
|
||||||
|
@ -184,10 +188,6 @@ public class BindingClassifier {
|
||||||
canBeDeclared = true;
|
canBeDeclared = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// This is a default value parameter. The function call itself doesn't need
|
|
||||||
// a definition of this parameter type.
|
|
||||||
canBeDeclared = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,23 +196,17 @@ public class BindingClassifier {
|
||||||
// because this type doesn't appear within the AST.
|
// because this type doesn't appear within the AST.
|
||||||
declareType(parameterType);
|
declareType(parameterType);
|
||||||
} else {
|
} else {
|
||||||
parameterType = getNestedType(parameterType, REF | ALLCVQ);
|
assert argument != null;
|
||||||
if (i < arguments.length) {
|
|
||||||
// This argument is present within the function call expression.
|
|
||||||
// It's therefore not a default parameter.
|
|
||||||
IASTInitializerClause argument = arguments[i];
|
|
||||||
if (argument instanceof IASTExpression) {
|
if (argument instanceof IASTExpression) {
|
||||||
argumentType = ((IASTExpression) argument).getExpressionType();
|
IType argumentType = ((IASTExpression) argument).getExpressionType();
|
||||||
// The type of the argument requires a full definition.
|
// The type of the argument requires a full definition.
|
||||||
defineTypeExceptTypedefOrNonFixedEnum(argumentType);
|
defineTypeExceptTypedefOrNonFixedEnum(argumentType);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 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.
|
||||||
if (i >= arguments.length ||
|
if (!(parameterType instanceof ICPPClassType) ||
|
||||||
!(parameterType instanceof ICPPClassType) ||
|
|
||||||
fAst.getDeclarationsInAST(function).length != 0 ||
|
fAst.getDeclarationsInAST(function).length != 0 ||
|
||||||
!hasConvertingConstructor((ICPPClassType) parameterType, arguments[i])) {
|
!hasConvertingConstructor((ICPPClassType) parameterType, argument)) {
|
||||||
defineTypeExceptTypedefOrNonFixedEnum(parameterType);
|
defineTypeExceptTypedefOrNonFixedEnum(parameterType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,7 +230,7 @@ public class BindingClassifier {
|
||||||
lookupData.qualified = true;
|
lookupData.qualified = true;
|
||||||
try {
|
try {
|
||||||
IBinding constructor = CPPSemantics.resolveFunction(lookupData, ClassTypeHelper.getConstructors(classType, argument), false);
|
IBinding constructor = CPPSemantics.resolveFunction(lookupData, ClassTypeHelper.getConstructors(classType, argument), false);
|
||||||
if (constructor instanceof ICPPConstructor)
|
if (constructor instanceof ICPPConstructor && !((ICPPConstructor) constructor).isExplicit())
|
||||||
return true;
|
return true;
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue