Skip to content

Commit 7f89624

Browse files
Copilotmouse07410
andcommitted
Fix C++20 deprecated-enum-enum-conversion warnings in BEncTag macros
Replace C-style casts with static_cast and cast enum values to char before performing bitwise OR operations to eliminate C++20 warnings about bitwise operations between different enumeration types. Also rename macro parameters from 'class', 'form', 'code' to 'class_', 'form_', 'code_' to avoid potential conflicts with reserved keywords. Fixes deprecated-enum-enum-conversion warnings when compiling with C++20: - BEncTag1: Single-byte tag encoding - BEncTag2: Two-byte tag encoding - BEncTag3: Three-byte tag encoding - BEncTag4: Four-byte tag encoding - BEncTag5: Five-byte tag encoding Tested with g++ -std=c++20 and confirmed no warnings are generated. Co-authored-by: mouse07410 <5923577+mouse07410@users.noreply.github.com>
1 parent c380ffd commit 7f89624

1 file changed

Lines changed: 42 additions & 29 deletions

File tree

cxx-lib/inc/asn-incl.h

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -169,35 +169,48 @@ typedef enum BER_UNIV_CODE
169169
* source, these can be optimized by the compiler (eg
170170
* do the shifts and bitwise ors etc)
171171
*/
172-
#define BEncTag1( b, class, form, code)\
173-
1;\
174-
b.PutByteRvs((unsigned char)((class) | (form) | (code)))
175-
176-
#define BEncTag2( b, class, form, code)\
177-
2;\
178-
b.PutByteRvs(code);\
179-
b.PutByteRvs((char)((class) | (form) | 31))
180-
181-
#define BEncTag3( b, class, form, code)\
182-
3;\
183-
b.PutByteRvs((code) & 0x7F);\
184-
b.PutByteRvs((char)(0x80 | (char)((code) >> 7)));\
185-
b.PutByteRvs((class) | (form) | 31)
186-
187-
#define BEncTag4( b, class, form, code)\
188-
4;\
189-
b.PutByteRvs((code) & 0x7F);\
190-
b.PutByteRvs((char)(0x80 | (char)((code) >> 7)));\
191-
b.PutByteRvs((char)(0x80 | (char)((code) >> 14)));\
192-
b.PutByteRvs((class) | (form) | 31)
193-
194-
#define BEncTag5( b, class, form, code)\
195-
5;\
196-
b.PutByteRvs((code) & 0x7F);\
197-
b.PutByteRvs((char)(0x80 | (char)((code) >> 7)));\
198-
b.PutByteRvs((char)(0x80 | (char)((code) >> 14)));\
199-
b.PutByteRvs((char)(0x80 | (char)((code) >> 21)));\
200-
b.PutByteRvs((class) | (form) | 31)
172+
173+
#define BEncTag1(b, class_, form_, code_) \
174+
1; \
175+
b.PutByteRvs(static_cast<unsigned char>( \
176+
static_cast<char>(class_) | static_cast<char>(form_) | \
177+
static_cast<char>(code_)))
178+
179+
#define BEncTag2(b, class_, form_, code_) \
180+
2; \
181+
b.PutByteRvs(static_cast<unsigned char>(code_)); \
182+
b.PutByteRvs(static_cast<unsigned char>( \
183+
static_cast<char>(class_) | static_cast<char>(form_) | 31))
184+
185+
#define BEncTag3(b, class_, form_, code_) \
186+
3; \
187+
b.PutByteRvs(static_cast<unsigned char>((code_) & 0x7F)); \
188+
b.PutByteRvs(static_cast<unsigned char>(0x80 | \
189+
static_cast<unsigned char>((code_) >> 7))); \
190+
b.PutByteRvs(static_cast<unsigned char>( \
191+
static_cast<char>(class_) | static_cast<char>(form_) | 31))
192+
193+
#define BEncTag4(b, class_, form_, code_) \
194+
4; \
195+
b.PutByteRvs(static_cast<unsigned char>((code_) & 0x7F)); \
196+
b.PutByteRvs(static_cast<unsigned char>(0x80 | \
197+
static_cast<unsigned char>((code_) >> 7))); \
198+
b.PutByteRvs(static_cast<unsigned char>(0x80 | \
199+
static_cast<unsigned char>((code_) >> 14))); \
200+
b.PutByteRvs(static_cast<unsigned char>( \
201+
static_cast<char>(class_) | static_cast<char>(form_) | 31))
202+
203+
#define BEncTag5(b, class_, form_, code_) \
204+
5; \
205+
b.PutByteRvs(static_cast<unsigned char>((code_) & 0x7F)); \
206+
b.PutByteRvs(static_cast<unsigned char>(0x80 | \
207+
static_cast<unsigned char>((code_) >> 7))); \
208+
b.PutByteRvs(static_cast<unsigned char>(0x80 | \
209+
static_cast<unsigned char>((code_) >> 14))); \
210+
b.PutByteRvs(static_cast<unsigned char>(0x80 | \
211+
static_cast<unsigned char>((code_) >> 21))); \
212+
b.PutByteRvs(static_cast<unsigned char>( \
213+
static_cast<char>(class_) | static_cast<char>(form_) | 31))
201214

202215
AsnLen SNACCDLL_API PEncTag(AsnBufBits& b, unsigned char ucClass,
203216
unsigned char form, long code, long lByteCount);

0 commit comments

Comments
 (0)