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

Bug 305974. Fixed AST2TemplateTests.testSFINAE_b

This commit is contained in:
Sergey Prigogin 2012-08-10 11:39:02 -07:00
parent e7c0e1fb81
commit 273f7ce331
5 changed files with 86 additions and 63 deletions

View file

@ -18,7 +18,6 @@ import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -322,18 +321,23 @@ public class AST2BaseTest extends BaseTestCase {
{
shouldVisitNames = true;
}
public List nameList = new ArrayList();
public List<IASTName> nameList = new ArrayList<IASTName>();
@Override
public int visit(IASTName name) {
nameList.add(name);
return PROCESS_CONTINUE;
}
public IASTName getName(int idx) {
if (idx < 0 || idx >= nameList.size())
return null;
return (IASTName) nameList.get(idx);
return nameList.get(idx);
}
public int size() { return nameList.size(); }
public int size() {
return nameList.size();
}
}
protected void assertInstances(CNameCollector collector, IBinding binding, int num) throws Exception {
@ -354,17 +358,22 @@ public class AST2BaseTest extends BaseTestCase {
shouldVisitNames = true;
}
public List<IASTName> nameList = new ArrayList<IASTName>();
@Override
public int visit(IASTName name) {
nameList.add(name);
return PROCESS_CONTINUE;
}
public IASTName getName(int idx) {
if (idx < 0 || idx >= nameList.size())
return null;
return nameList.get(idx);
}
public int size() { return nameList.size(); }
public int size() {
return nameList.size();
}
public void dump() {
for (int i= 0; i < size(); i++) {
@ -434,9 +443,10 @@ public class AST2BaseTest extends BaseTestCase {
{
shouldVisitNames = true;
}
public int numProblemBindings=0;
public int numNullBindings=0;
public List nameList = new ArrayList();
public int numProblemBindings;
public int numNullBindings;
public List<IASTName> nameList = new ArrayList<IASTName>();
@Override
public int visit(IASTName name) {
nameList.add(name);
@ -447,21 +457,26 @@ public class AST2BaseTest extends BaseTestCase {
numNullBindings++;
return PROCESS_CONTINUE;
}
public IASTName getName(int idx) {
if (idx < 0 || idx >= nameList.size())
return null;
return (IASTName) nameList.get(idx);
return nameList.get(idx);
}
public int size() { return nameList.size(); }
public int size() {
return nameList.size();
}
}
static protected class CPPNameResolver extends ASTVisitor {
{
shouldVisitNames = true;
}
public int numProblemBindings=0;
public int numNullBindings=0;
public List nameList = new ArrayList();
public int numProblemBindings;
public int numNullBindings;
public List<IASTName> nameList = new ArrayList<IASTName>();
@Override
public int visit(IASTName name) {
nameList.add(name);
@ -472,12 +487,16 @@ public class AST2BaseTest extends BaseTestCase {
numNullBindings++;
return PROCESS_CONTINUE;
}
public IASTName getName(int idx) {
if (idx < 0 || idx >= nameList.size())
return null;
return (IASTName) nameList.get(idx);
return nameList.get(idx);
}
public int size() { return nameList.size(); }
public int size() {
return nameList.size();
}
}
protected String getAboveComment() throws IOException {
@ -575,7 +594,7 @@ public class AST2BaseTest extends BaseTestCase {
if (implicits.length > 1) {
boolean found = false;
for (IASTImplicitName n : implicits) {
if (((ASTNode) n).getOffset() == ((ASTNode)name).getOffset()) {
if (((ASTNode) n).getOffset() == ((ASTNode) name).getOffset()) {
assertFalse(found);
found = true;
}
@ -662,8 +681,8 @@ public class AST2BaseTest extends BaseTestCase {
}
}
}
} catch(IllegalAccessException iae) {
throw new RuntimeException(iae);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
return "Unknown problem ID";
}
@ -736,18 +755,14 @@ public class AST2BaseTest extends BaseTestCase {
}
final protected void assertNoProblemBindings(CNameCollector col) {
Iterator i = col.nameList.iterator();
while (i.hasNext()) {
IASTName n = (IASTName) i.next();
for (IASTName n : col.nameList) {
assertFalse("ProblemBinding for " + n.getRawSignature(), n.resolveBinding() instanceof IProblemBinding);
}
}
final protected void assertProblemBindings(CNameCollector col, int count) {
Iterator i = col.nameList.iterator();
int sum = 0;
while (i.hasNext()) {
IASTName n = (IASTName) i.next();
for (IASTName n : col.nameList) {
if (n.getBinding() instanceof IProblemBinding)
++sum;
}

View file

@ -5985,7 +5985,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// A<double>::get();
// A<int>::get();
// }
public void _testSFINAE_b() throws Exception {
public void testSFINAE_b() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2010 IBM Corporation and others.
* Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -46,7 +46,6 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
protected final int id;
protected char[] arg;
protected IASTNode node;
private final String message = null;
private IBinding[] candidateBindings;
public ProblemBinding(IASTName name, int id) {
@ -100,15 +99,17 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
*/
@Override
public String getMessage() {
if (message != null)
return message;
String msg = ParserMessages.getProblemPattern(this);
if (msg == null)
return ""; //$NON-NLS-1$
if (arg == null && node instanceof IASTName)
arg= ((IASTName) node).toCharArray();
if (arg == null) {
if (node instanceof IASTName) {
arg= ((IASTName) node).toCharArray();
} else if (candidateBindings != null && candidateBindings.length != 0) {
arg = candidateBindings[0].getNameCharArray();
}
}
if (arg != null) {
msg = MessageFormat.format(msg, new Object[] { new String(arg) });

View file

@ -101,7 +101,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization;
@ -177,7 +176,7 @@ public class CPPTemplates {
ICPPTemplateArgument[] arguments= SemanticUtil.getSimplifiedArguments(args);
arguments= addDefaultArguments(template, arguments, point);
if (arguments == null)
return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS);
return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, point);
if (template instanceof ICPPTemplateTemplateParameter || hasDependentArgument(arguments)) {
return deferredInstance(template, arguments);
@ -202,14 +201,14 @@ public class CPPTemplates {
param= parameters[i];
isPack= param.isParameterPack();
} else {
return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS);
return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, point);
}
}
if (i < numArgs) {
ICPPTemplateArgument arg= arguments[i];
ICPPTemplateArgument newArg = CPPTemplates.matchTemplateParameterAndArgument(param, arg, map, point);
if (newArg == null)
return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS);
return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, point);
if (newArg != arg) {
if (arguments == args) {
arguments= args.clone();
@ -249,9 +248,8 @@ public class CPPTemplates {
}
}
private static IBinding createProblem(ICPPClassTemplate template, int id) {
IASTNode node= new CPPASTName(template.getNameCharArray());
return new ProblemBinding(node, id, template.getNameCharArray());
private static IBinding createProblem(ICPPClassTemplate template, int id, IASTNode point) {
return new ProblemBinding(point, id, template.getNameCharArray());
}
static IBinding isUsedInClassTemplateScope(ICPPClassTemplate ct, IASTName name) {
@ -845,7 +843,7 @@ public class CPPTemplates {
return null;
ICPPClassSpecialization within= (ICPPClassSpecialization) owner;
ICPPClassType orig = within.getSpecializedBinding();
for (;;) {
while (true) {
IBinding o1 = within.getOwner();
IBinding o2 = orig.getOwner();
if (!(o1 instanceof ICPPClassSpecialization && o2 instanceof ICPPClassType))
@ -1997,18 +1995,20 @@ public class CPPTemplates {
return null;
}
ICPPClassTemplatePartialSpecialization bestMatch = null, spec = null;
ICPPClassTemplatePartialSpecialization bestMatch = null;
CPPTemplateParameterMap bestMap= null;
boolean bestMatchIsBest = true;
for (ICPPClassTemplatePartialSpecialization specialization : specializations) {
spec = specialization;
final CPPTemplateParameterMap map = new CPPTemplateParameterMap(args.length);
if (TemplateArgumentDeduction.fromTemplateArguments(spec.getTemplateParameters(), spec.getTemplateArguments(), args, map, point)) {
int compare = orderSpecializations(bestMatch, spec, point);
ICPPTemplateArgument[] specializationArguments = specialization.getTemplateArguments();
if (TemplateArgumentDeduction.fromTemplateArguments(specialization.getTemplateParameters(),
specializationArguments, args, map, point) &&
checkInstantiationOfArguments(specializationArguments, map, point)) {
int compare = orderSpecializations(bestMatch, specialization, point);
if (compare == 0) {
bestMatchIsBest = false;
} else if (compare < 0) {
bestMatch = spec;
bestMatch = specialization;
bestMap= map;
bestMatchIsBest = true;
}
@ -2019,7 +2019,8 @@ public class CPPTemplates {
// specializations, then the use of the class template is ambiguous and the program is
// ill-formed.
if (!bestMatchIsBest) {
return new CPPTemplateDefinition.CPPTemplateProblem(null, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, null);
return new CPPTemplateDefinition.CPPTemplateProblem(null, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP,
template.getNameCharArray());
}
if (bestMatch == null)
@ -2028,6 +2029,16 @@ public class CPPTemplates {
return instantiatePartialSpecialization(bestMatch, args, isDef, bestMap, point);
}
private static boolean checkInstantiationOfArguments(ICPPTemplateArgument[] args,
CPPTemplateParameterMap tpMap, IASTNode point) throws DOMException {
args = instantiateArguments(args, tpMap, -1, null, point);
for (ICPPTemplateArgument arg : args) {
if (!isValidArgument(arg))
return false;
}
return true;
}
/**
* Compare spec1 to spec2. Return > 0 if spec1 is more specialized, < 0 if spec2
* is more specialized, = 0 otherwise.
@ -2100,7 +2111,7 @@ public class CPPTemplates {
}
static boolean isValidType(IType t) {
for (;;) {
while (true) {
if (t instanceof ISemanticProblem) {
return false;
} else if (t instanceof IFunctionType) {

View file

@ -1,14 +1,14 @@
###############################################################################
# Copyright (c) 2005, 2011 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
# Copyright (c) 2005, 2011 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# IBM Rational Software - Initial API and implementation
# Anton Leherbauer (Wind River Systems)
# Markus Schorn (Wind River Systems)
# Contributors:
# IBM Rational Software - Initial API and implementation
# Anton Leherbauer (Wind River Systems)
# Markus Schorn (Wind River Systems)
###############################################################################
ScannerProblemFactory.error.preproc.error=#error encountered with text: {0}
@ -51,7 +51,7 @@ ISemanticProblem.BINDING_NOT_FOUND=Attempt to use symbol failed: {0}
ISemanticProblem.BINDING_AMBIGUOUS_LOOKUP=Ambiguity encountered during lookup: {0}
ISemanticProblem.BINDING_BAD_SCOPE=A scope could not be created to represent the name {0}
ISemanticProblem.BINDING_INVALID_TYPE=Invalid type encountered in: {0}
ISemanticProblem.BINDING_CIRCULAR_INHERITANCE=Circular inheritance encountered in: {0}
ISemanticProblem.BINDING_CIRCULAR_INHERITANCE=Circular inheritance encountered in {0}
ISemanticProblem.BINDING_INVALID_OVERLOAD=Invalid overload of the name: {0}
ISemanticProblem.BINDING_INVALID_USING=Invalid using directive/declaration: {0}
ISemanticProblem.BINDING_DEFINITION_NOT_FOUND=A definition was not found for {0}
@ -60,9 +60,8 @@ ISemanticProblem.BINDING_LABEL_STATEMENT_NOT_FOUND=A label statement was not fou
ISemanticProblem.BINDING_INVALID_REDEFINITION=Invalid redefinition of the name {0}
ISemanticProblem.BINDING_INVALID_REDECLARATION=Invalid redeclaration of the name {0}
ISemanticProblem.BINDING_RECURSION_IN_LOOKUP=Recursion while looking up ''{0}''
ISemanticProblem.BINDING_MEMBER_DECLARATION_NOT_FOUND=A declaration could not be found for this member definition: {0}: return "ASTProblemFactory.error.semantic.dom.memberDeclNotFound"; //$NON-NLS-1$
ISemanticProblem.BINDING_INVALID_TEMPLATE_ARGUMENTS=A template id provides illegal arguments for the instantiation: {0}: return "ASTProblemFactory.error.semantic.dom.invalidTemplateArgs"; //$NON-NLS-1$
ISemanticProblem.BINDING_MEMBER_DECLARATION_NOT_FOUND=A declaration could not be found for this member definition: {0}
ISemanticProblem.BINDING_INVALID_TEMPLATE_ARGUMENTS=A template id provides illegal arguments for the instantiation: {0}
ISemanticProblem.TYPE_NO_NAME=Type specification lacks a name
ISemanticProblem.TYPE_UNRESOLVED_NAME=Type depends on an unresolved name
@ -70,6 +69,3 @@ ISemanticProblem.TYPE_AUTO_FOR_NON_STATIC_FIELD=Illegally auto-typed static fiel
ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE=Failure to determine auto-type
ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION=Failure to determine type of expression
ISemanticProblem.TYPE_NOT_PERSISTED=Failure to store type in the index