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

View file

@ -5985,7 +5985,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// A<double>::get(); // A<double>::get();
// A<int>::get(); // A<int>::get();
// } // }
public void _testSFINAE_b() throws Exception { public void testSFINAE_b() throws Exception {
parseAndCheckBindings(); 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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 final int id;
protected char[] arg; protected char[] arg;
protected IASTNode node; protected IASTNode node;
private final String message = null;
private IBinding[] candidateBindings; private IBinding[] candidateBindings;
public ProblemBinding(IASTName name, int id) { public ProblemBinding(IASTName name, int id) {
@ -100,15 +99,17 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
*/ */
@Override @Override
public String getMessage() { public String getMessage() {
if (message != null)
return message;
String msg = ParserMessages.getProblemPattern(this); String msg = ParserMessages.getProblemPattern(this);
if (msg == null) if (msg == null)
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
if (arg == null && node instanceof IASTName) if (arg == null) {
arg= ((IASTName) node).toCharArray(); if (node instanceof IASTName) {
arg= ((IASTName) node).toCharArray();
} else if (candidateBindings != null && candidateBindings.length != 0) {
arg = candidateBindings[0].getNameCharArray();
}
}
if (arg != null) { if (arg != null) {
msg = MessageFormat.format(msg, new Object[] { new String(arg) }); 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.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType; 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.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.CPPArrayType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization;
@ -177,7 +176,7 @@ public class CPPTemplates {
ICPPTemplateArgument[] arguments= SemanticUtil.getSimplifiedArguments(args); ICPPTemplateArgument[] arguments= SemanticUtil.getSimplifiedArguments(args);
arguments= addDefaultArguments(template, arguments, point); arguments= addDefaultArguments(template, arguments, point);
if (arguments == null) 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)) { if (template instanceof ICPPTemplateTemplateParameter || hasDependentArgument(arguments)) {
return deferredInstance(template, arguments); return deferredInstance(template, arguments);
@ -202,14 +201,14 @@ public class CPPTemplates {
param= parameters[i]; param= parameters[i];
isPack= param.isParameterPack(); isPack= param.isParameterPack();
} else { } else {
return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, point);
} }
} }
if (i < numArgs) { if (i < numArgs) {
ICPPTemplateArgument arg= arguments[i]; ICPPTemplateArgument arg= arguments[i];
ICPPTemplateArgument newArg = CPPTemplates.matchTemplateParameterAndArgument(param, arg, map, point); ICPPTemplateArgument newArg = CPPTemplates.matchTemplateParameterAndArgument(param, arg, map, point);
if (newArg == null) if (newArg == null)
return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, point);
if (newArg != arg) { if (newArg != arg) {
if (arguments == args) { if (arguments == args) {
arguments= args.clone(); arguments= args.clone();
@ -249,9 +248,8 @@ public class CPPTemplates {
} }
} }
private static IBinding createProblem(ICPPClassTemplate template, int id) { private static IBinding createProblem(ICPPClassTemplate template, int id, IASTNode point) {
IASTNode node= new CPPASTName(template.getNameCharArray()); return new ProblemBinding(point, id, template.getNameCharArray());
return new ProblemBinding(node, id, template.getNameCharArray());
} }
static IBinding isUsedInClassTemplateScope(ICPPClassTemplate ct, IASTName name) { static IBinding isUsedInClassTemplateScope(ICPPClassTemplate ct, IASTName name) {
@ -845,7 +843,7 @@ public class CPPTemplates {
return null; return null;
ICPPClassSpecialization within= (ICPPClassSpecialization) owner; ICPPClassSpecialization within= (ICPPClassSpecialization) owner;
ICPPClassType orig = within.getSpecializedBinding(); ICPPClassType orig = within.getSpecializedBinding();
for (;;) { while (true) {
IBinding o1 = within.getOwner(); IBinding o1 = within.getOwner();
IBinding o2 = orig.getOwner(); IBinding o2 = orig.getOwner();
if (!(o1 instanceof ICPPClassSpecialization && o2 instanceof ICPPClassType)) if (!(o1 instanceof ICPPClassSpecialization && o2 instanceof ICPPClassType))
@ -1997,18 +1995,20 @@ public class CPPTemplates {
return null; return null;
} }
ICPPClassTemplatePartialSpecialization bestMatch = null, spec = null; ICPPClassTemplatePartialSpecialization bestMatch = null;
CPPTemplateParameterMap bestMap= null; CPPTemplateParameterMap bestMap= null;
boolean bestMatchIsBest = true; boolean bestMatchIsBest = true;
for (ICPPClassTemplatePartialSpecialization specialization : specializations) { for (ICPPClassTemplatePartialSpecialization specialization : specializations) {
spec = specialization;
final CPPTemplateParameterMap map = new CPPTemplateParameterMap(args.length); final CPPTemplateParameterMap map = new CPPTemplateParameterMap(args.length);
if (TemplateArgumentDeduction.fromTemplateArguments(spec.getTemplateParameters(), spec.getTemplateArguments(), args, map, point)) { ICPPTemplateArgument[] specializationArguments = specialization.getTemplateArguments();
int compare = orderSpecializations(bestMatch, spec, point); if (TemplateArgumentDeduction.fromTemplateArguments(specialization.getTemplateParameters(),
specializationArguments, args, map, point) &&
checkInstantiationOfArguments(specializationArguments, map, point)) {
int compare = orderSpecializations(bestMatch, specialization, point);
if (compare == 0) { if (compare == 0) {
bestMatchIsBest = false; bestMatchIsBest = false;
} else if (compare < 0) { } else if (compare < 0) {
bestMatch = spec; bestMatch = specialization;
bestMap= map; bestMap= map;
bestMatchIsBest = true; bestMatchIsBest = true;
} }
@ -2019,7 +2019,8 @@ public class CPPTemplates {
// specializations, then the use of the class template is ambiguous and the program is // specializations, then the use of the class template is ambiguous and the program is
// ill-formed. // ill-formed.
if (!bestMatchIsBest) { 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) if (bestMatch == null)
@ -2028,6 +2029,16 @@ public class CPPTemplates {
return instantiatePartialSpecialization(bestMatch, args, isDef, bestMap, point); 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 * Compare spec1 to spec2. Return > 0 if spec1 is more specialized, < 0 if spec2
* is more specialized, = 0 otherwise. * is more specialized, = 0 otherwise.
@ -2100,7 +2111,7 @@ public class CPPTemplates {
} }
static boolean isValidType(IType t) { static boolean isValidType(IType t) {
for (;;) { while (true) {
if (t instanceof ISemanticProblem) { if (t instanceof ISemanticProblem) {
return false; return false;
} else if (t instanceof IFunctionType) { } else if (t instanceof IFunctionType) {

View file

@ -1,14 +1,14 @@
############################################################################### ###############################################################################
# Copyright (c) 2005, 2011 IBM Corporation and others. # Copyright (c) 2005, 2011 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials # All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0 # are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at # which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html # http://www.eclipse.org/legal/epl-v10.html
# #
# Contributors: # Contributors:
# IBM Rational Software - Initial API and implementation # IBM Rational Software - Initial API and implementation
# Anton Leherbauer (Wind River Systems) # Anton Leherbauer (Wind River Systems)
# Markus Schorn (Wind River Systems) # Markus Schorn (Wind River Systems)
############################################################################### ###############################################################################
ScannerProblemFactory.error.preproc.error=#error encountered with text: {0} 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_AMBIGUOUS_LOOKUP=Ambiguity encountered during lookup: {0}
ISemanticProblem.BINDING_BAD_SCOPE=A scope could not be created to represent the name {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_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_OVERLOAD=Invalid overload of the name: {0}
ISemanticProblem.BINDING_INVALID_USING=Invalid using directive/declaration: {0} ISemanticProblem.BINDING_INVALID_USING=Invalid using directive/declaration: {0}
ISemanticProblem.BINDING_DEFINITION_NOT_FOUND=A definition was not found for {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_REDEFINITION=Invalid redefinition of the name {0}
ISemanticProblem.BINDING_INVALID_REDECLARATION=Invalid redeclaration 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_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_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}: return "ASTProblemFactory.error.semantic.dom.invalidTemplateArgs"; //$NON-NLS-1$ 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_NO_NAME=Type specification lacks a name
ISemanticProblem.TYPE_UNRESOLVED_NAME=Type depends on an unresolved 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_CANNOT_DEDUCE_AUTO_TYPE=Failure to determine auto-type
ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION=Failure to determine type of expression ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION=Failure to determine type of expression
ISemanticProblem.TYPE_NOT_PERSISTED=Failure to store type in the index ISemanticProblem.TYPE_NOT_PERSISTED=Failure to store type in the index