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 94e3ca4eb51..f3152eacb42 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 @@ -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 { 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 e640ccd732c..0d2192dc78b 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 @@ -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$ - parse(buffer.toString(), ParserLanguage.CPP, false, true); + try{ + parse(buffer.toString(), ParserLanguage.CPP, false, true); + } catch ( ParserException e ){ + assertEquals( e.getMessage(), "found IProblemBinding" ); //$NON-NLS-1$ + } } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 13ac731caf0..8e3c54d6d81 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -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 - ((ICPPInternalBinding)function).addDefinition( name ); + 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;