mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 45203. Don't forward declare types of function parameters since
the header containing the function declaration must declare them.
This commit is contained in:
parent
9d234dcfce
commit
d9d69d49a2
2 changed files with 33 additions and 50 deletions
|
@ -189,9 +189,10 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
|
|
||||||
// class A {};
|
// class A {};
|
||||||
// void f(const A* p);
|
// void f(const A* p);
|
||||||
|
// A* g();
|
||||||
|
|
||||||
// void test(A* a) {
|
// void test() {
|
||||||
// f(a);
|
// f(g());
|
||||||
// f(0);
|
// f(0);
|
||||||
// f(nullptr);
|
// f(nullptr);
|
||||||
// }
|
// }
|
||||||
|
@ -199,7 +200,7 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
IPreferenceStore preferenceStore = getPreferenceStore();
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
|
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
|
||||||
assertDefined();
|
assertDefined();
|
||||||
assertDeclared("f", "A");
|
assertDeclared("f", "g");
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedef int A;
|
// typedef int A;
|
||||||
|
|
|
@ -163,59 +163,41 @@ public class BindingClassifier {
|
||||||
*/
|
*/
|
||||||
private void processFunctionParameters(IFunction function, IASTInitializerClause[] arguments) {
|
private void processFunctionParameters(IFunction function, IASTInitializerClause[] arguments) {
|
||||||
IParameter[] parameters = function.getParameters();
|
IParameter[] parameters = function.getParameters();
|
||||||
for (int i = 0; i < parameters.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);
|
parameterType = getNestedType(parameterType, REF | ALLCVQ);
|
||||||
IASTInitializerClause argument = null;
|
IASTInitializerClause argument = arguments[i];
|
||||||
boolean canBeDeclared = false;
|
if (parameterType instanceof IPointerType || parameterType instanceof ICPPReferenceType) {
|
||||||
if (i >= arguments.length) {
|
// The declared parameter type is a pointer or reference type. A declaration is
|
||||||
// This is a default value parameter. The function call itself doesn't need
|
// sufficient if it matches the actual parameter type.
|
||||||
// a definition of this parameter type.
|
if (argument instanceof IASTExpression) {
|
||||||
canBeDeclared = true;
|
IType argumentType = ((IASTExpression) argument).getExpressionType();
|
||||||
} else {
|
if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) {
|
||||||
// This argument is present within the function call expression.
|
continue;
|
||||||
// It's therefore not a default parameter.
|
}
|
||||||
argument = arguments[i];
|
argumentType = getNestedType(argumentType, REF | ALLCVQ);
|
||||||
if (parameterType instanceof IPointerType || parameterType instanceof ICPPReferenceType) {
|
|
||||||
// The declared parameter type is a pointer or reference type. A declaration is
|
|
||||||
// sufficient if it matches the actual parameter type.
|
|
||||||
if (argument instanceof IASTExpression) {
|
|
||||||
IType argumentType = ((IASTExpression) argument).getExpressionType();
|
|
||||||
if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) {
|
|
||||||
canBeDeclared = true;
|
|
||||||
} else {
|
|
||||||
argumentType = getNestedType(argumentType, REF | ALLCVQ);
|
|
||||||
|
|
||||||
if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) {
|
if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) {
|
||||||
parameterType = getNestedType(((IPointerType) parameterType).getType(), ALLCVQ);
|
parameterType = getNestedType(((IPointerType) parameterType).getType(), ALLCVQ);
|
||||||
argumentType = getNestedType(((IPointerType) argumentType).getType(), ALLCVQ);
|
argumentType = getNestedType(((IPointerType) argumentType).getType(), ALLCVQ);
|
||||||
}
|
}
|
||||||
if (isSameType(parameterType, argumentType)) {
|
if (isSameType(parameterType, argumentType)) {
|
||||||
canBeDeclared = true;
|
continue;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canBeDeclared) {
|
if (argument instanceof IASTExpression) {
|
||||||
// The declared parameter type must be declared. We must explicitly do this here
|
IType argumentType = ((IASTExpression) argument).getExpressionType();
|
||||||
// because this type doesn't appear within the AST.
|
// The type of the argument requires a full definition.
|
||||||
declareTypeExceptTypedefOrNonFixedEnum(parameterType);
|
defineTypeExceptTypedefOrNonFixedEnum(argumentType);
|
||||||
} else {
|
}
|
||||||
assert argument != null;
|
// As a matter of policy, a header declaring the function is responsible for
|
||||||
if (argument instanceof IASTExpression) {
|
// defining parameter types that allow implicit conversion.
|
||||||
IType argumentType = ((IASTExpression) argument).getExpressionType();
|
if (!(parameterType instanceof ICPPClassType) ||
|
||||||
// The type of the argument requires a full definition.
|
fAst.getDeclarationsInAST(function).length != 0 ||
|
||||||
defineTypeExceptTypedefOrNonFixedEnum(argumentType);
|
!hasConvertingConstructor((ICPPClassType) parameterType, argument)) {
|
||||||
}
|
defineTypeExceptTypedefOrNonFixedEnum(parameterType);
|
||||||
// As a matter of policy, a header declaring the function is responsible for
|
|
||||||
// defining parameter types that allow implicit conversion.
|
|
||||||
if (!(parameterType instanceof ICPPClassType) ||
|
|
||||||
fAst.getDeclarationsInAST(function).length != 0 ||
|
|
||||||
!hasConvertingConstructor((ICPPClassType) parameterType, argument)) {
|
|
||||||
defineTypeExceptTypedefOrNonFixedEnum(parameterType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue