mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 301779: Re-declaration of parameter as variable.
This commit is contained in:
parent
a65e64eb06
commit
255de3a80b
3 changed files with 30 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue