[cfe-commits] r62302 - in /cfe/trunk/test/SemaCXX: convert-to-bool.cpp member-expr.cpp
Douglas Gregor
dgregor at apple.com
Thu Jan 15 19:02:29 PST 2009
Author: dgregor
Date: Thu Jan 15 21:02:29 2009
New Revision: 62302
URL: http://llvm.org/viewvc/llvm-project?rev=62302&view=rev
Log:
Add test for contextual conversion to bool, and enable some FIXME'd tests
Added:
cfe/trunk/test/SemaCXX/convert-to-bool.cpp
Modified:
cfe/trunk/test/SemaCXX/member-expr.cpp
Added: cfe/trunk/test/SemaCXX/convert-to-bool.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/convert-to-bool.cpp?rev=62302&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/convert-to-bool.cpp (added)
+++ cfe/trunk/test/SemaCXX/convert-to-bool.cpp Thu Jan 15 21:02:29 2009
@@ -0,0 +1,67 @@
+// RUN: clang -fsyntax-only -verify %s
+struct ConvToBool {
+ operator bool() const;
+};
+
+struct ConvToInt {
+ operator int();
+};
+
+struct ExplicitConvToBool {
+ explicit operator bool(); // expected-warning{{explicit conversion functions are a C++0x extension}}
+};
+
+void test_conv_to_bool(ConvToBool ctb, ConvToInt cti, ExplicitConvToBool ecb) {
+ if (ctb) { }
+ if (cti) { }
+ if (ecb) { }
+ for (; ctb; ) { }
+ for (; cti; ) { }
+ for (; ecb; ) { }
+ while (ctb) { };
+ while (cti) { }
+ while (ecb) { }
+ do { } while (ctb);
+ do { } while (cti);
+ do { } while (ecb);
+
+ if (!ctb) { }
+ if (!cti) { }
+ if (!ecb) { }
+
+ bool b1 = !ecb;
+ if (ctb && ecb) { }
+ bool b2 = ctb && ecb;
+ if (ctb || ecb) { }
+ bool b3 = ctb || ecb;
+}
+
+void accepts_bool(bool) { }
+
+struct ExplicitConvToRef {
+ explicit operator int&(); // expected-warning{{explicit conversion functions are a C++0x extension}}
+};
+
+void test_explicit_bool(ExplicitConvToBool ecb) {
+ bool b1(ecb); // okay
+ bool b2 = ecb; // expected-error{{incompatible type initializing 'struct ExplicitConvToBool', expected '_Bool'}}
+ accepts_bool(ecb); // expected-error{{incompatible type passing 'struct ExplicitConvToBool', expected '_Bool'}}
+}
+
+void test_explicit_conv_to_ref(ExplicitConvToRef ecr) {
+ int& i1 = ecr; // expected-error{{non-const reference to type 'int' cannot be initialized with a value of type 'struct ExplicitConvToRef'}}
+ int& i2(ecr); // okay
+}
+
+struct A { };
+struct B { };
+struct C {
+ explicit operator A&(); // expected-warning{{explicit conversion functions are a C++0x extension}}
+ operator B&();
+};
+
+void test_copy_init_conversions(C c) {
+ A &a = c; // expected-error{{non-const reference to type 'struct A' cannot be initialized with a value of type 'struct C'}}
+ B &b = b; // okay
+}
+
Modified: cfe/trunk/test/SemaCXX/member-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-expr.cpp?rev=62302&r1=62301&r2=62302&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-expr.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-expr.cpp Thu Jan 15 21:02:29 2009
@@ -13,8 +13,8 @@
int i2 = xp->f();
x.E; // expected-error{{cannot refer to type member 'E' with '.'}}
xp->E; // expected-error{{cannot refer to type member 'E' with '->'}}
- // FIXME: lookup needs to find enumerators int i3 = x.Enumerator;
- // FIXME: int i4 = xp->Enumerator;
+ int i3 = x.Enumerator;
+ int i4 = xp->Enumerator;
x.mem = 1;
xp->mem = 2;
float f1 = x.g();
More information about the cfe-commits
mailing list