From 7affbb771e8d3890e440225183954702d48c9794 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Fri, 30 Sep 2011 14:13:18 +0200 Subject: [PATCH] Bug 359376: Updating implicit ctors in index. --- .../index/tests/IndexUpdateTests.java | 31 +++++++++++++++++++ .../core/pdom/dom/cpp/PDOMCPPLinkage.java | 14 +++++++++ .../core/pdom/dom/cpp/PDOMCPPMethod.java | 9 ++++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java index 879b11ef2e2..2f9a59e801a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java @@ -1432,5 +1432,36 @@ public class IndexUpdateTests extends IndexTestBase { fIndex.releaseReadLock(); } } + + // struct S {}; + + // struct S {S(int){}}; + public void testImplicitDefaultCtor_Bug359376() throws Exception { + setupFile(2, true); + fIndex.acquireReadLock(); + try { + final ICPPClassType s = (ICPPClassType) findBinding("S"); + assertNotNull(s); + final ICPPConstructor[] ctors = s.getConstructors(); + assertEquals(2, ctors.length); // 2 implicit ctors + assertTrue(ctors[0].isImplicit()); + assertTrue(ctors[1].isImplicit()); + } finally { + fIndex.releaseReadLock(); + } + updateFile(); + + fIndex.acquireReadLock(); + try { + final ICPPClassType s = (ICPPClassType) findBinding("S"); + assertNotNull(s); + final ICPPConstructor[] ctors = s.getConstructors(); + assertEquals(2, ctors.length); // 1 explicit and one implicit ctor + assertTrue(ctors[0].isImplicit() != ctors[1].isImplicit()); + } finally { + fIndex.releaseReadLock(); + } + } + } 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 8b7dab40caf..eb3c04ceb0e 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 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; +import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -473,6 +475,13 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { final long fileLocalRec= type.getLocalToFileRec(); IScope scope = binding.getCompositeScope(); if (scope instanceof ICPPClassScope) { + List old= new ArrayList(); + if (type instanceof ICPPClassType) { + IScope oldScope = ((ICPPClassType)type).getCompositeScope(); + if (oldScope instanceof ICPPClassScope) { + old.addAll(Arrays.asList(((ICPPClassScope) oldScope).getImplicitMethods())); + } + } ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods(); for (ICPPMethod method : implicit) { if (!(method instanceof IProblemBinding)) { @@ -481,9 +490,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { pdomBinding = createBinding(type, method, fileLocalRec); } else if (!getPDOM().hasLastingDefinition(pdomBinding)) { pdomBinding.update(this, method); + old.remove(pdomBinding); } } } + for (ICPPMethod method : old) { + if (method instanceof PDOMBinding) + ((PDOMBinding) method).update(this, null); + } } } catch (DOMException e) { CCorePlugin.log(e); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java index 0a5d2e03466..9262f137782 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 QNX Software Systems and others. + * Copyright (c) 2006, 2011 QNX Software Systems 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 @@ -80,7 +80,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod { } @Override - public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException { + public final void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException { if (newBinding instanceof ICPPMethod) { ICPPMethod method= (ICPPMethod) newBinding; super.update(linkage, newBinding); @@ -92,6 +92,11 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod { } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); } + } else if (newBinding == null && isImplicit()) { + // Clear the implicit flag, such that the binding will no longer be picked up. + byte annot= (byte) (getAnnotation1() ^ (1 << PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET)); + getDB().putByte(record + ANNOTATION1, annot); + annotation1= annot; } }