xref: /aosp_15_r20/external/clang/test/Misc/integer-literal-printing.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
2*67e74705SXin Li 
3*67e74705SXin Li // PR11179
4*67e74705SXin Li template <short T> class Type1 {};
Function1(Type1<T> & x)5*67e74705SXin Li template <short T> void Function1(Type1<T>& x) {} // expected-note{{candidate function [with T = -42] not viable: expects an l-value for 1st argument}}
6*67e74705SXin Li 
7*67e74705SXin Li template <unsigned short T> class Type2 {};
Function2(Type2<T> & x)8*67e74705SXin Li template <unsigned short T> void Function2(Type2<T>& x) {} // expected-note{{candidate function [with T = 42] not viable: expects an l-value for 1st argument}}
9*67e74705SXin Li 
10*67e74705SXin Li enum class boolTy : bool {
11*67e74705SXin Li   b = 0,
12*67e74705SXin Li };
13*67e74705SXin Li 
14*67e74705SXin Li template <boolTy T> struct Type3Helper;
15*67e74705SXin Li template <> struct Type3Helper<boolTy::b> { typedef boolTy Ty; };
16*67e74705SXin Li template <boolTy T, typename Type3Helper<T>::Ty U> struct Type3 {};
17*67e74705SXin Li 
18*67e74705SXin Li // PR14386
19*67e74705SXin Li enum class charTy : char {
20*67e74705SXin Li   c = 0,
21*67e74705SXin Li };
22*67e74705SXin Li 
23*67e74705SXin Li template <charTy T> struct Type4Helper;
24*67e74705SXin Li template <> struct Type4Helper<charTy::c> { typedef charTy Ty; };
25*67e74705SXin Li template <charTy T, typename Type4Helper<T>::Ty U> struct Type4 {};
26*67e74705SXin Li 
27*67e74705SXin Li enum class scharTy : signed char {
28*67e74705SXin Li   c = 0,
29*67e74705SXin Li };
30*67e74705SXin Li 
31*67e74705SXin Li template <scharTy T> struct Type5Helper;
32*67e74705SXin Li template <> struct Type5Helper<scharTy::c> { typedef scharTy Ty; };
33*67e74705SXin Li template <scharTy T, typename Type5Helper<T>::Ty U> struct Type5 {};
34*67e74705SXin Li 
35*67e74705SXin Li enum class ucharTy : unsigned char {
36*67e74705SXin Li   c = 0,
37*67e74705SXin Li };
38*67e74705SXin Li 
39*67e74705SXin Li template <ucharTy T> struct Type6Helper;
40*67e74705SXin Li template <> struct Type6Helper<ucharTy::c> { typedef ucharTy Ty; };
41*67e74705SXin Li template <ucharTy T, typename Type6Helper<T>::Ty U> struct Type6 {};
42*67e74705SXin Li 
43*67e74705SXin Li enum class wcharTy : wchar_t {
44*67e74705SXin Li   c = 0,
45*67e74705SXin Li };
46*67e74705SXin Li 
47*67e74705SXin Li template <wcharTy T> struct Type7Helper;
48*67e74705SXin Li template <> struct Type7Helper<wcharTy::c> { typedef wcharTy Ty; };
49*67e74705SXin Li template <wcharTy T, typename Type7Helper<T>::Ty U> struct Type7 {};
50*67e74705SXin Li 
51*67e74705SXin Li enum class char16Ty : char16_t {
52*67e74705SXin Li   c = 0,
53*67e74705SXin Li };
54*67e74705SXin Li 
55*67e74705SXin Li template <char16Ty T> struct Type8Helper;
56*67e74705SXin Li template <> struct Type8Helper<char16Ty::c> { typedef char16Ty Ty; };
57*67e74705SXin Li template <char16Ty T, typename Type8Helper<T>::Ty U> struct Type8 {};
58*67e74705SXin Li 
59*67e74705SXin Li enum class char32Ty : char16_t {
60*67e74705SXin Li   c = 0,
61*67e74705SXin Li };
62*67e74705SXin Li 
63*67e74705SXin Li template <char32Ty T> struct Type9Helper;
64*67e74705SXin Li template <> struct Type9Helper<char32Ty::c> { typedef char32Ty Ty; };
65*67e74705SXin Li template <char32Ty T, typename Type9Helper<T>::Ty U> struct Type9 {};
66*67e74705SXin Li 
Function()67*67e74705SXin Li void Function() {
68*67e74705SXin Li   Function1(Type1<-42>()); // expected-error{{no matching function for call to 'Function1'}}
69*67e74705SXin Li   Function2(Type2<42>()); // expected-error{{no matching function for call to 'Function2'}}
70*67e74705SXin Li 
71*67e74705SXin Li   struct Type3<boolTy::b, "3"> t3; // expected-error{{value of type 'const char [2]' is not implicitly convertible to 'typename Type3Helper<(boolTy)false>::Ty' (aka 'boolTy')}}
72*67e74705SXin Li 
73*67e74705SXin Li   struct Type4<charTy::c, "4"> t4; // expected-error{{value of type 'const char [2]' is not implicitly convertible to 'typename Type4Helper<(charTy)'\x00'>::Ty' (aka 'charTy')}}
74*67e74705SXin Li   struct Type5<scharTy::c, "5"> t5; // expected-error{{value of type 'const char [2]' is not implicitly convertible to 'typename Type5Helper<(scharTy)'\x00'>::Ty' (aka 'scharTy')}}
75*67e74705SXin Li   struct Type6<ucharTy::c, "6"> t6; // expected-error{{value of type 'const char [2]' is not implicitly convertible to 'typename Type6Helper<(ucharTy)'\x00'>::Ty' (aka 'ucharTy')}}
76*67e74705SXin Li   struct Type7<wcharTy::c, "7"> t7; // expected-error{{value of type 'const char [2]' is not implicitly convertible to 'typename Type7Helper<(wcharTy)L'\x00'>::Ty' (aka 'wcharTy')}}
77*67e74705SXin Li   struct Type8<char16Ty::c, "8"> t8; // expected-error{{value of type 'const char [2]' is not implicitly convertible to 'typename Type8Helper<(char16Ty)u'\x00'>::Ty' (aka 'char16Ty')}}
78*67e74705SXin Li   struct Type9<char32Ty::c, "9"> t9; // expected-error{{value of type 'const char [2]' is not implicitly convertible to 'typename Type9Helper<(char32Ty)u'\x00'>::Ty' (aka 'char32Ty')}}
79*67e74705SXin Li }
80