mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 08:45:44 +02:00
Bug 489710 - Name resolution problem with inherited constructor
Change-Id: Ic2a090a79e9d4414217e5f8f15ee70a64bb77885
This commit is contained in:
parent
a29e37cffc
commit
31e3379235
2 changed files with 75 additions and 5 deletions
|
@ -4390,6 +4390,66 @@ public class AST2TemplateTests extends AST2TestBase {
|
|||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// template<typename... Ts>
|
||||
// struct E {};
|
||||
//
|
||||
// template<int I, typename T>
|
||||
// struct D;
|
||||
//
|
||||
// template<int I, typename T, typename... Us>
|
||||
// struct D<I, E<T, Us...>> : D<I - 1, E<Us...>> {};
|
||||
//
|
||||
// template<typename T, typename... Us>
|
||||
// struct D<0, E<T, Us...>> {
|
||||
// typedef T type;
|
||||
// };
|
||||
//
|
||||
// template <typename... Ts>
|
||||
// class A;
|
||||
//
|
||||
// template <typename T>
|
||||
// struct F {
|
||||
// using type = T;
|
||||
// };
|
||||
//
|
||||
// template <int N, typename T>
|
||||
// struct C;
|
||||
//
|
||||
// template <int N, typename... Ts>
|
||||
// struct C<N, A<Ts...>> {
|
||||
// using type = typename D<N, E<F<Ts>...>>::type::type;
|
||||
// };
|
||||
//
|
||||
// template <int I, typename T>
|
||||
// struct B : public B<I - 1, T> {
|
||||
// using U = typename C<I, T>::type;
|
||||
// using Base = B<I - 1, T>;
|
||||
// using Base::Base;
|
||||
//
|
||||
// B(const U& value);
|
||||
// };
|
||||
//
|
||||
// template <typename... Ts>
|
||||
// struct B<-1, A<Ts...>> {};
|
||||
//
|
||||
// template <typename... Ts>
|
||||
// struct A : public B<sizeof...(Ts) - 1, A<Ts...>> {
|
||||
// using B = B<sizeof...(Ts) - 1, A>;
|
||||
// using B::B;
|
||||
// };
|
||||
//
|
||||
// struct X {};
|
||||
// struct Y {};
|
||||
//
|
||||
// void waldo(const A<X, Y>& p);
|
||||
//
|
||||
// void test() {
|
||||
// waldo(X());
|
||||
// waldo(Y());
|
||||
// }
|
||||
public void testInheritedConstructor_489710() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// template <typename T>
|
||||
// struct A {
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
|
@ -155,8 +156,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
}
|
||||
}
|
||||
|
||||
private ICPPBase[] findInheritedConstructorsSourceBases(
|
||||
ICPPASTCompositeTypeSpecifier compositeTypeSpec) {
|
||||
private ICPPBase[] findInheritedConstructorsSourceBases(ICPPASTCompositeTypeSpecifier compositeTypeSpec) {
|
||||
ICPPBase[] bases = ClassTypeHelper.getBases(getClassType(), compositeTypeSpec);
|
||||
if (bases.length == 0)
|
||||
return bases;
|
||||
|
@ -173,9 +173,8 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
IBinding parent = qualifier[qualifier.length - 1].resolveBinding();
|
||||
if (!(parent instanceof IType) || parent instanceof IProblemBinding)
|
||||
continue;
|
||||
IType type = SemanticUtil.getNestedType((IType) parent, TDEF);
|
||||
if (type instanceof IBinding &&
|
||||
Arrays.equals(((IBinding) type).getNameCharArray(), qName.getLastName().getSimpleID())) {
|
||||
if (isConstructorNameForType(qName.getLastName().getSimpleID(), (IType) parent)) {
|
||||
IType type = SemanticUtil.getNestedType((IType) parent, TDEF);
|
||||
for (ICPPBase base : bases) {
|
||||
IType baseClass = base.getBaseClassType();
|
||||
if (type.isSameType(baseClass)) {
|
||||
|
@ -189,6 +188,17 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
return trim(results, n);
|
||||
}
|
||||
|
||||
private static boolean isConstructorNameForType(char[] lastName, IType type) {
|
||||
while (type instanceof IBinding) {
|
||||
if (Arrays.equals(((IBinding) type).getNameCharArray(), lastName))
|
||||
return true;
|
||||
if (!(type instanceof ITypedef))
|
||||
break;
|
||||
type = ((ITypedef) type).getType();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static ICPPMethod[] createInheritedConsructors(ICPPClassScope scope, char[] className,
|
||||
ICPPBase[] bases, IType[][] existingConstructorParamTypes, IASTNode point) {
|
||||
ICPPMethod[] inheritedConstructors = ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
|
||||
|
|
Loading…
Add table
Reference in a new issue