@@ -27,41 +27,56 @@ using ostream = basic_ostream<char>;
27
27
28
28
class A : public std ::ostream {};
29
29
30
+ using uint8_t = unsigned char ;
31
+ using int8_t = signed char ;
32
+
30
33
void origin_ostream (std::ostream &os) {
31
- unsigned char unsigned_value = 9 ;
34
+ uint8_t unsigned_value = 9 ;
32
35
os << unsigned_value;
33
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'unsigned char' passed to 'operator<<' outputs as character instead of integer
36
+ // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'uint8_t' (aka ' unsigned char') passed to 'operator<<' outputs as character instead of integer
34
37
// CHECK-FIXES: os << static_cast<unsigned int>(unsigned_value);
35
38
36
- signed char signed_value = 9 ;
39
+ int8_t signed_value = 9 ;
37
40
os << signed_value;
38
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'signed char' passed to 'operator<<' outputs as character instead of integer
41
+ // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'int8_t' (aka ' signed char') passed to 'operator<<' outputs as character instead of integer
39
42
// CHECK-FIXES: os << static_cast<int>(signed_value);
40
43
41
44
char char_value = 9 ;
42
45
os << char_value;
46
+ unsigned char unsigned_char_value = 9 ;
47
+ os << unsigned_char_value;
48
+ signed char signed_char_value = 9 ;
49
+ os << signed_char_value;
50
+ }
51
+
52
+ void explicit_cast_to_char_type (std::ostream &os) {
53
+ enum V : uint8_t {};
54
+ V e{};
55
+ os << static_cast <unsigned char >(e);
56
+ os << (unsigned char )(e);
57
+ os << (static_cast <unsigned char >(e));
43
58
}
44
59
45
60
void based_on_ostream (A &os) {
46
- unsigned char unsigned_value = 9 ;
61
+ uint8_t unsigned_value = 9 ;
47
62
os << unsigned_value;
48
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'unsigned char' passed to 'operator<<' outputs as character instead of integer
63
+ // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'uint8_t' (aka ' unsigned char') passed to 'operator<<' outputs as character instead of integer
49
64
// CHECK-FIXES: os << static_cast<unsigned int>(unsigned_value);
50
65
51
- signed char signed_value = 9 ;
66
+ int8_t signed_value = 9 ;
52
67
os << signed_value;
53
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'signed char' passed to 'operator<<' outputs as character instead of integer
68
+ // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'int8_t' (aka ' signed char') passed to 'operator<<' outputs as character instead of integer
54
69
// CHECK-FIXES: os << static_cast<int>(signed_value);
55
70
56
71
char char_value = 9 ;
57
72
os << char_value;
58
73
}
59
74
60
- void other_ostream_template_parameters (std::basic_ostream<unsigned char > &os) {
61
- unsigned char unsigned_value = 9 ;
75
+ void other_ostream_template_parameters (std::basic_ostream<uint8_t > &os) {
76
+ uint8_t unsigned_value = 9 ;
62
77
os << unsigned_value;
63
78
64
- signed char signed_value = 9 ;
79
+ int8_t signed_value = 9 ;
65
80
os << signed_value;
66
81
67
82
char char_value = 9 ;
@@ -70,23 +85,22 @@ void other_ostream_template_parameters(std::basic_ostream<unsigned char> &os) {
70
85
71
86
template <class T > class B : public std ::ostream {};
72
87
void template_based_on_ostream (B<int > &os) {
73
- unsigned char unsigned_value = 9 ;
88
+ uint8_t unsigned_value = 9 ;
74
89
os << unsigned_value;
75
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'unsigned char' passed to 'operator<<' outputs as character instead of integer
90
+ // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'uint8_t' (aka ' unsigned char') passed to 'operator<<' outputs as character instead of integer
76
91
// CHECK-FIXES: os << static_cast<unsigned int>(unsigned_value);
77
92
}
78
93
79
94
template <class T > void template_fn_1 (T &os) {
80
- unsigned char unsigned_value = 9 ;
95
+ uint8_t unsigned_value = 9 ;
81
96
os << unsigned_value;
82
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'unsigned char' passed to 'operator<<' outputs as character instead of integer
97
+ // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'uint8_t' (aka ' unsigned char') passed to 'operator<<' outputs as character instead of integer
83
98
// CHECK-FIXES: os << static_cast<unsigned int>(unsigned_value);
84
99
}
85
100
template <class T > void template_fn_2 (std::ostream &os) {
86
101
T unsigned_value = 9 ;
87
102
os << unsigned_value;
88
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'unsigned char' passed to 'operator<<' outputs as character instead of integer
89
- // CHECK-FIXES: os << static_cast<unsigned int>(unsigned_value);
103
+ // It should be detected as well. But we cannot get the sugared type name for SubstTemplateTypeParmType.
90
104
}
91
105
template <class T > void template_fn_3 (std::ostream &os) {
92
106
T unsigned_value = 9 ;
@@ -95,26 +109,10 @@ template<class T> void template_fn_3(std::ostream &os) {
95
109
void call_template_fn () {
96
110
A a{};
97
111
template_fn_1 (a);
98
- template_fn_2<unsigned char >(a);
112
+ template_fn_2<uint8_t >(a);
99
113
template_fn_3<char >(a);
100
114
}
101
115
102
- using U8 = unsigned char ;
103
- void alias_unsigned_char (std::ostream &os) {
104
- U8 v = 9 ;
105
- os << v;
106
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'U8' (aka 'unsigned char') passed to 'operator<<' outputs as character instead of integer
107
- // CHECK-FIXES: os << static_cast<unsigned int>(v);
108
- }
109
-
110
- using I8 = signed char ;
111
- void alias_signed_char (std::ostream &os) {
112
- I8 v = 9 ;
113
- os << v;
114
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'I8' (aka 'signed char') passed to 'operator<<' outputs as character instead of integer
115
- // CHECK-FIXES: os << static_cast<int>(v);
116
- }
117
-
118
116
using C8 = char ;
119
117
void alias_char (std::ostream &os) {
120
118
C8 v = 9 ;
@@ -124,8 +122,8 @@ void alias_char(std::ostream &os) {
124
122
125
123
#define MACRO_VARIANT_NAME a
126
124
void macro_variant_name (std::ostream &os) {
127
- unsigned char MACRO_VARIANT_NAME = 9 ;
125
+ uint8_t MACRO_VARIANT_NAME = 9 ;
128
126
os << MACRO_VARIANT_NAME;
129
- // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'unsigned char' passed to 'operator<<' outputs as character instead of integer
127
+ // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'uint8_t' (aka ' unsigned char') passed to 'operator<<' outputs as character instead of integer
130
128
// CHECK-FIXES: os << static_cast<unsigned int>(MACRO_VARIANT_NAME);
131
129
}
0 commit comments