mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
disallow using a template name as a type name in a simple declaration
This commit is contained in:
parent
c2f4ab53ca
commit
73b13e3128
3 changed files with 17 additions and 10 deletions
|
@ -2474,7 +2474,7 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
//
|
//
|
||||||
// C c1;
|
// C c1;
|
||||||
// C<> c2; // ok - default args
|
// C<> c2; // ok - default args
|
||||||
public void _testMissingTemplateArgumentLists() throws Exception {
|
public void testMissingTemplateArgumentLists() throws Exception {
|
||||||
BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true);
|
BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true);
|
||||||
ba.assertProblem("B b1", 1);
|
ba.assertProblem("B b1", 1);
|
||||||
ba.assertNonProblem("B<> b2", 1, ICPPTemplateDefinition.class, ICPPClassType.class);
|
ba.assertNonProblem("B<> b2", 1, ICPPTemplateDefinition.class, ICPPClassType.class);
|
||||||
|
|
|
@ -10,12 +10,6 @@
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Norbert Ploett (Siemens AG)
|
* Norbert Ploett (Siemens AG)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
|
||||||
* Created on May 16, 2003
|
|
||||||
*
|
|
||||||
* To change the template for this generated file go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.suite;
|
package org.eclipse.cdt.core.suite;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
@ -38,9 +32,6 @@ import org.eclipse.cdt.internal.pdom.tests.PDOMTests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author vhirsl
|
* @author vhirsl
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
*/
|
||||||
public class AutomatedIntegrationSuite extends TestSuite {
|
public class AutomatedIntegrationSuite extends TestSuite {
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,9 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 14.6.1-1: Class template name without argument list is equivalent to the injected-class-name followed by
|
||||||
|
* the template-parameters of the class template enclosed in <> */
|
||||||
if (binding instanceof ICPPClassTemplate) {
|
if (binding instanceof ICPPClassTemplate) {
|
||||||
ASTNodeProperty prop = data.astName.getPropertyInParent();
|
ASTNodeProperty prop = data.astName.getPropertyInParent();
|
||||||
if (prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME &&
|
if (prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME &&
|
||||||
|
@ -256,7 +259,20 @@ public class CPPSemantics {
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the class template name is used as a type name in a simple declaration,
|
||||||
|
* outside of the class template scope, mark it as a problem.
|
||||||
|
*/
|
||||||
|
if (binding instanceof ICPPClassTemplate) {
|
||||||
|
IASTNode parent= data.astName.getParent();
|
||||||
|
if(parent instanceof IASTNamedTypeSpecifier) {
|
||||||
|
if(parent.getParent() instanceof IASTSimpleDeclaration) {
|
||||||
|
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binding instanceof ICPPClassType && data.considerConstructors) {
|
if (binding instanceof ICPPClassType && data.considerConstructors) {
|
||||||
ICPPClassType cls = (ICPPClassType) binding;
|
ICPPClassType cls = (ICPPClassType) binding;
|
||||||
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) {
|
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue