1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Adjustment of parameter types, bug 239975.

This commit is contained in:
Markus Schorn 2008-07-09 09:13:48 +00:00
parent 0b6a51224f
commit eba71c1297
5 changed files with 74 additions and 40 deletions

View file

@ -3943,7 +3943,8 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// int f (int) { } // definition of f(int)
// int f (cInt) { } // error: redefinition of f(int)
public void test12_8s3e() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
String[] problems= {"f"};
parse(getAboveComment(), ParserLanguage.CPP, problems);
}
// void f (int i, int j);

View file

@ -5938,4 +5938,19 @@ public class AST2CPPTests extends AST2BaseTest {
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
}
// typedef char t[12];
// void test1(char *);
// void test2(char []);
// void test3(t);
// void xx() {
// char* x= 0;
// test1(x);
// test2(x); // problem binding here
// test3(x); // problem binding here
// }
public void testAdjustmentOfParameterTypes_Bug239975() throws Exception {
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
}
}

View file

@ -847,4 +847,21 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
assertTrue(bar_c_ft.isConst()); assertTrue(!bar_c_ft.isVolatile());
assertTrue(!bar_ft.isConst()); assertTrue(!bar_ft.isVolatile());
}
// typedef char t[12];
// void test1(char *);
// void test2(char []);
// void test3(t);
// void xx() {
// char* x= 0;
// test1(x);
// test2(x); // problem binding here
// test3(x); // problem binding here
// }
public void testAdjustmentOfParameterTypes_Bug239975() throws Exception {
getBindingFromASTName("test1(x)", 5, ICPPFunction.class);
getBindingFromASTName("test2(x)", 5, ICPPFunction.class);
getBindingFromASTName("test3(x)", 5, ICPPFunction.class);
}
}

View file

@ -1927,40 +1927,35 @@ public class CPPSemantics {
}
static private IType[] getTargetParameterTypes(IFunction fn) throws DOMException{
IParameter[] params = fn.getParameters();
boolean useImplicit = (fn instanceof ICPPMethod && !(fn instanceof ICPPConstructor));
IType[] result = new IType[useImplicit ? params.length + 1 : params.length];
final ICPPFunctionType ftype = (ICPPFunctionType) fn.getType();
if (ftype == null)
return IType.EMPTY_TYPE_ARRAY;
if (useImplicit) {
ICPPFunctionType ftype = (ICPPFunctionType) ((ICPPFunction)fn).getType();
if (ftype != null) {
IScope scope = fn.getScope();
if (scope instanceof ICPPTemplateScope)
scope = scope.getParent();
ICPPClassType cls = null;
if (scope instanceof ICPPClassScope) {
cls = ((ICPPClassScope)scope).getClassType();
} else {
cls = new CPPClassType.CPPClassTypeProblem(ASTInternal.getPhysicalNodeOfScope(scope), IProblemBinding.SEMANTIC_BAD_SCOPE, fn.getNameCharArray());
}
if (cls instanceof ICPPClassTemplate) {
IBinding within = CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) cls);
if (within instanceof ICPPClassType)
cls = (ICPPClassType)within;
}
IType implicitType = cls;
if (ftype.isConst() || ftype.isVolatile()) {
implicitType = new CPPQualifierType(implicitType, ftype.isConst(), ftype.isVolatile());
}
implicitType = new CPPReferenceType(implicitType);
result[0] = implicitType;
}
final IType[] ptypes= ftype.getParameterTypes();
if (fn instanceof ICPPMethod == false || fn instanceof ICPPConstructor)
return ptypes;
final IType[] result = new IType[ptypes.length + 1];
System.arraycopy(ptypes, 0, result, 1, ptypes.length);
IScope scope = fn.getScope();
if (scope instanceof ICPPTemplateScope)
scope = scope.getParent();
ICPPClassType cls = null;
if (scope instanceof ICPPClassScope) {
cls = ((ICPPClassScope)scope).getClassType();
} else {
cls = new CPPClassType.CPPClassTypeProblem(ASTInternal.getPhysicalNodeOfScope(scope), IProblemBinding.SEMANTIC_BAD_SCOPE, fn.getNameCharArray());
}
for (IParameter param : params)
result = (IType[]) ArrayUtil.append(IType.class, result, param.getType());
if (cls instanceof ICPPClassTemplate) {
IBinding within = CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) cls);
if (within instanceof ICPPClassType)
cls = (ICPPClassType)within;
}
IType implicitType = cls;
if (ftype.isConst() || ftype.isVolatile()) {
implicitType = new CPPQualifierType(implicitType, ftype.isConst(), ftype.isVolatile());
}
result[0]= new CPPReferenceType(implicitType);
return result;
}

View file

@ -1510,27 +1510,33 @@ public class CPPVisitor {
pt = createType(pDeclSpec);
pt = createType(pt, pDtor);
// bug 239975
IType noTypedef= SemanticUtil.getUltimateTypeViaTypedefs(pt);
//8.3.5-3
//Any cv-qualifier modifying a parameter type is deleted.
//so only create the base type from the declspec and not the qualifiers
try {
if (pt instanceof IQualifierType) {
pt= ((IQualifierType) pt).getType();
if (noTypedef instanceof IQualifierType) {
pt= ((IQualifierType) noTypedef).getType();
noTypedef= SemanticUtil.getUltimateTypeViaTypedefs(pt);
}
if (pt instanceof CPPPointerType) {
pt= ((CPPPointerType) pt).stripQualifiers();
if (noTypedef instanceof CPPPointerType) {
pt= ((CPPPointerType) noTypedef).stripQualifiers();
noTypedef= SemanticUtil.getUltimateTypeViaTypedefs(pt);
}
//any parameter of type array of T is adjusted to be pointer to T
if (pt instanceof IArrayType) {
IArrayType at = (IArrayType) pt;
if (noTypedef instanceof IArrayType) {
IArrayType at = (IArrayType) noTypedef;
pt = new CPPPointerType(at.getType());
noTypedef= SemanticUtil.getUltimateTypeViaTypedefs(pt);
}
} catch (DOMException e) {
pt = e.getProblem();
}
//any parameter to type function returning T is adjusted to be pointer to function
if (pt instanceof IFunctionType) {
if (noTypedef instanceof IFunctionType) {
pt = new CPPPointerType(pt);
}