Skip to content
Snippets Groups Projects
Commit eb82a420 authored by Eli Friedman's avatar Eli Friedman
Browse files

Add a few more tests for casts.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184392 91177308-0d34-0410-b5e6-96231b3b80d8
parent e40bc4b7
No related branches found
No related tags found
No related merge requests found
...@@ -65,3 +65,11 @@ void *intToPointer4() { ...@@ -65,3 +65,11 @@ void *intToPointer4() {
void *intToPointer5(long l) { void *intToPointer5(long l) {
return (void*)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'}}
}
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
// 2012, which supports C++11 and static_assert. It should pass for both 64-bit // 2012, which supports C++11 and static_assert. It should pass for both 64-bit
// and 32-bit x86. // and 32-bit x86.
// //
// expected-no-diagnostics
// Test the size of various member pointer combinations: // Test the size of various member pointer combinations:
// - complete and incomplete // - complete and incomplete
// - single, multiple, and virtual inheritance (and unspecified for incomplete) // - single, multiple, and virtual inheritance (and unspecified for incomplete)
...@@ -165,3 +163,6 @@ struct MemPtrInTemplate { ...@@ -165,3 +163,6 @@ struct MemPtrInTemplate {
int T::*data_ptr; int T::*data_ptr;
void (T::*func_ptr)(); void (T::*func_ptr)();
}; };
int Virtual::*CastTest = reinterpret_cast<int Virtual::*>(&AA::x);
// expected-error@-1 {{cannot reinterpret_cast from member pointer type}}
...@@ -64,6 +64,9 @@ nullptr_t f(nullptr_t null) ...@@ -64,6 +64,9 @@ nullptr_t f(nullptr_t null)
(void)reinterpret_cast<uintptr_t>(nullptr); (void)reinterpret_cast<uintptr_t>(nullptr);
(void)reinterpret_cast<uintptr_t>(*pn); (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; int *ip = *pn;
if (*pn) { } if (*pn) { }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment