From 73b13e31285f150343e47e479e5653794f00dff4 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Wed, 7 May 2008 11:27:05 +0000 Subject: [PATCH] disallow using a template name as a type name in a simple declaration --- .../parser/tests/ast2/AST2TemplateTests.java | 2 +- .../core/suite/AutomatedIntegrationSuite.java | 9 --------- .../dom/parser/cpp/semantics/CPPSemantics.java | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index fc1db65400e..c7a400c4190 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -2474,7 +2474,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // C c1; // C<> c2; // ok - default args - public void _testMissingTemplateArgumentLists() throws Exception { + public void testMissingTemplateArgumentLists() throws Exception { BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true); ba.assertProblem("B b1", 1); ba.assertNonProblem("B<> b2", 1, ICPPTemplateDefinition.class, ICPPClassType.class); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index cc6486a9fb5..571a9aea566 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -10,12 +10,6 @@ * Markus Schorn (Wind River Systems) * 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; import junit.framework.Test; @@ -38,9 +32,6 @@ import org.eclipse.cdt.internal.pdom.tests.PDOMTests; /** * @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 { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index eb5b0169a4e..5d9b3c544ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -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) { ASTNodeProperty prop = data.astName.getPropertyInParent(); if (prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME && @@ -256,7 +259,20 @@ public class CPPSemantics { } 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) { ICPPClassType cls = (ICPPClassType) binding; if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) {