aboutsummaryrefslogtreecommitdiff
path: root/test/CXX
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2013-05-06 21:39:12 +0000
committerJohn McCall <rjmccall@apple.com>2013-05-06 21:39:12 +0000
commit993f43f24d7a45a5cd4678a3316b0852261fc5d4 (patch)
treebf54fbd0ff497973e08eb9c0667daaaa43804fb0 /test/CXX
parent009735db957ac4bcca8f5ad1a5c01354b1b57fbd (diff)
Grab-bag of bit-field fixes:
- References to ObjC bit-field ivars are bit-field lvalues; fixes rdar://13794269, which got me started down this. - Introduce Expr::refersToBitField, switch a couple users to it where semantically important, and comment the difference between this and the existing API. - Discourage Expr::getBitField by making it a bit longer and less general-sounding. - Lock down on const_casts of bit-field gl-values until we hear back from the committee as to whether they're allowed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181252 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r--test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp23
-rw-r--r--test/CXX/expr/expr.post/expr.const.cast/p1-0x.cpp17
-rw-r--r--test/CXX/expr/expr.unary/expr.sizeof/p1.cpp20
3 files changed, 59 insertions, 1 deletions
diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp
index 51d61a52a6..263f661208 100644
--- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp
+++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp
@@ -38,3 +38,26 @@ namespace PR6066 {
return 0;
}
}
+
+namespace test3 {
+ struct A {
+ unsigned bitX : 4; // expected-note 4 {{bit-field is declared here}}
+ unsigned bitY : 4; // expected-note {{bit-field is declared here}}
+ unsigned var;
+
+ void foo();
+ };
+
+ void test(A *a) {
+ unsigned &t0 = a->bitX; // expected-error {{non-const reference cannot bind to bit-field 'bitX'}}
+ unsigned &t1 = (unsigned&) a->bitX; // expected-error {{non-const reference cannot bind to bit-field 'bitX'}}
+ unsigned &t2 = const_cast<unsigned&>(a->bitX); // expected-error {{const_cast from bit-field lvalue to reference type 'unsigned int &'}}
+ unsigned &t3 = (a->foo(), a->bitX); // expected-error {{non-const reference cannot bind to bit-field 'bitX'}}
+ unsigned &t4 = (a->var ? a->bitX : a->bitY); // expected-error {{non-const reference cannot bind to bit-field}}
+ unsigned &t5 = (a->var ? a->bitX : a->bitX); // expected-error {{non-const reference cannot bind to bit-field}}
+ unsigned &t6 = (a->var ? a->bitX : a->var); // expected-error {{non-const reference cannot bind to bit-field}}
+ unsigned &t7 = (a->var ? a->var : a->bitY); // expected-error {{non-const reference cannot bind to bit-field}}
+ unsigned &t8 = (a->bitX = 3); // expected-error {{non-const reference cannot bind to bit-field 'bitX'}}
+ unsigned &t9 = (a->bitY += 3); // expected-error {{non-const reference cannot bind to bit-field 'bitY'}}
+ }
+}
diff --git a/test/CXX/expr/expr.post/expr.const.cast/p1-0x.cpp b/test/CXX/expr/expr.post/expr.const.cast/p1-0x.cpp
index be898761fa..76ea96fe14 100644
--- a/test/CXX/expr/expr.post/expr.const.cast/p1-0x.cpp
+++ b/test/CXX/expr/expr.post/expr.const.cast/p1-0x.cpp
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
// The result of the expression const_cast<T>(v) is of type T. If T is
// an lvalue reference to object type, the result is an lvalue; if T
@@ -16,3 +15,19 @@ void test_classification(const int *ptr) {
int *ptr1 = const_cast<int *&&>(xvalue<const int*>());
int *ptr2 = const_cast<int *&&>(prvalue<const int*>());
}
+
+struct A {
+ volatile unsigned ubf : 4;
+ volatile unsigned uv;
+ volatile int sv;
+ void foo();
+ bool pred();
+};
+
+void test(A &a) {
+ unsigned &t0 = const_cast<unsigned&>(a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}}
+ unsigned &t1 = const_cast<unsigned&>(a.foo(), a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}}
+ unsigned &t2 = const_cast<unsigned&>(a.pred() ? a.ubf : a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}}
+ unsigned &t3 = const_cast<unsigned&>(a.pred() ? a.ubf : a.uv); // expected-error {{const_cast from bit-field lvalue to reference type}}
+ unsigned &t4 = const_cast<unsigned&>(a.pred() ? a.ubf : a.sv); // expected-error {{const_cast from rvalue to reference type}}
+}
diff --git a/test/CXX/expr/expr.unary/expr.sizeof/p1.cpp b/test/CXX/expr/expr.unary/expr.sizeof/p1.cpp
new file mode 100644
index 0000000000..6a59e3d7ae
--- /dev/null
+++ b/test/CXX/expr/expr.unary/expr.sizeof/p1.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct A {
+ unsigned bitX : 4;
+ unsigned bitY : 4;
+ unsigned var;
+
+ void foo();
+};
+
+void test(A *a) {
+ int x;
+ x = sizeof(a->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}}
+ x = sizeof((unsigned) a->bitX);
+ x = sizeof(a->foo(), a->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}}
+ x = sizeof(a->var ? a->bitX : a->bitY); // expected-error {{invalid application of 'sizeof' to bit-field}}
+ x = sizeof(a->var ? a->bitX : a->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}}
+ x = sizeof(a->bitX = 3); // expected-error {{invalid application of 'sizeof' to bit-field}}
+ x = sizeof(a->bitY += 3); // expected-error {{invalid application of 'sizeof' to bit-field}}
+}