]> granicus.if.org Git - clang/commitdiff
Add a few more tests for casts.
authorEli Friedman <eli.friedman@gmail.com>
Thu, 20 Jun 2013 01:35:13 +0000 (01:35 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 20 Jun 2013 01:35:13 +0000 (01:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184392 91177308-0d34-0410-b5e6-96231b3b80d8

test/SemaCXX/cast-conversion.cpp
test/SemaCXX/member-pointer-ms.cpp
test/SemaCXX/nullptr.cpp

index 270f96831bd4e6b206e9eaf4d088b9ea80436a41..76b09997ef1e4c86a86b94f48b4bfbea664fd4f1 100644 (file)
@@ -65,3 +65,11 @@ void *intToPointer4() {
 void *intToPointer5(long l) {
   return (void*)l;
 }
+
+struct AmbiguousCast {
+  operator int(); // expected-note {{candidate function}}
+  operator unsigned int(); // expected-note {{candidate function}}
+};
+long long AmbiguousCastFunc(AmbiguousCast& a) {
+  return static_cast<long long>(a); // expected-error {{ambiguous conversion for static_cast from 'AmbiguousCast' to 'long long'}}
+}
index 7dca12190584685797d0dd3f91b39715b85b918b..aee8e2eca774280e2ab0bf21d5f4833b98e5024a 100644 (file)
@@ -5,8 +5,6 @@
 // 2012, which supports C++11 and static_assert.  It should pass for both 64-bit
 // and 32-bit x86.
 //
-// expected-no-diagnostics
-
 // Test the size of various member pointer combinations:
 // - complete and incomplete
 // - single, multiple, and virtual inheritance (and unspecified for incomplete)
@@ -165,3 +163,6 @@ struct MemPtrInTemplate {
   int T::*data_ptr;
   void (T::*func_ptr)();
 };
+
+int Virtual::*CastTest = reinterpret_cast<int Virtual::*>(&AA::x);
+  // expected-error@-1 {{cannot reinterpret_cast from member pointer type}}
index b49f63b98051020e18ad4ac39fb8ddcc8ad425dd..28798a4f8ce8a9898dd9b35435abc32f5016fa51 100644 (file)
@@ -64,6 +64,9 @@ nullptr_t f(nullptr_t null)
   (void)reinterpret_cast<uintptr_t>(nullptr);
   (void)reinterpret_cast<uintptr_t>(*pn);
 
+  // You can't reinterpret_cast nullptr to any integer
+  (void)reinterpret_cast<char>(nullptr); // expected-error {{cast from pointer to smaller type 'char' loses information}}
+
   int *ip = *pn;
   if (*pn) { }