diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 2a5e4b6f252..e0d5039f58f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -17,6 +17,7 @@ import junit.framework.TestSuite; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; @@ -91,7 +92,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // c1.m1("aaa"); // OK // c1.m2("aaa"); // problem // } - public void _testUnindexedConstructorInstanceImplicitReferenceToDeferred() throws Exception { + public void testUnindexedConstructorInstanceImplicitReferenceToDeferred() throws Exception { IBinding b0= getBindingFromASTName("C1 c1", 8); IBinding b1= getBindingFromASTName("m1(\"aaa\")", 2); IBinding b2= getBindingFromASTName("m2(\"aaa\")", 2); @@ -115,6 +116,25 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b0, ICPPMethod.class); } + // template + // class StrT { + // public: void assign(const T* s) {} + // }; + + // void main() { + // StrT x; + // x.assign("aaa"); + // } + public void testUnindexedMethodInstance2() throws Exception { + IBinding b0= getBindingFromASTName("assign(\"aaa\")", 6); + assertInstance(b0, ICPPMethod.class); + assertEquals(1, getIndex().findNames(b0, IIndex.FIND_REFERENCES).length); + IParameter[] parameters = ((ICPPMethod) b0).getParameters(); + System.out.println(String.valueOf(parameters)); + IFunctionType type = ((ICPPMethod) b0).getType(); + System.out.println(String.valueOf(type)); + } + // template // class X {}; @@ -188,7 +208,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // m1("aaa"); // OK // m2("aaa"); // problem // } - public void _testUnindexedConstructorInstanceImplicitReference() throws Exception { + public void testUnindexedConstructorInstanceImplicitReference() throws Exception { IBinding b0= getBindingFromASTName("m1(\"aaa\")", 2); IBinding b1= getBindingFromASTName("m2(\"aaa\")", 2); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 9b9ceddd835..e95a3d3af2f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -9,6 +9,7 @@ * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -224,20 +225,33 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (shouldUpdate(pdomBinding, fromName)) { pdomBinding.update(this, fromName.getBinding()); } - } - else { + } else { try { PDOMNode parent = getAdaptedParent(binding, true, true); if (parent == null) return null; pdomBinding = addBinding(parent, binding); - } catch(DOMException e) { + if (pdomBinding instanceof PDOMCPPClassInstance && binding instanceof ICPPClassType) { + // Add instantiated constructors to the index (bug 201174). + addConstructors(pdomBinding, (ICPPClassType) binding); + } + } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); } } return pdomBinding; } + private void addConstructors(PDOMBinding pdomBinding, ICPPClassType binding) + throws DOMException, CoreException { + ICPPConstructor[] constructors = binding.getConstructors(); + for (int i = 0; i < constructors.length; i++) { + if (adaptBinding(constructors[i]) == null) { + addBinding(pdomBinding, constructors[i]); + } + } + } + private boolean shouldUpdate(PDOMBinding pdomBinding, IASTName fromName) throws CoreException { if (fromName != null) { if (fromName.isReference()) {