1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
// RUN: clang-tidy %s -checks='-*,hicpp-signed-bitwise' -- -std=c++11
// FIXME: Make the test work in all language modes.
#include "hicpp-signed-bitwise-standard-types.h"
void pure_bitmask_types() {
// std::locale::category
int SResult = 0;
std::locale::category C = std::locale::category::ctype;
SResult = std::locale::category::none | std::locale::category::collate;
SResult|= std::locale::category::collate;
SResult = std::locale::category::ctype & std::locale::category::monetary;
SResult&= std::locale::category::monetary;
SResult = std::locale::category::numeric ^ std::locale::category::time;
SResult^= std::locale::category::time;
SResult = std::locale::category::messages | std::locale::category::all;
SResult = std::locale::category::all & C;
SResult&= std::locale::category::all;
SResult = std::locale::category::all | C;
SResult|= std::locale::category::all;
SResult = std::locale::category::all ^ C;
SResult^= std::locale::category::all;
// std::ctype_base::mask
std::ctype_base::mask M = std::ctype_base::mask::punct;
SResult = std::ctype_base::mask::space | std::ctype_base::mask::print;
SResult = std::ctype_base::mask::cntrl & std::ctype_base::mask::upper;
SResult = std::ctype_base::mask::lower ^ std::ctype_base::mask::alpha;
SResult|= std::ctype_base::mask::digit | std::ctype_base::mask::punct;
SResult&= std::ctype_base::mask::xdigit & std::ctype_base::mask::alnum;
SResult^= std::ctype_base::mask::alnum ^ std::ctype_base::mask::graph;
SResult&= std::ctype_base::mask::space & M;
SResult|= std::ctype_base::mask::space | M;
SResult^= std::ctype_base::mask::space ^ M;
// std::ios_base::fmtflags
std::ios_base::fmtflags F = std::ios_base::fmtflags::floatfield;
SResult = std::ios_base::fmtflags::dec | std::ios_base::fmtflags::oct;
SResult = std::ios_base::fmtflags::hex & std::ios_base::fmtflags::basefield;
SResult = std::ios_base::fmtflags::left ^ std::ios_base::fmtflags::right;
SResult|= std::ios_base::fmtflags::internal | std::ios_base::fmtflags::adjustfield;
SResult&= std::ios_base::fmtflags::scientific & std::ios_base::fmtflags::fixed;
SResult^= std::ios_base::fmtflags::floatfield ^ std::ios_base::fmtflags::boolalpha;
SResult = std::ios_base::fmtflags::showbase | std::ios_base::fmtflags::showpoint;
SResult = std::ios_base::fmtflags::showpos & std::ios_base::fmtflags::skipws;
SResult = std::ios_base::fmtflags::unitbuf ^ std::ios_base::fmtflags::uppercase;
SResult|= std::ios_base::fmtflags::unitbuf | F;
SResult&= std::ios_base::fmtflags::unitbuf & F;
SResult^= std::ios_base::fmtflags::unitbuf ^ F;
// std::ios_base::iostate
std::ios_base::iostate S = std::ios_base::iostate::goodbit;
SResult^= std::ios_base::iostate::goodbit | std::ios_base::iostate::badbit;
SResult|= std::ios_base::iostate::failbit & std::ios_base::iostate::eofbit;
SResult&= std::ios_base::iostate::failbit ^ std::ios_base::iostate::eofbit;
SResult = std::ios_base::iostate::goodbit | S;
SResult = std::ios_base::iostate::goodbit & S;
SResult = std::ios_base::iostate::goodbit ^ S;
// std::ios_base::openmode
std::ios_base::openmode B = std::ios_base::openmode::binary;
SResult = std::ios_base::openmode::app | std::ios_base::openmode::binary;
SResult = std::ios_base::openmode::in & std::ios_base::openmode::out;
SResult = std::ios_base::openmode::trunc ^ std::ios_base::openmode::ate;
SResult&= std::ios_base::openmode::trunc | B;
SResult^= std::ios_base::openmode::trunc & B;
SResult|= std::ios_base::openmode::trunc ^ B;
}
void still_forbidden() {
// std::locale::category
unsigned int UResult = 0u;
int SResult = 0;
SResult = std::ctype_base::mask::print ^ 8u;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
SResult = std::ctype_base::mask::cntrl | 8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
SResult = std::ctype_base::mask::upper & 8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
SResult = std::ctype_base::mask::lower ^ -8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
// Staying within the allowed standard types is ok for bitwise assignment
// operations.
std::ctype_base::mask var = std::ctype_base::mask::print;
SResult<<= std::ctype_base::mask::upper;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
SResult>>= std::ctype_base::mask::upper;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
SResult &= std::ctype_base::mask::upper;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
SResult |= std::ctype_base::mask::upper;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
SResult ^= std::ctype_base::mask::upper;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::locale::category::collate << 1u;
UResult = std::locale::category::ctype << 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::locale::category::monetary >> 1u;
UResult = std::locale::category::numeric >> 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = ~std::locale::category::messages;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
SResult = ~std::locale::category::all;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
// std::ctype_base::mask
UResult = std::ctype_base::mask::space | 8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ctype_base::mask::print & 8u;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ctype_base::mask::cntrl ^ -8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ctype_base::mask::upper << 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ctype_base::mask::lower << 1u;
UResult = std::ctype_base::mask::alpha >> 1u;
UResult = std::ctype_base::mask::digit >> 1u;
UResult = ~std::ctype_base::mask::punct;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
SResult = ~std::ctype_base::mask::xdigit;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
// std::ios_base::fmtflags
UResult = std::ios_base::fmtflags::dec | 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::fmtflags::oct & 1u;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::fmtflags::hex ^ -1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::fmtflags::basefield >> 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::fmtflags::left >> 1u;
UResult = std::ios_base::fmtflags::right << 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::fmtflags::internal << 1u;
UResult = ~std::ios_base::fmtflags::adjustfield;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
SResult = ~std::ios_base::fmtflags::scientific;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
// std::ios_base::iostate
UResult = std::ios_base::iostate::goodbit | 8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::iostate::badbit & 8u;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::iostate::failbit ^ -8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::iostate::eofbit << 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::iostate::goodbit << 1u;
UResult = std::ios_base::iostate::badbit >> 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::iostate::failbit >> 1u;
UResult = ~std::ios_base::iostate::eofbit;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
SResult = ~std::ios_base::iostate::goodbit;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
// std::ios_base::openmode
UResult = std::ios_base::app | 8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::binary & 8u;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::in ^ -8;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::out >> 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::trunc >> 1u;
UResult = std::ios_base::ate << 1;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
UResult = std::ios_base::ate << 1u;
UResult = ~std::ios_base::openmode::app;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
SResult = ~std::ios_base::openmode::binary;
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator
}
|