From 8468711bacdc0af2f9759dc0e9e17ba4fe114837 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Mon, 2 May 2005 20:06:07 +0000 Subject: [PATCH] fix bug 90673 - template parameter as a target for resolving function references without parameters --- .../tests/ast2/AST2CPPSpecFailingTest.java | 41 ------------------- .../parser/tests/ast2/AST2CPPSpecTest.java | 38 +++++++++++++++++ .../core/dom/parser/cpp/CPPSemantics.java | 29 ++++++++++--- 3 files changed, 62 insertions(+), 46 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java index 84a5bf52957..dd435efaf14 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java @@ -554,47 +554,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { } } - /** - [--Start Example(CPP 14.3.2-5): - template struct X { }; - int ai[10]; - X xi; // array to pointer and qualification conversions - struct Y { }; - template struct Z { }; - Y y; - Z z; // no conversion, but note extra cvqualification - template struct W { }; - int b[5]; - W w; // no conversion - void f(char); - void f(int); - template struct A { }; - A<&f> a; // selects f(int) - --End Example] - */ - public void test14_3_2s5() { // TODO raised bug 90673 - StringBuffer buffer = new StringBuffer(); - buffer.append("template struct X { };\n"); //$NON-NLS-1$ - buffer.append("int ai[10];\n"); //$NON-NLS-1$ - buffer.append("X xi; // array to pointer and qualification conversions\n"); //$NON-NLS-1$ - buffer.append("struct Y { };\n"); //$NON-NLS-1$ - buffer.append("template struct Z { };\n"); //$NON-NLS-1$ - buffer.append("Y y;\n"); //$NON-NLS-1$ - buffer.append("Z z; // no conversion, but note extra cvqualification\n"); //$NON-NLS-1$ - buffer.append("template struct W { };\n"); //$NON-NLS-1$ - buffer.append("int b[5];\n"); //$NON-NLS-1$ - buffer.append("W w; // no conversion\n"); //$NON-NLS-1$ - buffer.append("void f(char);\n"); //$NON-NLS-1$ - buffer.append("void f(int);\n"); //$NON-NLS-1$ - buffer.append("template struct A { };\n"); //$NON-NLS-1$ - buffer.append("A<&f> a; // selects f(int)\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - /** [--Start Example(CPP 14.5.3-1): template class task; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index c725e195f99..d34f56b1d2d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -11795,6 +11795,44 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(buffer.toString(), ParserLanguage.CPP, false, 0); } + /** + [--Start Example(CPP 14.3.2-5): + template struct X { }; + int ai[10]; + X xi; // array to pointer and qualification conversions + struct Y { }; + template struct Z { }; + Y y; + Z z; // no conversion, but note extra cvqualification + template struct W { }; + int b[5]; + W w; // no conversion + void f(char); + void f(int); + template struct A { }; + A<&f> a; // selects f(int) + --End Example] + */ + public void test14_3_2s5() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("template struct X { };\n"); //$NON-NLS-1$ + buffer.append("int ai[10];\n"); //$NON-NLS-1$ + buffer.append("X xi; // array to pointer and qualification conversions\n"); //$NON-NLS-1$ + buffer.append("struct Y { };\n"); //$NON-NLS-1$ + buffer.append("template struct Z { };\n"); //$NON-NLS-1$ + buffer.append("Y y;\n"); //$NON-NLS-1$ + buffer.append("Z z; // no conversion, but note extra cvqualification\n"); //$NON-NLS-1$ + buffer.append("template struct W { };\n"); //$NON-NLS-1$ + buffer.append("int b[5];\n"); //$NON-NLS-1$ + buffer.append("W w; // no conversion\n"); //$NON-NLS-1$ + buffer.append("void f(char);\n"); //$NON-NLS-1$ + buffer.append("void f(int);\n"); //$NON-NLS-1$ + buffer.append("template struct A { };\n"); //$NON-NLS-1$ + buffer.append("A<&f> a; // selects f(int)\n"); //$NON-NLS-1$ + + parse(buffer.toString(), ParserLanguage.CPP, true, 0); + } + /** [--Start Example(CPP 14.5.2-2): template struct A { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index e401ad7682e..60ee157019f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -100,6 +100,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; @@ -2206,16 +2208,33 @@ public class CPPSemantics { return result; } //target is an explicit type conversion -// else if( prop == ICPPASTSimpleTypeConstructorExpression.INITIALIZER_VALUE ) -// { -// -// } - //target is an explicit type conversion else if( prop == IASTCastExpression.OPERAND ) { IASTCastExpression cast = (IASTCastExpression) node.getParent(); return CPPVisitor.createType( cast.getTypeId().getAbstractDeclarator() ); } + //target is a template non-type parameter (14.3.2-5) + else if( prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ){ + ICPPASTTemplateId id = (ICPPASTTemplateId) node.getParent(); + IASTNode [] args = id.getTemplateArguments(); + int i = 0; + for ( ; i < args.length; i++ ) { + if( args[i] == node ){ + break; + } + } + ICPPTemplateDefinition template = (ICPPTemplateDefinition) id.getTemplateName().resolveBinding(); + if( template != null ){ + try { + ICPPTemplateParameter [] ps = template.getTemplateParameters(); + if( i < args.length && i < ps.length && ps[i] instanceof ICPPTemplateNonTypeParameter ){ + return ((ICPPTemplateNonTypeParameter)ps[i]).getType(); + } + } catch ( DOMException e ) { + return null; + } + } + } //target is the return value of a function, operator or conversion else if( prop == IASTReturnStatement.RETURNVALUE ) {