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:
parent
58e4809932
commit
1b02f7df80
7 changed files with 98 additions and 31 deletions
|
@ -5876,4 +5876,52 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
public void testConstInTypeParameter_377223() throws Exception {
|
public void testConstInTypeParameter_377223() throws Exception {
|
||||||
parseAndCheckBindings();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,10 +94,10 @@ public class EvalBinding extends CPPEvaluation {
|
||||||
t= ((ICPPTemplateNonTypeParameter) fBinding).getType();
|
t= ((ICPPTemplateNonTypeParameter) fBinding).getType();
|
||||||
} else if (fBinding instanceof IVariable) {
|
} else if (fBinding instanceof IVariable) {
|
||||||
t = ((IVariable) fBinding).getType();
|
t = ((IVariable) fBinding).getType();
|
||||||
} else if (fBinding instanceof IFunction) {
|
|
||||||
t= ((IFunction) fBinding).getType();
|
|
||||||
} else if (fBinding instanceof ICPPUnknownBinding) {
|
} else if (fBinding instanceof ICPPUnknownBinding) {
|
||||||
return true;
|
return true;
|
||||||
|
} else if (fBinding instanceof IFunction) {
|
||||||
|
t= ((IFunction) fBinding).getType();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -123,12 +123,12 @@ public class EvalBinding extends CPPEvaluation {
|
||||||
if (fBinding instanceof IVariable) {
|
if (fBinding instanceof IVariable) {
|
||||||
return Value.isDependentValue(((IVariable) fBinding).getInitialValue());
|
return Value.isDependentValue(((IVariable) fBinding).getInitialValue());
|
||||||
}
|
}
|
||||||
if (fBinding instanceof IFunction) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (fBinding instanceof ICPPUnknownBinding) {
|
if (fBinding instanceof ICPPUnknownBinding) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (fBinding instanceof IFunction) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,14 +173,18 @@ public class EvalComma extends CPPEvaluation {
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
||||||
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
||||||
ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length];
|
ICPPEvaluation[] args = null;
|
||||||
boolean changed = false;
|
|
||||||
for (int i = 0; i < fArguments.length; i++) {
|
for (int i = 0; i < fArguments.length; i++) {
|
||||||
args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
||||||
if (args[i] != fArguments[i])
|
if (arg != fArguments[i]) {
|
||||||
changed = true;
|
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 this;
|
||||||
return new EvalComma(args);
|
return new EvalComma(args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,14 +186,18 @@ public class EvalFunctionCall extends CPPEvaluation {
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
||||||
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
||||||
ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length];
|
ICPPEvaluation[] args = null;
|
||||||
boolean changed = false;
|
|
||||||
for (int i = 0; i < fArguments.length; i++) {
|
for (int i = 0; i < fArguments.length; i++) {
|
||||||
args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
||||||
if (args[i] != fArguments[i])
|
if (arg != fArguments[i]) {
|
||||||
changed = true;
|
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 this;
|
||||||
|
|
||||||
if (args[0] instanceof EvalFunctionSet) {
|
if (args[0] instanceof EvalFunctionSet) {
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class EvalID extends CPPEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IValue getValue(IASTNode point) {
|
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;
|
// IBinding nameOwner = fNameOwner;
|
||||||
// if (nameOwner == null && fFieldOwner != null)
|
// if (nameOwner == null && fFieldOwner != null)
|
||||||
// nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point);
|
// nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point);
|
||||||
|
|
|
@ -105,14 +105,18 @@ public class EvalInitList extends CPPEvaluation {
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
||||||
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
||||||
ICPPEvaluation[] clauses = new ICPPEvaluation[fClauses.length];
|
ICPPEvaluation[] clauses = null;
|
||||||
boolean changed = false;
|
|
||||||
for (int i = 0; i < fClauses.length; i++) {
|
for (int i = 0; i < fClauses.length; i++) {
|
||||||
clauses[i] = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
ICPPEvaluation clause = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
||||||
if (clauses[i] != fClauses[i])
|
if (clause != fClauses[i]) {
|
||||||
changed = true;
|
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 this;
|
||||||
return new EvalInitList(clauses);
|
return new EvalInitList(clauses);
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,16 +146,23 @@ public class EvalTypeId extends CPPEvaluation {
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
||||||
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
||||||
ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length];
|
ICPPEvaluation[] args = null;
|
||||||
boolean argsChanged = false;
|
|
||||||
for (int i = 0; i < fArguments.length; i++) {
|
for (int i = 0; i < fArguments.length; i++) {
|
||||||
args[i] = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
||||||
if (args[i] != fArguments[i])
|
if (arg != fArguments[i]) {
|
||||||
argsChanged = true;
|
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);
|
IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point);
|
||||||
if (!argsChanged && type == fInputType)
|
if (args == null) {
|
||||||
return this;
|
if (type == fInputType)
|
||||||
|
return this;
|
||||||
|
args = fArguments;
|
||||||
|
}
|
||||||
return new EvalTypeId(type, args);
|
return new EvalTypeId(type, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue