mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 90666, fix class cast execption
This commit is contained in:
parent
7c7ae6fd68
commit
8ec23b43cc
3 changed files with 54 additions and 44 deletions
|
@ -761,27 +761,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 12.8-3d):
|
||||
void h(int());
|
||||
void h(int (*)()); // redeclaration of h(int())
|
||||
void h(int x()) { } // definition of h(int())
|
||||
void h(int (*x)()) { } // illformed: redefinition of h(int())
|
||||
--End Example]
|
||||
*/
|
||||
public void test12_8s3d() { // TODO Devin raised bug 90666
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void h(int());\n"); //$NON-NLS-1$
|
||||
buffer.append("void h(int (*)()); // redeclaration of h(int())\n"); //$NON-NLS-1$
|
||||
buffer.append("void h(int x()) { } // definition of h(int())\n"); //$NON-NLS-1$
|
||||
buffer.append("void h(int (*x)()) { } // illformed: redefinition of h(int())\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 13.3.3.2-3c):
|
||||
struct A {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
|
@ -7325,6 +7326,27 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(buffer.toString(), ParserLanguage.CPP, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 12.8-3d):
|
||||
void h(int());
|
||||
void h(int (*)()); // redeclaration of h(int())
|
||||
void h(int x()) { } // definition of h(int())
|
||||
void h(int (*x)()) { } // illformed: redefinition of h(int())
|
||||
--End Example]
|
||||
*/
|
||||
public void test12_8s3d() { // TODO assert redefinition problem
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void h(int());\n"); //$NON-NLS-1$
|
||||
buffer.append("void h(int (*)()); // redeclaration of h(int())\n"); //$NON-NLS-1$
|
||||
buffer.append("void h(int x()) { } // definition of h(int())\n"); //$NON-NLS-1$
|
||||
buffer.append("void h(int (*x)()) { } // illformed: redefinition of h(int())\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 12.8-4a):
|
||||
struct X {
|
||||
|
@ -7495,14 +7517,18 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
void f(Int i) { } // error: redefinition of f(int)
|
||||
--End Example]
|
||||
*/
|
||||
public void test12_1s3a() throws Exception {
|
||||
public void test12_1s3a() throws Exception { //TODO better assert of expected redefinition problem
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("typedef int Int;\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(int i);\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(Int i); // OK: redeclaration of f(int)\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(int i) { }\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(Int i) { } // error: redefinition of f(int)\n"); //$NON-NLS-1$
|
||||
try{
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
} catch ( ParserException e ){
|
||||
assertEquals( e.getMessage(), "found IProblemBinding" ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -461,14 +461,36 @@ public class CPPVisitor {
|
|||
binding = null;
|
||||
}
|
||||
|
||||
if( declarator instanceof ICPPASTFunctionDeclarator ){
|
||||
if( parent instanceof ICPPASTParameterDeclaration ){
|
||||
ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent;
|
||||
parent = param.getParent();
|
||||
if( parent instanceof IASTStandardFunctionDeclarator ) {
|
||||
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||
if( fDtor.getParent() instanceof IASTDeclarator || fDtor.getNestedDeclarator() != null )
|
||||
return null;
|
||||
IBinding temp = fDtor.getName().resolveBinding();
|
||||
if( temp instanceof CPPFunction ){
|
||||
CPPFunction function = (CPPFunction) temp;
|
||||
binding = function.resolveParameter( param );
|
||||
} else if( temp instanceof CPPFunctionTemplate ) {
|
||||
binding = ((CPPFunctionTemplate)temp).resolveFunctionParameter( param );
|
||||
}
|
||||
} else if( parent instanceof ICPPASTTemplateDeclaration ) {
|
||||
return CPPTemplates.createBinding( param );
|
||||
}
|
||||
} else if( declarator instanceof ICPPASTFunctionDeclarator ){
|
||||
if( binding != null && binding instanceof IFunction ){
|
||||
IFunction function = (IFunction) binding;
|
||||
if( CPPSemantics.isSameFunction( function, declarator ) ){
|
||||
ICPPInternalBinding internal = (ICPPInternalBinding) function;
|
||||
if( parent instanceof IASTSimpleDeclaration )
|
||||
((ICPPInternalBinding)function).addDeclaration( name );
|
||||
else
|
||||
internal.addDeclaration( name );
|
||||
else {
|
||||
if( internal.getDefinition() == null )
|
||||
((ICPPInternalBinding)function).addDefinition( name );
|
||||
else
|
||||
return new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() );
|
||||
}
|
||||
|
||||
return function;
|
||||
}
|
||||
|
@ -487,23 +509,6 @@ public class CPPVisitor {
|
|||
binding = template ? (ICPPFunction) new CPPFunctionTemplate( name )
|
||||
: new CPPFunction( (ICPPASTFunctionDeclarator) declarator );
|
||||
}
|
||||
} else if( parent instanceof ICPPASTParameterDeclaration ){
|
||||
ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent;
|
||||
parent = param.getParent();
|
||||
if( parent instanceof IASTStandardFunctionDeclarator ) {
|
||||
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||
if( fDtor.getParent() instanceof IASTDeclarator || fDtor.getNestedDeclarator() != null )
|
||||
return null;
|
||||
IBinding temp = fDtor.getName().resolveBinding();
|
||||
if( temp instanceof CPPFunction ){
|
||||
CPPFunction function = (CPPFunction) temp;
|
||||
binding = function.resolveParameter( param );
|
||||
} else if( temp instanceof CPPFunctionTemplate ) {
|
||||
binding = ((CPPFunctionTemplate)temp).resolveFunctionParameter( param );
|
||||
}
|
||||
} else if( parent instanceof ICPPASTTemplateDeclaration ) {
|
||||
return CPPTemplates.createBinding( param );
|
||||
}
|
||||
} else if( parent instanceof IASTSimpleDeclaration ){
|
||||
|
||||
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent;
|
||||
|
|
Loading…
Add table
Reference in a new issue