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 a09d97679de..0ac4d60d070 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 @@ -7276,4 +7276,17 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } + + // void func(int* obj) { + // int* obj = 0; + // } + public void testParameterRedeclaration_301779() throws Exception { + final String code = getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + bh.assertNonProblem("obj", 3, IParameter.class); + bh.assertProblem("obj =", 3); + bh= new BindingAssertionHelper(code, false); + bh.assertNonProblem("obj", 3, IParameter.class); + bh.assertProblem("obj =", 3); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index 599e7495cfe..e4de53cd6f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,8 +27,8 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.Linkage; @@ -272,11 +272,13 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI for (int i = 0; i < ns.length && ns[i] != null; i++) { IASTNode parent = ns[i].getParent(); - while (!(parent instanceof IASTParameterDeclaration)) + while (parent != null && !(parent instanceof IASTParameterDeclaration)) parent = parent.getParent(); - IASTDeclSpecifier declSpec = ((IASTParameterDeclaration) parent).getDeclSpecifier(); - if (declSpec.getStorageClass() == storage) - return true; + if (parent != null) { + IASTDeclSpecifier declSpec = ((IASTParameterDeclaration) parent).getDeclSpecifier(); + if (declSpec.getStorageClass() == storage) + return true; + } } return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 35e9eb8beb7..bdc3b98b0ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -610,7 +610,7 @@ public class CPPVisitor extends ASTQueries { } else if (parent instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent; if (simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { - // typedef declaration + // Typedef declaration if (binding instanceof ICPPInternalBinding && binding instanceof ITypedef && name.isActive()) { IType t1 = ((ITypedef) binding).getType(); IType t2 = createType(declarator); @@ -620,23 +620,26 @@ public class CPPVisitor extends ASTQueries { } return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); } - // if we don't resolve the target type first, we get a problem binding in case the typedef + // If we don't resolve the target type first, we get a problem binding in case the typedef // redeclares the target type, otherwise it is safer to defer the resolution of the target type. IType targetType= createType(declarator); CPPTypedef td= new CPPTypedef(name); td.setType(targetType); binding = td; } else if (typeRelevantDtor instanceof IASTFunctionDeclarator) { - // function declaration + // Function declaration via function declarator isFunction= true; } else { - // looks like a variable declaration + // Looks like a variable declaration IType t1 = createType(declarator); if (SemanticUtil.getNestedType(t1, TDEF) instanceof IFunctionType) { - // function declaration with typedef + // Function declaration via a typedef for a function type isFunction= true; + } else if (binding instanceof IParameter) { + // Variable declaration redeclaring a parameter + binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); } else { - // variable declaration + // Variable declaration IType t2= null; if (binding != null && binding instanceof IVariable && !(binding instanceof IIndexBinding)) { try {