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

Bug 299911. Added AST2TemplateTests.testSFINAE.

This commit is contained in:
Sergey Prigogin 2012-08-04 18:19:46 -07:00
parent 58e4809932
commit 1b02f7df80
7 changed files with 98 additions and 31 deletions

View file

@ -5876,4 +5876,52 @@ public class AST2TemplateTests extends AST2BaseTest {
public void testConstInTypeParameter_377223() throws Exception {
parseAndCheckBindings();
}
// template<typename T, T v>
// struct integral_constant {
// static constexpr T value = v;
// typedef T value_type;
// typedef integral_constant<T, v> type;
// };
//
// typedef integral_constant<bool, true> true_type;
//
// typedef integral_constant<bool, false> false_type;
//
// template<typename T>
// class helper {
// typedef char one;
// typedef struct { char arr[2]; } two;
// template<typename U> struct Wrap_type {};
// template<typename U> static one test(Wrap_type<typename U::category>*);
// template<typename U> static two test(...);
// public: static const bool value = sizeof(test<T>(0)) == 1;
// };
//
// template<typename T>
// struct has_category : integral_constant<bool, helper<T>::value> {};
//
// template<typename Iterator, bool = has_category<Iterator>::value>
// struct traits {};
//
// template<typename Iterator>
// struct traits<Iterator, true> {
// typedef typename Iterator::value_type value_type;
// };
//
// struct tag {};
//
// struct C {
// typedef int value_type;
// typedef tag category;
// };
//
// template<typename It, typename Val = typename traits<It>::value_type>
// class A {
// };
//
// typedef A<C> type;
public void testSFINAE() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -94,10 +94,10 @@ public class EvalBinding extends CPPEvaluation {
t= ((ICPPTemplateNonTypeParameter) fBinding).getType();
} else if (fBinding instanceof IVariable) {
t = ((IVariable) fBinding).getType();
} else if (fBinding instanceof IFunction) {
t= ((IFunction) fBinding).getType();
} else if (fBinding instanceof ICPPUnknownBinding) {
return true;
} else if (fBinding instanceof IFunction) {
t= ((IFunction) fBinding).getType();
} else {
return false;
}
@ -123,12 +123,12 @@ public class EvalBinding extends CPPEvaluation {
if (fBinding instanceof IVariable) {
return Value.isDependentValue(((IVariable) fBinding).getInitialValue());
}
if (fBinding instanceof IFunction) {
return false;
}
if (fBinding instanceof ICPPUnknownBinding) {
return true;
}
if (fBinding instanceof IFunction) {
return false;
}
return false;
}

View file

@ -173,14 +173,18 @@ public class EvalComma extends CPPEvaluation {
@Override
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length];
boolean changed = false;
ICPPEvaluation[] args = null;
for (int i = 0; i < fArguments.length; i++) {
args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (args[i] != fArguments[i])
changed = true;
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (arg != fArguments[i]) {
if (args == null) {
args = new ICPPEvaluation[fArguments.length];
System.arraycopy(fArguments, 0, args, 0, fArguments.length);
}
args[i] = arg;
}
}
if (!changed)
if (args == null)
return this;
return new EvalComma(args);
}

View file

@ -186,14 +186,18 @@ public class EvalFunctionCall extends CPPEvaluation {
@Override
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length];
boolean changed = false;
ICPPEvaluation[] args = null;
for (int i = 0; i < fArguments.length; i++) {
args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (args[i] != fArguments[i])
changed = true;
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (arg != fArguments[i]) {
if (args == null) {
args = new ICPPEvaluation[fArguments.length];
System.arraycopy(fArguments, 0, args, 0, fArguments.length);
}
args[i] = arg;
}
}
if (!changed)
if (args == null)
return this;
if (args[0] instanceof EvalFunctionSet) {

View file

@ -128,7 +128,7 @@ public class EvalID extends CPPEvaluation {
@Override
public IValue getValue(IASTNode point) {
// Name lookup is not needed here because it was already done in "instantiate" method.
// Name lookup is not needed here because it was already done in the "instantiate" method.
// IBinding nameOwner = fNameOwner;
// if (nameOwner == null && fFieldOwner != null)
// nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point);

View file

@ -105,14 +105,18 @@ public class EvalInitList extends CPPEvaluation {
@Override
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
ICPPEvaluation[] clauses = new ICPPEvaluation[fClauses.length];
boolean changed = false;
ICPPEvaluation[] clauses = null;
for (int i = 0; i < fClauses.length; i++) {
clauses[i] = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (clauses[i] != fClauses[i])
changed = true;
ICPPEvaluation clause = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (clause != fClauses[i]) {
if (clauses == null) {
clauses = new ICPPEvaluation[fClauses.length];
System.arraycopy(fClauses, 0, clauses, 0, fClauses.length);
}
clauses[i] = clause;
}
}
if (!changed)
if (clauses == null)
return this;
return new EvalInitList(clauses);
}

View file

@ -146,16 +146,23 @@ public class EvalTypeId extends CPPEvaluation {
@Override
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length];
boolean argsChanged = false;
ICPPEvaluation[] args = null;
for (int i = 0; i < fArguments.length; i++) {
args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (args[i] != fArguments[i])
argsChanged = true;
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (arg != fArguments[i]) {
if (args == null) {
args = new ICPPEvaluation[fArguments.length];
System.arraycopy(fArguments, 0, args, 0, fArguments.length);
}
args[i] = arg;
}
}
IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point);
if (!argsChanged && type == fInputType)
return this;
if (args == null) {
if (type == fInputType)
return this;
args = fArguments;
}
return new EvalTypeId(type, args);
}