From a2ed1fa490cd0aeef4b06d5f3173ef1f0638b329 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Tue, 22 Mar 2005 19:57:24 +0000 Subject: [PATCH] bugs 88338, 88501, 88459 --- .../core/parser/tests/ast2/AST2CPPTests.java | 39 +++++++++++++++++ .../core/parser/tests/ast2/AST2KnRTests.java | 10 ++--- .../cdt/core/parser/tests/ast2/AST2Tests.java | 42 +++++++++++++++++++ .../cdt/core/dom/ast/IProblemBinding.java | 10 +++++ .../core/dom/parser/ProblemBinding.java | 2 + .../parser/c/CASTElaboratedTypeSpecifier.java | 28 +++++++++++-- .../internal/core/dom/parser/c/CFunction.java | 2 +- .../core/dom/parser/c/CStructure.java | 2 +- .../internal/core/dom/parser/c/CVariable.java | 2 +- ...{ICBinding.java => ICInternalBinding.java} | 2 +- .../cpp/CPPASTElaboratedTypeSpecifier.java | 28 ++++++++++++- .../core/dom/parser/cpp/CPPFunction.java | 12 +++--- .../core/dom/parser/cpp/CPPVisitor.java | 10 +++-- .../core/parser/ParserMessages.properties | 2 + 14 files changed, 169 insertions(+), 22 deletions(-) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/{ICBinding.java => ICInternalBinding.java} (95%) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index c3dc4180551..a9a083d565f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -3027,6 +3027,45 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals( C.getID(), IProblemBinding.SEMANTIC_BAD_SCOPE ); } + public void testBug88459() throws Exception { + IASTTranslationUnit tu = parse( "int f(); ", ParserLanguage.CPP ); //$NON-NLS-1$ + CPPNameCollector col = new CPPNameCollector(); + tu.accept( col ); + + IFunction f = (IFunction) col.getName(0).resolveBinding(); + assertFalse( f.isStatic() ); + } + + public void testBug88501_1() throws Exception { + IASTTranslationUnit tu = parse( "void f(); void f( int ); struct f;", ParserLanguage.CPP ); //$NON-NLS-1$ + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertTrue( col.getName(0).resolveBinding() instanceof IFunction ); + assertTrue( col.getName(1).resolveBinding() instanceof IFunction ); + assertTrue( col.getName(3).resolveBinding() instanceof ICPPClassType ); + } + +// public void testBug8342_1() throws Exception { +// IASTTranslationUnit tu = parse( "int a; int a;", ParserLanguage.CPP ); //$NON-NLS-1$ +// CPPNameCollector col = new CPPNameCollector(); +// tu.accept(col); +// +// assertTrue( col.getName(0).resolveBinding() instanceof IVariable ); +// IProblemBinding p = (IProblemBinding) col.getName(1).resolveBinding(); +// assertEquals( p.getID(), IProblemBinding.SEMANTIC_INVALID_REDEFINITION ); +// } + + public void testBug8342_2() throws Exception { + IASTTranslationUnit tu = parse( "extern int a; extern char a;", ParserLanguage.CPP ); //$NON-NLS-1$ + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertTrue( col.getName(0).resolveBinding() instanceof IVariable ); + IProblemBinding p = (IProblemBinding) col.getName(1).resolveBinding(); + assertEquals( p.getID(), IProblemBinding.SEMANTIC_INVALID_REDECLARATION ); + } + public void testNamespaceAlias_2() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("namespace A { int i; } \n"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java index f8a57fa956c..f0d73a7add4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java @@ -46,7 +46,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.c.CParameter; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.c.ICBinding; +import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding; /** * @author dsteffle @@ -453,7 +453,7 @@ public class AST2KnRTests extends AST2BaseTest { IASTName A_struct_name1 = ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName(); assertEquals( A_struct_name1.toString(), "A_struct" ); //$NON-NLS-1$ ICompositeType A_struct_type1 = (ICompositeType)A_struct_name1.resolveBinding(); - assertEquals( ((ICBinding)A_struct_type1).getPhysicalNode(), A_struct.getDeclSpecifier() ); + assertEquals( ((ICInternalBinding)A_struct_type1).getPhysicalNode(), A_struct.getDeclSpecifier() ); IField[] fields = A_struct_type1.getFields(); IField a1 = fields[0]; IField c1 = fields[1]; @@ -516,7 +516,7 @@ public class AST2KnRTests extends AST2BaseTest { IASTExpressionStatement stmt1 = (IASTExpressionStatement)f_def_body.getStatements()[0]; IASTExpressionStatement stmt2 = (IASTExpressionStatement)f_def_body.getStatements()[1]; IASTName a2 = ((IASTFieldReference)((IASTBinaryExpression)stmt1.getExpression()).getOperand1()).getFieldName(); - assertEquals( ((IASTName)((ICBinding)a1).getPhysicalNode()).resolveBinding(), a2.resolveBinding() ); + assertEquals( ((IASTName)((ICInternalBinding)a1).getPhysicalNode()).resolveBinding(), a2.resolveBinding() ); IASTName x3 = ((IASTIdExpression)((IASTFieldReference)((IASTBinaryExpression)stmt1.getExpression()).getOperand1()).getFieldOwner()).getName(); assertEquals( x2.resolveBinding(), x3.resolveBinding() ); assertEquals( ((IASTBinaryExpression)stmt1.getExpression()).getOperand2().toString(), "0" ); //$NON-NLS-1$ @@ -526,8 +526,8 @@ public class AST2KnRTests extends AST2BaseTest { IASTName x4 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName(); IASTName c3 = ((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand2()).getArrayExpression()).getFieldName(); IASTName x5 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName(); - assertEquals( ((IASTName)((ICBinding)c1).getPhysicalNode()).resolveBinding(), c2.resolveBinding() ); - assertEquals( ((IASTName)((ICBinding)c1).getPhysicalNode()).resolveBinding(), c3.resolveBinding() ); + assertEquals( ((IASTName)((ICInternalBinding)c1).getPhysicalNode()).resolveBinding(), c2.resolveBinding() ); + assertEquals( ((IASTName)((ICInternalBinding)c1).getPhysicalNode()).resolveBinding(), c3.resolveBinding() ); assertEquals( x3.resolveBinding(), x4.resolveBinding() ); assertEquals( x4.resolveBinding(), x5.resolveBinding() ); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index c35e7839d78..4cfb54ec962 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -2960,4 +2960,46 @@ public class AST2Tests extends AST2BaseTest { assertEquals( prob.getID(), IProblemBinding.SEMANTIC_INVALID_OVERLOAD ); assertNotNull( foo ); } + + public void testBug88338_CPP() throws Exception { + IASTTranslationUnit tu = parse( "struct A; struct A* a;", ParserLanguage.CPP ); //$NON-NLS-1$ + CPPNameCollector col = new CPPNameCollector(); + tu.accept( col ); + + assertTrue( col.getName(0).isDeclaration() ); + assertFalse( col.getName(0).isReference() ); + assertTrue( col.getName(1).isReference() ); + assertFalse( col.getName(1).isDeclaration() ); + + tu = parse( "struct A* a;", ParserLanguage.CPP ); //$NON-NLS-1$ + col = new CPPNameCollector(); + tu.accept( col ); + + assertTrue( col.getName(0).isDeclaration() ); + assertFalse( col.getName(0).isReference() ); + + } + + public void testBug88338_C() throws Exception { + IASTTranslationUnit tu = parse( "struct A; struct A* a;", ParserLanguage.C ); //$NON-NLS-1$ + CPPNameCollector col = new CPPNameCollector(); + tu.accept( col ); + + assertTrue( col.getName(0).isDeclaration() ); + assertFalse( col.getName(0).isReference() ); + assertTrue( col.getName(1).isReference() ); + assertFalse( col.getName(1).isDeclaration() ); + + tu = parse( "struct A* a; struct A;", ParserLanguage.C ); //$NON-NLS-1$ + col = new CPPNameCollector(); + tu.accept( col ); + + col.getName(2).resolveBinding(); + + assertTrue( col.getName(0).isDeclaration() ); + assertFalse( col.getName(0).isReference() ); + + assertTrue( col.getName(2).isDeclaration() ); + assertFalse( col.getName(2).isReference() ); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java index 8ce3e0528fa..bf8bca490e2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java @@ -98,5 +98,15 @@ public interface IProblemBinding extends IBinding, IScope, IType { */ public static final int SEMANTIC_BAD_SCOPE = 0x00A; + /** + * invalid redefinition of the name + */ + public static final int SEMANTIC_INVALID_REDEFINITION = 0x00B; + + /** + * invalid redeclaration of the name + */ + public static final int SEMANTIC_INVALID_REDECLARATION = 0x00C; + public static final int LAST_PROBLEM = SEMANTIC_BAD_SCOPE; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index 2636f31daff..809b8e099a6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -52,6 +52,8 @@ public class ProblemBinding implements IProblemBinding, IType, IScope { errorMessages[SEMANTIC_DEFINITION_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.definitionNotFound"); //$NON-NLS-1$ errorMessages[SEMANTIC_KNR_PARAMETER_DECLARATION_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.knrParameterDeclarationNotFound"); //$NON-NLS-1$ errorMessages[SEMANTIC_LABEL_STATEMENT_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.labelStatementNotFound"); //$NON-NLS-1$ + errorMessages[SEMANTIC_INVALID_REDEFINITION - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.invalidRedefinition"); //$NON-NLS-1$ + errorMessages[SEMANTIC_INVALID_REDECLARATION - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.invalidRedeclaration"); //$NON-NLS-1$ errorMessages[SEMANTIC_BAD_SCOPE - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.badScope"); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java index 4334bc397b7..9494926f39c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java @@ -10,7 +10,12 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; /** @@ -66,8 +71,25 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName) */ public int getRoleForName(IASTName n ) { - if( this.name == n ) - return r_declaration; - return r_unclear; + if( n != name ) return r_unclear; + + IASTNode parent = getParent(); + if( !( parent instanceof IASTDeclaration ) ) + return r_reference; + + if( parent instanceof IASTSimpleDeclaration ){ + IASTDeclarator [] dtors = ((IASTSimpleDeclaration)parent).getDeclarators(); + if( dtors.length == 0 ) + return r_declaration; + } + + //can't tell, resolve the binding + IBinding binding = name.resolveBinding(); + if( binding instanceof ICInternalBinding ){ + IASTNode node = ((ICInternalBinding)binding).getPhysicalNode(); + if( node == this ) + return r_declaration; + } + return r_reference; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 52eb5b2808c..b4a7faebd72 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -37,7 +37,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; * Created on Nov 5, 2004 * @author aniefer */ -public class CFunction implements IFunction, ICBinding { +public class CFunction implements IFunction, ICInternalBinding { private IASTStandardFunctionDeclarator [] declarators = null; private IASTFunctionDeclarator definition; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java index 9146778a7a0..a01b5298b65 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java @@ -33,7 +33,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; * Created on Nov 8, 2004 * @author aniefer */ -public class CStructure implements ICompositeType, ICBinding { +public class CStructure implements ICompositeType, ICInternalBinding { private IASTElaboratedTypeSpecifier[] declarations = null; private ICASTCompositeTypeSpecifier definition; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java index f62a7a81e17..0aa66c08fc7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; * Created on Nov 5, 2004 * @author aniefer */ -public class CVariable implements IVariable, ICBinding { +public class CVariable implements IVariable, ICInternalBinding { public static class CVariableProblem extends ProblemBinding implements IVariable { public CVariableProblem( int id, char[] arg ) { super( id, arg ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalBinding.java similarity index 95% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICBinding.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalBinding.java index 295a701d63a..34d278730e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalBinding.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; /** * @author aniefer */ -public interface ICBinding { +public interface ICInternalBinding { //methods needed by CVisitor but not meant for public interface public IASTNode getPhysicalNode(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java index eb525779a5c..ab005cdae54 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java @@ -11,8 +11,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -67,7 +73,25 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName) */ public int getRoleForName(IASTName n) { - if( n == name ) return r_reference; //TODO is this right? - return r_unclear; + if( n != name ) return r_unclear; + + IASTNode parent = getParent(); + if( !( parent instanceof IASTDeclaration ) ) + return r_reference; + + if( parent instanceof IASTSimpleDeclaration ){ + IASTDeclarator [] dtors = ((IASTSimpleDeclaration)parent).getDeclarators(); + if( dtors.length == 0 ) + return r_declaration; + } + + //can't tell, resolve the binding + IBinding binding = name.resolveBinding(); + if( binding instanceof ICPPInternalBinding ){ + IASTNode [] decls = ((ICPPInternalBinding)binding).getDeclarations(); + if( ArrayUtil.contains( decls, name ) ) + return r_declaration; + } + return r_reference; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index c6cfcf36f38..ce89d99b75c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -352,12 +352,14 @@ public class CPPFunction implements ICPPFunction, ICPPInternalBinding { int state = ( bits & IS_STATIC ) >> 2; if( state > 1 ) return (state % 2 != 0); - + IASTDeclSpecifier declSpec = null; IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getDefinition(); - IASTDeclSpecifier declSpec = ((IASTFunctionDefinition)dtor.getParent()).getDeclSpecifier(); - if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ){ - bits |= 3 << 2; - return true; + if( dtor != null ){ + declSpec = ((IASTFunctionDefinition)dtor.getParent()).getDeclSpecifier(); + if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ){ + bits |= 3 << 2; + return true; + } } IASTFunctionDeclarator[] dtors = (IASTFunctionDeclarator[]) getDeclarations(); 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 e876eab5000..44d653566d8 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 @@ -294,7 +294,7 @@ public class CPPVisitor { } try { binding = scope.getBinding( elabType.getName(), false ); - if( binding == null ){ + if( binding == null || !(binding instanceof ICPPClassType) ){ if( elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum ){ binding = new CPPClassType( elabType.getName() ); scope.addName( elabType.getName() ); @@ -468,8 +468,12 @@ public class CPPVisitor { } catch ( DOMException e1 ) { } } - if( t1 != null && t2 != null && t1.equals( t2 ) ){ - ((CPPVariable)binding).addDeclaration( declarator.getName() ); + if( t1 != null && t2 != null ){ + if( t1.equals( t2 ) ){ + ((CPPVariable)binding).addDeclaration( declarator.getName() ); + } else { + binding = new ProblemBinding( IProblemBinding.SEMANTIC_INVALID_REDECLARATION, declarator.getName().toCharArray() ); + } } else if( simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier ){ binding = new CPPField( declarator.getName() ); } else { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties index 838f3eee153..ce6339198be 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties @@ -80,4 +80,6 @@ ASTProblemFactory.error.semantic.pst.recursiveTemplateInstantiation=Possible inf ASTProblemFactory.error.semantic.dom.definitionNotFound=A definition was not found for {0} ASTProblemFactory.error.semantic.dom.knrParameterDeclarationNotFound=A declaration was not found for the k&r parameter {0} ASTProblemFactory.error.semantic.dom.labelStatementNotFound=A label statement was not found for the name {0} +ASTProblemFactory.error.semantic.dom.invalidRedefinition=Invalid redefinition of the name {0} +ASTProblemFactory.error.semantic.dom.invalidRedeclaration=Invalid redeclaration of the name {0} ASTProblemFactory.error.semantic.dom.badScope=A scope could not be created to represent the name {0} \ No newline at end of file