aboutsummaryrefslogtreecommitdiff
path: root/test/SemaTemplate/instantiate-cast.cpp
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2009-06-02 17:58:47 +0000
committerEd Schouten <ed@FreeBSD.org>2009-06-02 17:58:47 +0000
commitec2b103c267a06a66e926f62cd96767b280f5cf5 (patch)
treece7d964cbb5e39695b71481698f10cb099c23d4a /test/SemaTemplate/instantiate-cast.cpp
downloadsrc-ec2b103c267a06a66e926f62cd96767b280f5cf5.tar.gz
src-ec2b103c267a06a66e926f62cd96767b280f5cf5.zip
Import Clang, at r72732.vendor/clang/clang-r72732
Notes
Notes: svn path=/vendor/clang/dist/; revision=193326 svn path=/vendor/clang/clang-r72732/; revision=193327; tag=vendor/clang/clang-r72732
Diffstat (limited to 'test/SemaTemplate/instantiate-cast.cpp')
-rw-r--r--test/SemaTemplate/instantiate-cast.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/test/SemaTemplate/instantiate-cast.cpp b/test/SemaTemplate/instantiate-cast.cpp
new file mode 100644
index 000000000000..d99f3e556602
--- /dev/null
+++ b/test/SemaTemplate/instantiate-cast.cpp
@@ -0,0 +1,109 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+struct A { int x; };
+
+class Base {
+public:
+ virtual void f();
+};
+
+class Derived : public Base { };
+
+struct ConvertibleToInt {
+ operator int() const;
+};
+
+struct Constructible {
+ Constructible(int, float);
+};
+
+// ---------------------------------------------------------------------
+// C-style casts
+// ---------------------------------------------------------------------
+template<typename T, typename U>
+struct CStyleCast0 {
+ void f(T t) {
+ (void)((U)t); // FIXME:ugly expected-error{{operand}}
+ }
+};
+
+template struct CStyleCast0<int, float>;
+template struct CStyleCast0<A, int>; // expected-note{{instantiation}}
+
+// ---------------------------------------------------------------------
+// static_cast
+// ---------------------------------------------------------------------
+template<typename T, typename U>
+struct StaticCast0 {
+ void f(T t) {
+ (void)static_cast<U>(t); // expected-error{{static_cast}}
+ }
+};
+
+template struct StaticCast0<ConvertibleToInt, bool>;
+template struct StaticCast0<int, float>;
+template struct StaticCast0<int, A>; // expected-note{{instantiation}}
+
+// ---------------------------------------------------------------------
+// dynamic_cast
+// ---------------------------------------------------------------------
+template<typename T, typename U>
+struct DynamicCast0 {
+ void f(T t) {
+ (void)dynamic_cast<U>(t); // expected-error{{not a reference or pointer}}
+ }
+};
+
+template struct DynamicCast0<Base*, Derived*>;
+template struct DynamicCast0<Base*, A>; // expected-note{{instantiation}}
+
+// ---------------------------------------------------------------------
+// reinterpret_cast
+// ---------------------------------------------------------------------
+template<typename T, typename U>
+struct ReinterpretCast0 {
+ void f(T t) {
+ (void)reinterpret_cast<U>(t); // expected-error{{constness}}
+ }
+};
+
+template struct ReinterpretCast0<void (*)(int), void (*)(float)>;
+template struct ReinterpretCast0<int const *, float *>; // expected-note{{instantiation}}
+
+// ---------------------------------------------------------------------
+// const_cast
+// ---------------------------------------------------------------------
+template<typename T, typename U>
+struct ConstCast0 {
+ void f(T t) {
+ (void)const_cast<U>(t); // expected-error{{not allowed}}
+ }
+};
+
+template struct ConstCast0<int const * *, int * *>;
+template struct ConstCast0<int const *, float *>; // expected-note{{instantiation}}
+
+// ---------------------------------------------------------------------
+// C++ functional cast
+// ---------------------------------------------------------------------
+template<typename T, typename U>
+struct FunctionalCast1 {
+ void f(T t) {
+ (void)U(t); // FIXME:ugly expected-error{{operand}}
+ }
+};
+
+template struct FunctionalCast1<int, float>;
+template struct FunctionalCast1<A, int>; // expected-note{{instantiation}}
+
+#if 0
+// Generates temporaries, which we cannot handle yet.
+template<int N, long M>
+struct FunctionalCast2 {
+ void f() {
+ (void)Constructible(N, M);
+ }
+};
+
+template struct FunctionalCast2<1, 3>;
+#endif