1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Name lookup in constructor chain initializers, bug 293566.

This commit is contained in:
Markus Schorn 2009-10-28 13:50:40 +00:00
parent 5e934ed6a5
commit 92305bfbd9
3 changed files with 31 additions and 10 deletions

View file

@ -7589,5 +7589,24 @@ public class AST2CPPTests extends AST2BaseTest {
final String code = getAboveComment(); final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP); parseAndCheckBindings(code, ParserLanguage.CPP);
} }
// template <typename T> struct CT {
// CT(int) {}
// };
// namespace ns {
// typedef int B;
// struct A : CT<B>{
// A();
// };
// }
//
// ns::A::A() : CT<B>(1) {
// }
public void testLookupInConstructorChainInitializer_293566() throws Exception {
final String code = getAboveComment();
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
bh.assertNonProblem("B>(1)", 1);
parseAndCheckBindings(code, ParserLanguage.CPP);
}
} }

View file

@ -651,12 +651,6 @@ public class CPPSemantics {
n = ((ICPPASTQualifiedName) n).getLastName(); n = ((ICPPASTQualifiedName) n).getLastName();
} }
scope = CPPVisitor.getContainingScope(n); scope = CPPVisitor.getContainingScope(n);
} else if (parent instanceof ICPPASTConstructorChainInitializer) {
ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) parent;
IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent();
IBinding binding = fdef.getDeclarator().getName().resolveBinding();
if (!(binding instanceof IProblemBinding))
scope = binding.getScope();
} else { } else {
scope = CPPVisitor.getContainingScope(name, data); scope = CPPVisitor.getContainingScope(name, data);
} }

View file

@ -60,6 +60,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
@ -108,7 +109,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
@ -812,7 +812,15 @@ public class CPPVisitor extends ASTQueries {
return getContainingScope(ns[ns.length - 1]); return getContainingScope(ns[ns.length - 1]);
} }
} }
} else if (node instanceof IASTExpression) { } else if (node instanceof ICPPASTConstructorChainInitializer) {
ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) node;
IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent();
IBinding binding = fdef.getDeclarator().getName().resolveBinding();
try {
return binding.getScope();
} catch (DOMException e) {
}
} else if (node instanceof IASTExpression) {
IASTNode parent = node.getParent(); IASTNode parent = node.getParent();
if (parent instanceof IASTForStatement) { if (parent instanceof IASTForStatement) {
return ((IASTForStatement) parent).getScope(); return ((IASTForStatement) parent).getScope();
@ -1763,7 +1771,7 @@ public class CPPVisitor extends ASTQueries {
} }
} catch (DOMException e) { } catch (DOMException e) {
} }
basicType= new CPPBasicType(Kind.eInt, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED); basicType= new CPPBasicType(Kind.eInt, IBasicType.IS_LONG | IBasicType.IS_UNSIGNED);
basicType.setFromExpression(binary); basicType.setFromExpression(binary);
return basicType; return basicType;
} }
@ -1795,7 +1803,7 @@ public class CPPVisitor extends ASTQueries {
} }
} catch (DOMException e) { } catch (DOMException e) {
} }
return new CPPBasicType(Kind.eInt, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED); return new CPPBasicType(Kind.eInt, IBasicType.IS_LONG | IBasicType.IS_UNSIGNED);
} }
public static IASTProblem[] getProblems(IASTTranslationUnit tu) { public static IASTProblem[] getProblems(IASTTranslationUnit tu) {