mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix bug 45129
- function to pointer conversion - fix loop in argument deduction of template arguments from function types
This commit is contained in:
parent
bac2cf5297
commit
7aef086165
4 changed files with 54 additions and 0 deletions
|
@ -3642,5 +3642,27 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
IFunction f = (IFunction) col.getName(0).resolveBinding();
|
||||
assertInstances( col, f, 2 );
|
||||
}
|
||||
|
||||
public void testBug45129() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void f( int (*pf) (char) ); \n"); //$NON-NLS-1$
|
||||
buffer.append("int g( char ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void foo () { \n"); //$NON-NLS-1$
|
||||
buffer.append(" f( g ) ; \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunction f1 = (ICPPFunction) col.getName(0).resolveBinding();
|
||||
ICPPFunction g1 = (ICPPFunction) col.getName(3).resolveBinding();
|
||||
|
||||
IBinding f2 = col.getName(6).resolveBinding();
|
||||
IBinding g2 = col.getName(7).resolveBinding();
|
||||
|
||||
assertSame( f1, f2 );
|
||||
assertSame( g1, g2 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
|
@ -754,4 +755,27 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
assertTrue( y2 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)y2).getOriginalBinding(), Y );
|
||||
}
|
||||
|
||||
public void testBug45129() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template < class T, class U > void f ( T (*) ( T, U ) ); \n"); //$NON-NLS-1$
|
||||
buffer.append("int g ( int, char ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void foo () { \n"); //$NON-NLS-1$
|
||||
buffer.append(" f( g ); \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunction f1 = (ICPPFunction) col.getName(2).resolveBinding();
|
||||
ICPPFunction g1 = (ICPPFunction) col.getName(9).resolveBinding();
|
||||
|
||||
IBinding f2 = col.getName(13).resolveBinding();
|
||||
IBinding g2 = col.getName(14).resolveBinding();
|
||||
|
||||
assertTrue( f2 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f1 );
|
||||
assertSame( g1, g2 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2337,6 +2337,13 @@ public class CPPSemantics {
|
|||
cost.targetHadReference = true;
|
||||
}
|
||||
|
||||
//4.3 function to pointer conversion
|
||||
if( target instanceof IPointerType && ((IPointerType)target).getType() instanceof IFunctionType &&
|
||||
source instanceof IFunctionType )
|
||||
{
|
||||
source = new CPPPointerType( source );
|
||||
}
|
||||
|
||||
cost.source = source;
|
||||
cost.target = target;
|
||||
|
||||
|
|
|
@ -859,6 +859,7 @@ public class CPPTemplates {
|
|||
if( !deduceTemplateArgument( map, pParams[i], aParams[i] ) )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else if( p instanceof ICPPTemplateParameter ){
|
||||
if( map.containsKey( p ) ){
|
||||
IType current = (IType)map.get( p );
|
||||
|
|
Loading…
Add table
Reference in a new issue