mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 430230. More involved test case and a fix for the issues it
uncovered.
This commit is contained in:
parent
db4c3d2c3e
commit
450504e505
4 changed files with 73 additions and 23 deletions
|
@ -7430,7 +7430,57 @@ public class AST2TemplateTests extends AST2TestBase {
|
|||
// int waldo(int p);
|
||||
//
|
||||
// int x = waldo(test<A>(0));
|
||||
public void testSfinaeInNewExpression_430230() throws Exception {
|
||||
public void testSfinaeInNewExpression_430230a() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// template<bool __v>
|
||||
// struct bool_constant {
|
||||
// static constexpr bool value = __v;
|
||||
// };
|
||||
//
|
||||
// typedef bool_constant<true> true_type;
|
||||
// typedef bool_constant<false> false_type;
|
||||
//
|
||||
// struct B {
|
||||
// template<typename T, typename Arg, typename = decltype(::new T(Arg()))>
|
||||
// static true_type test(int);
|
||||
//
|
||||
// template<typename, typename>
|
||||
// static false_type test(...);
|
||||
// };
|
||||
//
|
||||
// template<typename T, typename Arg>
|
||||
// struct C : public B {
|
||||
// typedef decltype(test<T, Arg>(0)) type;
|
||||
// };
|
||||
//
|
||||
// template<typename T, typename Arg>
|
||||
// struct D : public C<T, Arg>::type {};
|
||||
//
|
||||
// template<typename T, typename Arg>
|
||||
// struct E : public bool_constant<D<T, Arg>::value> {};
|
||||
//
|
||||
// template<bool, typename T = void>
|
||||
// struct enable_if {};
|
||||
//
|
||||
// template<typename T>
|
||||
// struct enable_if<true, T> {
|
||||
// typedef T type;
|
||||
// };
|
||||
//
|
||||
// struct A {};
|
||||
//
|
||||
// template <class F>
|
||||
// typename enable_if<true>::type
|
||||
// waldo();
|
||||
//
|
||||
// template <class F>
|
||||
// typename enable_if<E<F, int>::value>::type
|
||||
// waldo();
|
||||
//
|
||||
// auto x = waldo<A>;
|
||||
public void testSfinaeInNewExpression_430230b() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
|
|
|
@ -73,4 +73,20 @@ public abstract class CPPEvaluation implements ICPPEvaluation {
|
|||
}
|
||||
return binding;
|
||||
}
|
||||
|
||||
public static boolean containsDependentType(ICPPEvaluation[] evaluations) {
|
||||
for (ICPPEvaluation eval : evaluations) {
|
||||
if (eval.isTypeDependent())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean containsDependentValue(ICPPEvaluation[] evaluations) {
|
||||
for (ICPPEvaluation eval : evaluations) {
|
||||
if (eval.isValueDependent())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -65,20 +65,12 @@ public class EvalComma extends CPPDependentEvaluation {
|
|||
if (fType != null)
|
||||
return fType instanceof TypeOfDependentExpression;
|
||||
|
||||
for (ICPPEvaluation arg : fArguments) {
|
||||
if (arg.isTypeDependent())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return containsDependentType(fArguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValueDependent() {
|
||||
for (ICPPEvaluation arg : fArguments) {
|
||||
if (arg.isValueDependent())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return containsDependentValue(fArguments);
|
||||
}
|
||||
|
||||
public ICPPFunction[] getOverloads(IASTNode point) {
|
||||
|
|
|
@ -93,7 +93,7 @@ public class EvalTypeId extends CPPDependentEvaluation {
|
|||
}
|
||||
|
||||
private IType computeType() {
|
||||
if (CPPTemplates.isDependentType(fInputType))
|
||||
if (CPPTemplates.isDependentType(fInputType) || containsDependentType(fArguments))
|
||||
return new TypeOfDependentExpression(this);
|
||||
|
||||
IType type = typeFromReturnType(fInputType);
|
||||
|
@ -186,14 +186,14 @@ public class EvalTypeId extends CPPDependentEvaluation {
|
|||
if (args == fArguments && type == fInputType)
|
||||
return this;
|
||||
|
||||
if (!CPPTemplates.isDependentType(type) && !areArgumentTypesDependent() && type instanceof ICPPClassType) {
|
||||
if (!CPPTemplates.isDependentType(type) && !containsDependentType(args) && type instanceof ICPPClassType) {
|
||||
// Check the constructor call and return EvalFixed.INCOMPLETE to indicate a substitution
|
||||
// failure if the call cannot be resolved.
|
||||
ICPPClassType classType = (ICPPClassType) type;
|
||||
LookupData data = new LookupData(classType.getNameCharArray(), null, point);
|
||||
ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, point);
|
||||
data.foundItems = constructors;
|
||||
data.setFunctionArguments(false, fArguments);
|
||||
data.setFunctionArguments(false, args);
|
||||
try {
|
||||
IBinding binding = CPPSemantics.resolveFunction(data, constructors, true);
|
||||
if (binding == null || binding instanceof IProblemBinding ||
|
||||
|
@ -244,12 +244,4 @@ public class EvalTypeId extends CPPDependentEvaluation {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean areArgumentTypesDependent() {
|
||||
for (ICPPEvaluation arg : fArguments) {
|
||||
if (arg.isTypeDependent())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue