blob: e5f26e584b064c8e2f52a3f393b1a5e891930b00 [file] [log] [blame]
Richard Smith967ecd32011-02-21 20:10:02 +00001// RUN: %clang_cc1 -std=c++0x -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
Douglas Gregor46287c72010-01-29 16:37:09 +00002
3template < bool condition, typename T = void >
4struct enable_if { typedef T type; };
5
6template< typename T >
7struct enable_if< false, T > {};
8
9// PR5876
10namespace Casts {
11 template< unsigned O >
12 void implicit(typename enable_if< O <= 4 >::type* = 0) {
13 }
14
15 template< unsigned O >
16 void cstyle(typename enable_if< O <= (unsigned)4 >::type* = 0) {
17 }
18
19 template< unsigned O >
20 void functional(typename enable_if< O <= unsigned(4) >::type* = 0) {
21 }
22
23 template< unsigned O >
24 void static_(typename enable_if< O <= static_cast<unsigned>(4) >::type* = 0) {
25 }
26
Richard Smith967ecd32011-02-21 20:10:02 +000027 template< typename T >
28 void auto_(decltype(new auto(T()))) {
29 }
30
Douglas Gregor46287c72010-01-29 16:37:09 +000031 // FIXME: Test const_cast, reinterpret_cast, dynamic_cast, which are
32 // a bit harder to use in template arguments.
33 template <unsigned N> struct T {};
34
35 template <int N> T<N> f() { return T<N>(); }
36
Douglas Gregor8f51a4f2010-03-13 18:23:07 +000037 // CHECK: define weak_odr void @_ZN5Casts8implicitILj4EEEvPN9enable_ifIXleT_Li4EEvE4typeE
Douglas Gregor46287c72010-01-29 16:37:09 +000038 template void implicit<4>(void*);
Douglas Gregor8f51a4f2010-03-13 18:23:07 +000039 // CHECK: define weak_odr void @_ZN5Casts6cstyleILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
Douglas Gregor46287c72010-01-29 16:37:09 +000040 template void cstyle<4>(void*);
Douglas Gregor8f51a4f2010-03-13 18:23:07 +000041 // CHECK: define weak_odr void @_ZN5Casts10functionalILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
Douglas Gregor46287c72010-01-29 16:37:09 +000042 template void functional<4>(void*);
Douglas Gregor8f51a4f2010-03-13 18:23:07 +000043 // CHECK: define weak_odr void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
Douglas Gregor46287c72010-01-29 16:37:09 +000044 template void static_<4>(void*);
45
Chris Lattner117e3f42010-07-30 04:02:24 +000046 // CHECK: define weak_odr void @_ZN5Casts1fILi6EEENS_1TIXT_EEEv
Douglas Gregor46287c72010-01-29 16:37:09 +000047 template T<6> f<6>();
Richard Smith967ecd32011-02-21 20:10:02 +000048
49 // CHECK: define weak_odr void @_ZN5Casts5auto_IiEEvDTnw_DapicvT__EEE(
50 template void auto_<int>(int*);
Douglas Gregor46287c72010-01-29 16:37:09 +000051}