r184392 - Add a few more tests for casts.
Eli Friedman
eli.friedman at gmail.com
Wed Jun 19 18:35:14 PDT 2013
Author: efriedma
Date: Wed Jun 19 20:35:13 2013
New Revision: 184392
URL: http://llvm.org/viewvc/llvm-project?rev=184392&view=rev
Log:
Add a few more tests for casts.
Modified:
cfe/trunk/test/SemaCXX/cast-conversion.cpp
cfe/trunk/test/SemaCXX/member-pointer-ms.cpp
cfe/trunk/test/SemaCXX/nullptr.cpp
Modified: cfe/trunk/test/SemaCXX/cast-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cast-conversion.cpp?rev=184392&r1=184391&r2=184392&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cast-conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/cast-conversion.cpp Wed Jun 19 20:35:13 2013
@@ -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'}}
+}
Modified: cfe/trunk/test/SemaCXX/member-pointer-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-pointer-ms.cpp?rev=184392&r1=184391&r2=184392&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-pointer-ms.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-pointer-ms.cpp Wed Jun 19 20:35:13 2013
@@ -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 at -1 {{cannot reinterpret_cast from member pointer type}}
Modified: cfe/trunk/test/SemaCXX/nullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr.cpp?rev=184392&r1=184391&r2=184392&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/nullptr.cpp (original)
+++ cfe/trunk/test/SemaCXX/nullptr.cpp Wed Jun 19 20:35:13 2013
@@ -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) { }
More information about the cfe-commits
mailing list