mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 510151 Braced default initialization by implicit default constructor
Change-Id: Id9f7dba42d45d1e2d9bd557802eb7669946d242f Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
parent
11de6abfaf
commit
eaa1442345
4 changed files with 39 additions and 10 deletions
|
@ -557,4 +557,34 @@ public class ConstructorTests extends TestBase {
|
||||||
public void testOrderOfFieldInitialization() throws Exception {
|
public void testOrderOfFieldInitialization() throws Exception {
|
||||||
assertEvaluationEquals(10);
|
assertEvaluationEquals(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct S {
|
||||||
|
// int value = 42;
|
||||||
|
// };
|
||||||
|
// constexpr S waldo{23};
|
||||||
|
|
||||||
|
// constexpr int x = waldo.value;
|
||||||
|
public void testDirectInitializedVariable_510151() throws Exception {
|
||||||
|
assertEvaluationEquals(23);
|
||||||
|
}
|
||||||
|
|
||||||
|
// struct S {
|
||||||
|
// int value = 42;
|
||||||
|
// };
|
||||||
|
// constexpr S waldo{};
|
||||||
|
|
||||||
|
// constexpr int x = waldo.value;
|
||||||
|
public void testDirectDefaultInitializedVariable_510151() throws Exception {
|
||||||
|
assertEvaluationEquals(42);
|
||||||
|
}
|
||||||
|
|
||||||
|
// struct S {
|
||||||
|
// int value = 42;
|
||||||
|
// };
|
||||||
|
// constexpr S waldo;
|
||||||
|
|
||||||
|
// constexpr int x = waldo.value;
|
||||||
|
public void testDefaultInitializedVariable_510151() throws Exception {
|
||||||
|
assertEvaluationEquals(42);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -297,9 +297,11 @@ public class CPPVariable extends PlatformObject implements ICPPInternalVariable
|
||||||
|
|
||||||
private static ICPPConstructor getImplicitlyCalledCtor(ICPPASTDeclarator declarator) {
|
private static ICPPConstructor getImplicitlyCalledCtor(ICPPASTDeclarator declarator) {
|
||||||
IBinding ctor = CPPSemantics.findImplicitlyCalledConstructor(declarator);
|
IBinding ctor = CPPSemantics.findImplicitlyCalledConstructor(declarator);
|
||||||
if (ctor instanceof ICPPConstructor && !EvalUtil.isCompilerGeneratedCtor(ctor)) {
|
if (ctor instanceof ICPPConstructor) {
|
||||||
|
if (!EvalUtil.isCompilerGeneratedCtor(ctor) || EvalUtil.isDefaultConstructor((ICPPConstructor) ctor)) {
|
||||||
return (ICPPConstructor) ctor;
|
return (ICPPConstructor) ctor;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.CompositeValue;
|
import org.eclipse.cdt.internal.core.dom.parser.CompositeValue;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.DependentValue;
|
import org.eclipse.cdt.internal.core.dom.parser.DependentValue;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
|
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IntegralValue;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.InstantiationContext;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.InstantiationContext;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -97,14 +96,8 @@ public class EvalInitList extends CPPDependentEvaluation {
|
||||||
if (isValueDependent()) {
|
if (isValueDependent()) {
|
||||||
return DependentValue.create(this);
|
return DependentValue.create(this);
|
||||||
}
|
}
|
||||||
if (getClauses().length >= 1) {
|
|
||||||
return CompositeValue.create(this);
|
return CompositeValue.create(this);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return IntegralValue.UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValueCategory getValueCategory(IASTNode point) {
|
public ValueCategory getValueCategory(IASTNode point) {
|
||||||
|
|
|
@ -186,4 +186,8 @@ public class EvalUtil {
|
||||||
recursionProtectionSet.remove(variable);
|
recursionProtectionSet.remove(variable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isDefaultConstructor(ICPPConstructor constructor) {
|
||||||
|
return constructor.getRequiredArgumentCount() == 0;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue