mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Improve ProblemBinding checker message for failed function instantiation (#668)
Display the new more accurate error when all candidates were failed instantiations. Otherwise, if there is a mix of failed instantiation and wrong number of arguments, display the old message. This could really be improved even more... template<typename T> void function() {} Before: function(); // Invalid arguments 'Candidates are: After: function(); // Cannot instantiate template function 'Candidates are:
This commit is contained in:
parent
e838a231d9
commit
d5ec9d7c68
8 changed files with 38 additions and 5 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %Bundle-Name
|
||||
Bundle-SymbolicName: org.eclipse.cdt.codan.checkers;singleton:=true
|
||||
Bundle-Version: 3.5.400.qualifier
|
||||
Bundle-Version: 3.5.500.qualifier
|
||||
Bundle-Activator: org.eclipse.cdt.codan.checkers.CodanCheckersActivator
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources,
|
||||
|
|
|
@ -116,6 +116,9 @@ problem.name.12 = Field cannot be resolved
|
|||
problem.description.13 = Name resolution problem found by the indexer
|
||||
problem.messagePattern.13 = Structured binding initializer expression refers to introduced name ''{0}''
|
||||
problem.name.13 = Invalid structured binding declaration
|
||||
problem.description.14 = Name resolution problem found by the indexer
|
||||
problem.messagePattern.14 = Cannot instantiate template function ''{0}''
|
||||
problem.name.14 = Function cannot be instantiated
|
||||
checker.name.AbstractClassCreation = Abstract class cannot be instantiated
|
||||
problem.name.AbstractClassCreation = Abstract class cannot be instantiated
|
||||
problem.messagePattern.AbstractClassCreation = The type ''{0}'' must implement the inherited pure virtual method ''{1}''\u0020
|
||||
|
|
|
@ -253,6 +253,16 @@
|
|||
messagePattern="%problem.messagePattern.10"
|
||||
name="%problem.name.10">
|
||||
</problem>
|
||||
<problem
|
||||
category="org.eclipse.cdt.codan.core.categories.CompilerErrors"
|
||||
defaultEnabled="true"
|
||||
defaultSeverity="Error"
|
||||
description="%problem.description.14"
|
||||
id="org.eclipse.cdt.codan.internal.checkers.TemplateInstantiationProblem"
|
||||
markerType="org.eclipse.cdt.codan.core.codanSemanticProblem"
|
||||
messagePattern="%problem.messagePattern.14"
|
||||
name="%problem.name.14">
|
||||
</problem>
|
||||
<problem
|
||||
category="org.eclipse.cdt.codan.core.categories.CompilerErrors"
|
||||
defaultEnabled="true"
|
||||
|
|
|
@ -66,6 +66,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
public static String ERR_ID_VariableResolutionProblem = "org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem"; //$NON-NLS-1$
|
||||
public static String ERR_ID_Candidates = "org.eclipse.cdt.codan.internal.checkers.Candidates"; //$NON-NLS-1$
|
||||
public static String ERR_ID_StructuredBindingDeclarationProblem = "org.eclipse.cdt.codan.internal.checkers.StructuredBindingDeclarationProblem"; //$NON-NLS-1$
|
||||
public static String ERR_ID_TemplateInstantiationProblem = "org.eclipse.cdt.codan.internal.checkers.TemplateInstantiationProblem"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public boolean runInEditor() {
|
||||
|
@ -175,6 +176,14 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
contextFlagsString);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
if (id == IProblemBinding.SEMANTIC_INVALID_TEMPLATE_INSTANTIATION) {
|
||||
if (isFunctionCall(name, parentNode)) {
|
||||
reportProblem(ERR_ID_TemplateInstantiationProblem, name.getLastName(),
|
||||
getCandidatesString(problemBinding), contextFlagsString);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
// From this point, we'll deal only with NAME_NOT_FOUND problems.
|
||||
// If it's something else continue because we don't want to give bad messages.
|
||||
if (id != IProblemBinding.SEMANTIC_NAME_NOT_FOUND) {
|
||||
|
|
|
@ -480,7 +480,7 @@ public class AST2TemplateTests extends AST2CPPTestBase {
|
|||
assertInstance(fCall, IProblemBinding.class);
|
||||
|
||||
IProblemBinding fCallPB = (IProblemBinding) fCall;
|
||||
assertEquals(IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fCallPB.getID());
|
||||
assertEquals(IProblemBinding.BINDING_INVALID_TEMPLATE_INSTANTIATION, fCallPB.getID());
|
||||
}
|
||||
|
||||
// template < class T, template < class X > class U, T *pT > class A {
|
||||
|
@ -7487,7 +7487,7 @@ public class AST2TemplateTests extends AST2CPPTestBase {
|
|||
public void testTemplatedAliasDeduction() throws Exception {
|
||||
BindingAssertionHelper bh = getAssertionHelper();
|
||||
bh.assertNonProblem("g(v)", "g", ICPPFunction.class);
|
||||
bh.assertProblem("f(v)", "f", ISemanticProblem.BINDING_NOT_FOUND);
|
||||
bh.assertProblem("f(v)", "f", ISemanticProblem.BINDING_INVALID_TEMPLATE_INSTANTIATION);
|
||||
}
|
||||
|
||||
// using function = void (&)(int);
|
||||
|
|
|
@ -67,6 +67,8 @@ public interface IProblemBinding extends IBinding, IScope, IType, ISemanticProbl
|
|||
public static final int SEMANTIC_INVALID_TEMPLATE_ARGUMENTS = BINDING_INVALID_TEMPLATE_ARGUMENTS;
|
||||
/** @since 8.1 */
|
||||
public static final int SEMANTIC_INVALID_STRUCTURED_BINDING_INITIALIZER = BINDING_INVALID_STRUCTURED_BINDING_INITIALIZER;
|
||||
/** @since 8.4 */
|
||||
public static final int SEMANTIC_INVALID_TEMPLATE_INSTANTIATION = BINDING_INVALID_TEMPLATE_INSTANTIATION;
|
||||
|
||||
/**
|
||||
* @deprecated There may be additional problems.
|
||||
|
|
|
@ -39,6 +39,8 @@ public interface ISemanticProblem {
|
|||
int BINDING_NO_CLASS = 16;
|
||||
/** @since 8.1 */
|
||||
int BINDING_INVALID_STRUCTURED_BINDING_INITIALIZER = 17;
|
||||
/** @since 8.4 */
|
||||
int BINDING_INVALID_TEMPLATE_INSTANTIATION = 18;
|
||||
|
||||
int TYPE_NO_NAME = 10000;
|
||||
int TYPE_UNRESOLVED_NAME = 10001;
|
||||
|
|
|
@ -3103,10 +3103,17 @@ public class CPPSemantics {
|
|||
ICPPFunction[] tmp = selectByArgumentCount(data, fns);
|
||||
if (tmp.length == 0 || tmp[0] == null)
|
||||
return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns);
|
||||
int nbBeforeInstantiate = tmp.length;
|
||||
tmp = CPPTemplates.instantiateForFunctionCall(tmp, data.getTemplateArguments(), Arrays.asList(argTypes),
|
||||
Arrays.asList(data.getFunctionArgumentValueCategories()), data.argsContainImpliedObject);
|
||||
if (tmp.length == 0 || tmp[0] == null)
|
||||
return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns);
|
||||
if (tmp.length == 0 || tmp[0] == null) {
|
||||
// All candidates were failed template instantiations
|
||||
if (nbBeforeInstantiate == fns.length)
|
||||
return new ProblemBinding(lookupName, lookupPoint,
|
||||
IProblemBinding.SEMANTIC_INVALID_TEMPLATE_INSTANTIATION, fns);
|
||||
else
|
||||
return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns);
|
||||
}
|
||||
|
||||
int viableCount = 0;
|
||||
for (IFunction f : tmp) {
|
||||
|
|
Loading…
Add table
Reference in a new issue