mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 506170 - Evaluation of dependent conditional expression
Change-Id: I59355bb40e84662554be76929ba9f9618aec7dba
This commit is contained in:
parent
b6d218a652
commit
8244bcd33d
2 changed files with 20 additions and 1 deletions
|
@ -9292,6 +9292,23 @@ public class AST2TemplateTests extends AST2TestBase {
|
|||
ICPPVariable waldo = helper.assertNonProblem("waldo");
|
||||
assertConstantValue(0, waldo);
|
||||
}
|
||||
|
||||
// template <typename T>
|
||||
// struct traits {
|
||||
// static constexpr int Flags = 1;
|
||||
// };
|
||||
//
|
||||
// template <typename T>
|
||||
// struct S {
|
||||
// static constexpr int a = traits<T>::Flags;
|
||||
// static constexpr int b = a ? 42 : 0;
|
||||
// };
|
||||
//
|
||||
// constexpr int waldo = S<int>::b;
|
||||
public void testDependentConditionalExpression_506170() throws Exception {
|
||||
BindingAssertionHelper helper = getAssertionHelper();
|
||||
helper.assertVariableValue("waldo", 42);
|
||||
}
|
||||
|
||||
// template <typename>
|
||||
// struct C {
|
||||
|
|
|
@ -282,8 +282,10 @@ public class ValueFactory {
|
|||
if (exp instanceof IASTConditionalExpression) {
|
||||
IASTConditionalExpression cexpr= (IASTConditionalExpression) exp;
|
||||
IValue v= evaluate(cexpr.getLogicalConditionExpression());
|
||||
if (isInvalidValue(v) || v.numberValue() == null)
|
||||
if (isInvalidValue(v))
|
||||
return v;
|
||||
if (isDeferredValue(v))
|
||||
return null; // the value will be computed using the evaluation
|
||||
if (v.numberValue().longValue() == 0) {
|
||||
return evaluate(cexpr.getNegativeResultExpression());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue