Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2016-10-27 05:12:04 +0000
committerNathan Ridge2016-11-04 07:00:04 +0000
commit8244bcd33d41784687c8612ca3516b3b05202f06 (patch)
treefb9986cc68ab895ace672215ca011957934af6db
parentb6d218a6524829af84c977d2e5cf948f5fa1b8a8 (diff)
downloadorg.eclipse.cdt-8244bcd33d41784687c8612ca3516b3b05202f06.tar.gz
org.eclipse.cdt-8244bcd33d41784687c8612ca3516b3b05202f06.tar.xz
org.eclipse.cdt-8244bcd33d41784687c8612ca3516b3b05202f06.zip
Bug 506170 - Evaluation of dependent conditional expression
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java4
2 files changed, 20 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
index 78245d1ce22..46283bd5219 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
@@ -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 {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java
index 672970714e2..3ef448f40c6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java
@@ -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());
}

Back to the top