summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-08-08 06:13:49 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-08-08 06:13:49 +0000
commitf2b084fc5a58f8069162a08c57e1c094a65d60e5 (patch)
treebdea194f48e67ca1a21e166ae58d5f0c87020ab7 /clang/test
parentb35f34105e66fd2e544f351e7c8e5124f74c8aad (diff)
downloadbcm5719-llvm-f2b084fc5a58f8069162a08c57e1c094a65d60e5.tar.gz
bcm5719-llvm-f2b084fc5a58f8069162a08c57e1c094a65d60e5.zip
Implement final piece of DR963 and also DR587:
A conditional operator between glvalues of types cv1 T and cv2 T produces a glvalue if the expressions are of the same value kind and one of cv1 and cv2 is a subset of the other. A conditional operator between two null pointer constants is permitted if one of them is of type std::nullptr_t. llvm-svn: 161476
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaCXX/conditional-expr.cpp26
-rw-r--r--clang/test/SemaCXX/nullptr.cpp4
2 files changed, 28 insertions, 2 deletions
diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp
index 4aee913277e..a80eda416f4 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -2,7 +2,7 @@
// C++ rules for ?: are a lot stricter than C rules, and have to take into
// account more conversion options.
-// This test runs in C++0x mode for the contextual conversion of the condition.
+// This test runs in C++11 mode for the contextual conversion of the condition.
struct ToBool { explicit operator bool(); };
@@ -328,3 +328,27 @@ namespace PR9236 {
(void)(true ? (void*)0 : A()); // expected-error{{incompatible operand types}}
}
}
+
+namespace DR587 {
+ template<typename T>
+ const T *f(bool b) {
+ static T t1 = T();
+ static const T t2 = T();
+ return &(b ? t1 : t2);
+ }
+ struct S {};
+ template const int *f(bool);
+ template const S *f(bool);
+
+ extern bool b;
+ int i = 0;
+ const int ci = 0;
+ volatile int vi = 0;
+ const volatile int cvi = 0;
+
+ const int &cir = b ? i : ci;
+ volatile int &vir = b ? vi : i;
+ const volatile int &cvir1 = b ? ci : cvi;
+ const volatile int &cvir2 = b ? cvi : vi;
+ const volatile int &cvir3 = b ? ci : vi; // expected-error{{volatile lvalue reference to type 'const volatile int' cannot bind to a temporary of type 'int'}}
+}
diff --git a/clang/test/SemaCXX/nullptr.cpp b/clang/test/SemaCXX/nullptr.cpp
index e3136039f42..d148f76698e 100644
--- a/clang/test/SemaCXX/nullptr.cpp
+++ b/clang/test/SemaCXX/nullptr.cpp
@@ -33,8 +33,10 @@ nullptr_t f(nullptr_t null)
// Operators
(void)(null == nullptr);
(void)(null <= nullptr);
+ (void)(null == 0);
(void)(null == (void*)0);
(void)((void*)0 == nullptr);
+ (void)(null <= 0);
(void)(null <= (void*)0);
(void)((void*)0 <= nullptr);
(void)(0 == nullptr);
@@ -44,7 +46,7 @@ nullptr_t f(nullptr_t null)
(void)(1 > nullptr); // expected-error {{invalid operands to binary expression}}
(void)(1 != nullptr); // expected-error {{invalid operands to binary expression}}
(void)(1 + nullptr); // expected-error {{invalid operands to binary expression}}
- (void)(0 ? nullptr : 0); // expected-error {{non-pointer operand type 'int' incompatible with nullptr}}
+ (void)(0 ? nullptr : 0);
(void)(0 ? nullptr : (void*)0);
(void)(0 ? nullptr : A()); // expected-error {{non-pointer operand type 'A' incompatible with nullptr}}
(void)(0 ? A() : nullptr); // expected-error {{non-pointer operand type 'A' incompatible with nullptr}}
OpenPOWER on IntegriCloud