Skip to content

Commit 5c9a452

Browse files
authored
Merge fallthrough to cpp (#1052)
Fix warnings on merge fallthroughs
1 parent 2722500 commit 5c9a452

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

tinyxml2.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ distribution.
3232
# include <cstdarg>
3333
#endif
3434

35+
// Handle fallthrough attribute for different compilers
36+
#ifndef __has_attribute
37+
# define __has_attribute(x) 0
38+
#endif
39+
#ifndef __has_cpp_attribute
40+
# define __has_cpp_attribute(x) 0
41+
#endif
42+
43+
#if defined(_MSC_VER)
44+
# define TIXML_FALLTHROUGH (void(0))
45+
#elif (__cplusplus >= 201703L && __has_cpp_attribute(fallthrough))
46+
# define TIXML_FALLTHROUGH [[fallthrough]]
47+
#elif __has_cpp_attribute(clang::fallthrough)
48+
# define TIXML_FALLTHROUGH [[clang::fallthrough]]
49+
#elif __has_attribute(fallthrough)
50+
# define TIXML_FALLTHROUGH __attribute__((fallthrough))
51+
#else
52+
# define TIXML_FALLTHROUGH (void(0))
53+
#endif
54+
55+
3556
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
3657
// Microsoft Visual Studio, version 2005 and higher. Not WinCE.
3758
/*int _snprintf_s(
@@ -446,17 +467,17 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length
446467
--output;
447468
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
448469
input >>= 6;
449-
//fall through
470+
TIXML_FALLTHROUGH;
450471
case 3:
451472
--output;
452473
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
453474
input >>= 6;
454-
//fall through
475+
TIXML_FALLTHROUGH;
455476
case 2:
456477
--output;
457478
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
458479
input >>= 6;
459-
//fall through
480+
TIXML_FALLTHROUGH;
460481
case 1:
461482
--output;
462483
*output = static_cast<char>(input | FIRST_BYTE_MARK[*length]);

0 commit comments

Comments
 (0)