mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Adjustment of parameter types, bug 239975.
This commit is contained in:
parent
0b6a51224f
commit
eba71c1297
5 changed files with 74 additions and 40 deletions
|
@ -3943,7 +3943,8 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
// int f (int) { } // definition of f(int)
|
// int f (int) { } // definition of f(int)
|
||||||
// int f (cInt) { } // error: redefinition of f(int)
|
// int f (cInt) { } // error: redefinition of f(int)
|
||||||
public void test12_8s3e() throws Exception {
|
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);
|
// void f (int i, int j);
|
||||||
|
|
|
@ -5938,4 +5938,19 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -847,4 +847,21 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
|
||||||
assertTrue(bar_c_ft.isConst()); assertTrue(!bar_c_ft.isVolatile());
|
assertTrue(bar_c_ft.isConst()); assertTrue(!bar_c_ft.isVolatile());
|
||||||
assertTrue(!bar_ft.isConst()); assertTrue(!bar_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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1927,14 +1927,16 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
|
|
||||||
static private IType[] getTargetParameterTypes(IFunction fn) throws DOMException{
|
static private IType[] getTargetParameterTypes(IFunction fn) throws DOMException{
|
||||||
IParameter[] params = fn.getParameters();
|
final ICPPFunctionType ftype = (ICPPFunctionType) fn.getType();
|
||||||
|
if (ftype == null)
|
||||||
|
return IType.EMPTY_TYPE_ARRAY;
|
||||||
|
|
||||||
boolean useImplicit = (fn instanceof ICPPMethod && !(fn instanceof ICPPConstructor));
|
final IType[] ptypes= ftype.getParameterTypes();
|
||||||
IType[] result = new IType[useImplicit ? params.length + 1 : params.length];
|
if (fn instanceof ICPPMethod == false || fn instanceof ICPPConstructor)
|
||||||
|
return ptypes;
|
||||||
|
|
||||||
if (useImplicit) {
|
final IType[] result = new IType[ptypes.length + 1];
|
||||||
ICPPFunctionType ftype = (ICPPFunctionType) ((ICPPFunction)fn).getType();
|
System.arraycopy(ptypes, 0, result, 1, ptypes.length);
|
||||||
if (ftype != null) {
|
|
||||||
IScope scope = fn.getScope();
|
IScope scope = fn.getScope();
|
||||||
if (scope instanceof ICPPTemplateScope)
|
if (scope instanceof ICPPTemplateScope)
|
||||||
scope = scope.getParent();
|
scope = scope.getParent();
|
||||||
|
@ -1953,14 +1955,7 @@ public class CPPSemantics {
|
||||||
if (ftype.isConst() || ftype.isVolatile()) {
|
if (ftype.isConst() || ftype.isVolatile()) {
|
||||||
implicitType = new CPPQualifierType(implicitType, ftype.isConst(), ftype.isVolatile());
|
implicitType = new CPPQualifierType(implicitType, ftype.isConst(), ftype.isVolatile());
|
||||||
}
|
}
|
||||||
implicitType = new CPPReferenceType(implicitType);
|
result[0]= new CPPReferenceType(implicitType);
|
||||||
|
|
||||||
result[0] = implicitType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (IParameter param : params)
|
|
||||||
result = (IType[]) ArrayUtil.append(IType.class, result, param.getType());
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1510,27 +1510,33 @@ public class CPPVisitor {
|
||||||
pt = createType(pDeclSpec);
|
pt = createType(pDeclSpec);
|
||||||
pt = createType(pt, pDtor);
|
pt = createType(pt, pDtor);
|
||||||
|
|
||||||
|
// bug 239975
|
||||||
|
IType noTypedef= SemanticUtil.getUltimateTypeViaTypedefs(pt);
|
||||||
|
|
||||||
//8.3.5-3
|
//8.3.5-3
|
||||||
//Any cv-qualifier modifying a parameter type is deleted.
|
//Any cv-qualifier modifying a parameter type is deleted.
|
||||||
//so only create the base type from the declspec and not the qualifiers
|
//so only create the base type from the declspec and not the qualifiers
|
||||||
try {
|
try {
|
||||||
if (pt instanceof IQualifierType) {
|
if (noTypedef instanceof IQualifierType) {
|
||||||
pt= ((IQualifierType) pt).getType();
|
pt= ((IQualifierType) noTypedef).getType();
|
||||||
|
noTypedef= SemanticUtil.getUltimateTypeViaTypedefs(pt);
|
||||||
}
|
}
|
||||||
if (pt instanceof CPPPointerType) {
|
if (noTypedef instanceof CPPPointerType) {
|
||||||
pt= ((CPPPointerType) pt).stripQualifiers();
|
pt= ((CPPPointerType) noTypedef).stripQualifiers();
|
||||||
|
noTypedef= SemanticUtil.getUltimateTypeViaTypedefs(pt);
|
||||||
}
|
}
|
||||||
//any parameter of type array of T is adjusted to be pointer to T
|
//any parameter of type array of T is adjusted to be pointer to T
|
||||||
if (pt instanceof IArrayType) {
|
if (noTypedef instanceof IArrayType) {
|
||||||
IArrayType at = (IArrayType) pt;
|
IArrayType at = (IArrayType) noTypedef;
|
||||||
pt = new CPPPointerType(at.getType());
|
pt = new CPPPointerType(at.getType());
|
||||||
|
noTypedef= SemanticUtil.getUltimateTypeViaTypedefs(pt);
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
pt = e.getProblem();
|
pt = e.getProblem();
|
||||||
}
|
}
|
||||||
|
|
||||||
//any parameter to type function returning T is adjusted to be pointer to function
|
//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);
|
pt = new CPPPointerType(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue