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

Test case for bug 259872.

This commit is contained in:
Sergey Prigogin 2009-01-03 03:25:54 +00:00
parent f9c0ac30d7
commit a27a1df93d
6 changed files with 69 additions and 33 deletions

View file

@ -3552,4 +3552,26 @@ public class AST2TemplateTests extends AST2BaseTest {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
bh.assertNonProblem("func(p)", 4, ICPPFunction.class);
}
// template <typename CL, typename T>
// struct A {
// template<typename U> struct C {
// typedef T (U::*method1)() const;
// };
// typedef typename C<CL>::method1 method2;
//
// A(method2 p);
// };
//
// struct B {
// int m() const;
//
// void test() {
// new A<B, int>(&B::m);
// }
// };
public void _testNestedTemplates_259872() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
bh.assertNonProblem("A<B, int>", 9, ICPPConstructor.class);
}
}

View file

@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IType;
@ -22,9 +23,9 @@ import org.eclipse.cdt.internal.core.index.IIndexType;
* @author aniefer
*/
public class CPPQualifierType implements IQualifierType, ITypeContainer {
private boolean isConst = false;
private boolean isVolatile = false;
private IType type = null;
private final boolean isConst;
private final boolean isVolatile;
private IType type;
public CPPQualifierType(IType type, boolean isConst, boolean isVolatile) {
this.type = type;
@ -82,4 +83,9 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer {
}
return t;
}
@Override
public String toString() {
return ASTTypeUtil.getType(this);
}
}

View file

@ -90,8 +90,8 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownCla
return type.isSameType(this);
if (type instanceof ICPPUnknownClassType
&& type instanceof ICPPUnknownClassInstance == false
&& type instanceof ICPPDeferredClassInstance == false) {
&& !(type instanceof ICPPUnknownClassInstance)
&& !(type instanceof ICPPDeferredClassInstance)) {
ICPPUnknownClassType rhs= (ICPPUnknownClassType) type;
if (CharArrayUtils.equals(getNameCharArray(), rhs.getNameCharArray())) {
try {

View file

@ -314,11 +314,12 @@ public class CPPSemantics {
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
ICPPTemplateArgument[] args = CPPTemplates.createTemplateArgumentArray(id);
IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args);
cls = inst instanceof ICPPClassType && !(inst instanceof ICPPDeferredClassInstance) ? (ICPPClassType)inst : cls;
cls = inst instanceof ICPPClassType && !(inst instanceof ICPPDeferredClassInstance) ?
(ICPPClassType) inst : cls;
}
}
if (cls != null) {
//force resolution of constructor bindings
// Force resolution of constructor bindings
IBinding[] ctors = cls.getConstructors();
if (ctors.length > 0 && !(ctors[0] instanceof IProblemBinding)) {
// then use the class scope to resolve which one.
@ -2109,7 +2110,8 @@ public class CPPSemantics {
}
if (isImpliedObject && ASTInternal.isStatic(currFn, false)) {
// 13.3.1-4 for static member functions, the implicit object parameter is considered to match any object
// 13.3.1-4 for static member functions, the implicit object parameter is
// considered to match any object
cost = new Cost(source, target);
cost.rank = Cost.IDENTITY_RANK; // exact match, no cost
} else if (source == null) {
@ -2121,7 +2123,8 @@ public class CPPSemantics {
cost = new Cost(source, target);
cost.rank = Cost.IDENTITY_RANK; // exact match, no cost
} else {
cost= Conversions.checkImplicitConversionSequence(!data.forUserDefinedConversion, sourceExp, source, target, isImpliedObject);
cost= Conversions.checkImplicitConversionSequence(!data.forUserDefinedConversion,
sourceExp, source, target, isImpliedObject);
}
currFnCost[j] = cost;

View file

@ -562,7 +562,8 @@ public class Conversions {
boolean canConvert = true;
int requiredConversion = Cost.IDENTITY_RANK;
IType s = cost.source, t = cost.target;
IType s = cost.source;
IType t = cost.target;
boolean constInEveryCV2k = true;
boolean firstPointer= true;
while (true) {
@ -743,7 +744,8 @@ public class Conversions {
IType sPrev= sHolder[0], tPrev= tHolder[0];
if (src instanceof CPPBasicType && trg instanceof IPointerType) {
//4.10-1 an integral constant expression of integer type that evaluates to 0 can be converted to a pointer type
// 4.10-1 an integral constant expression of integer type that evaluates to 0 can
// be converted to a pointer type
IASTExpression exp = ((CPPBasicType) src).getCreatedFromExpression();
if (exp != null) {
Long val= Value.create(exp, Value.MAX_RECURSION_DEPTH).numericalValue();
@ -755,7 +757,8 @@ public class Conversions {
} else if (sPrev instanceof IPointerType) {
//4.10-2 an rvalue of type "pointer to cv T", where T is an object type can be
//converted to an rvalue of type "pointer to cv void"
if (tPrev instanceof IPointerType && t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_void) {
if (tPrev instanceof IPointerType && t instanceof IBasicType &&
((IBasicType)t).getType() == IBasicType.t_void) {
cost.rank = Cost.CONVERSION_RANK;
cost.conversion = 1;
cost.detail = 2;
@ -781,7 +784,8 @@ public class Conversions {
//An rvalue of an enumeration type can be converted to an rvalue of an integer type.
cost.rank = Cost.CONVERSION_RANK;
cost.conversion = 1;
} else if (trg instanceof IBasicType && ((IBasicType)trg).getType() == ICPPBasicType.t_bool && s instanceof IPointerType) {
} else if (trg instanceof IBasicType && ((IBasicType)trg).getType() == ICPPBasicType.t_bool &&
s instanceof IPointerType) {
//4.12 pointer or pointer to member type can be converted to an rvalue of type bool
cost.rank = Cost.CONVERSION_RANK;
cost.conversion = 1;
@ -794,7 +798,8 @@ public class Conversions {
IType st = spm.getType();
IType tt = tpm.getType();
if (st != null && tt != null && st.isSameType(tt)) {
int depth= calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, tpm.getMemberOfClass(), spm.getMemberOfClass());
int depth= calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH,
tpm.getMemberOfClass(), spm.getMemberOfClass());
cost.rank= (depth > -1) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK;
cost.conversion= (depth > -1) ? depth : 0;
cost.detail= 1;