Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-08-30 19:20:50 -0400
committerNathan Ridge2017-09-07 01:32:17 -0400
commit47fe12a1793f1ee5ba7f3b20dd7081a5be8466c0 (patch)
tree342507651bf7141bf09f04a93f84e4713ef3fc75
parente75a209b9f5543701b616d71680ce4932b91c8d3 (diff)
downloadorg.eclipse.cdt-47fe12a1793f1ee5ba7f3b20dd7081a5be8466c0.tar.gz
org.eclipse.cdt-47fe12a1793f1ee5ba7f3b20dd7081a5be8466c0.tar.xz
org.eclipse.cdt-47fe12a1793f1ee5ba7f3b20dd7081a5be8466c0.zip
Bug 521543 - Correctly identify narrowing conversion to boolean
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java3
2 files changed, 17 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index fa70316b125..3259e16e93b 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -9850,6 +9850,20 @@ public class AST2CPPTests extends AST2CPPTestBase {
dtor= (IASTImplicitNameOwner) name.getParent();
assertSame(ctor3, dtor.getImplicitNames()[0].resolveBinding());
}
+
+ // struct S {
+ // bool a;
+ // int b;
+ // };
+ //
+ // void waldo(S);
+ //
+ // int main() {
+ // waldo({1, 2});
+ // }
+ public void testIntToBoolConversionInInitList_521543() throws Exception {
+ parseAndCheckBindings();
+ }
// namespace A {
// inline namespace B {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java
index 26728ebdc3c..0c9937daa5b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java
@@ -341,6 +341,9 @@ public abstract class ArithmeticConversion {
public static boolean fitsIntoType(IBasicType basicTarget, long n) {
final Kind kind = basicTarget.getKind();
switch (kind) {
+ case eBoolean:
+ return n == 0 || n == 1;
+
case eInt:
if (!basicTarget.isUnsigned()) {
if (basicTarget.isShort()) {

Back to the top