1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

Bug 508254 - Variable initializer that references the variable

Change-Id: Ic5b0692db297dead087e4c8479fa0c0f134554da
This commit is contained in:
Nathan Ridge 2016-12-01 22:21:12 -05:00
parent 17ed6bead8
commit 63e6688940
4 changed files with 45 additions and 4 deletions

View file

@ -62,7 +62,7 @@ import junit.framework.TestSuite;
* additionally check that the binding obtained has characteristics as
* expected (type,name,etc..)
*/
public abstract class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase {
public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase {
public static class SingleProject extends IndexCPPBindingResolutionTest {
public SingleProject() { setStrategy(new SinglePDOMTestStrategy(true)); }
@ -78,6 +78,11 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
suite.addTest(SingleProject.suite());
suite.addTest(ProjectWithDepProj.suite());
}
public IndexCPPBindingResolutionTest() {
setStrategy(new SinglePDOMTestStrategy(true));
}
public static TestSuite suite() { return suite(SingleProject.class); }
/* Assertion helpers */
/* ##################################################################### */
@ -1927,6 +1932,18 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
public void testNameLookupFromArrayModifier_435075() {
checkBindings();
}
// struct S {
// int* a;
// int* b;
// };
//
// constexpr S waldo = { nullptr, waldo.a };
// // empty file
public void testVariableInitializerThatReferencesVariable_508254() throws Exception {
checkBindings();
}
// class NonVirt {
// void m();

View file

@ -33,7 +33,7 @@ class PDOMCPPField extends PDOMCPPVariable implements ICPPField {
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = FIELD_POSITION_OFFSET + 2;
public PDOMCPPField(PDOMLinkage linkage, PDOMNode parent, ICPPField field, boolean setTypeAndValue)
public PDOMCPPField(PDOMCPPLinkage linkage, PDOMNode parent, ICPPField field, boolean setTypeAndValue)
throws CoreException {
super(linkage, parent, field, setTypeAndValue);
setFieldPosition(field);

View file

@ -225,6 +225,22 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
// Binding types
class ConfigureVariable implements Runnable {
private final PDOMCPPVariable fVariable;
private final IValue fInitialValue;
public ConfigureVariable(ICPPVariable original, PDOMCPPVariable variable) {
fVariable = variable;
fInitialValue = original.getInitialValue();
postProcesses.add(this);
}
@Override
public void run() {
fVariable.initData(fInitialValue);
}
}
class ConfigureTemplateParameters implements Runnable {
private final IPDOMCPPTemplateParameter[] fPersisted;
private final ICPPTemplateParameter[] fOriginal;

View file

@ -40,7 +40,7 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = ANNOTATIONS + 1;
public PDOMCPPVariable(PDOMLinkage linkage, PDOMNode parent, ICPPVariable variable, boolean setTypeAndValue)
public PDOMCPPVariable(PDOMCPPLinkage linkage, PDOMNode parent, ICPPVariable variable, boolean setTypeAndValue)
throws CoreException {
super(linkage, parent, variable.getNameCharArray());
@ -49,7 +49,15 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
db.putByte(record + ANNOTATIONS, PDOMCPPAnnotations.encodeVariableAnnotations(variable));
if (setTypeAndValue) {
setType(parent.getLinkage(), variable.getType());
setValue(variable.getInitialValue());
linkage.new ConfigureVariable(variable, this);
}
}
public void initData(IValue initialValue) {
try {
setValue(initialValue);
} catch (CoreException e) {
CCorePlugin.log(e);
}
}