13
13
#define CPPTRACE_MAYBE_UNUSED __attribute__ ((unused))
14
14
#endif
15
15
16
- #include < stdlib.h>
17
- #include < stdio.h>
16
+ #include < cstdint>
17
+ #include < cstdio>
18
+ #include < cstdlib>
19
+ #include < ios>
20
+ #include < sstream>
18
21
#include < string>
22
+ #include < utility>
19
23
#include < vector>
20
- #include < sstream>
21
24
22
25
// Lightweight std::source_location.
23
26
struct source_location {
27
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
24
28
const char * const file;
25
29
// const char* const function; // disabled for now due to static constexpr restrictions
30
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
26
31
const int line;
27
32
constexpr source_location (
28
33
// const char* _function /*= __builtin_FUNCTION()*/,
@@ -44,14 +49,20 @@ static void primitive_assert_impl(
44
49
const char * action = verify ? " verification" : " assertion" ;
45
50
const char * name = verify ? " verify" : " assert" ;
46
51
if (message == nullptr ) {
47
- fprintf (stderr, " Cpptrace %s failed at %s:%d: %s\n " ,
48
- action, location.file , location.line , signature);
52
+ (void ) fprintf (
53
+ stderr,
54
+ " Cpptrace %s failed at %s:%d: %s\n " ,
55
+ action, location.file , location.line , signature
56
+ );
49
57
} else {
50
- fprintf (stderr, " Cpptrace %s failed at %s:%d: %s: %s\n " ,
51
- action, location.file , location.line , signature, message);
58
+ (void ) fprintf (
59
+ stderr,
60
+ " Cpptrace %s failed at %s:%d: %s: %s\n " ,
61
+ action, location.file , location.line , signature, message
62
+ );
52
63
}
53
- fprintf (stderr, " primitive_%s(%s);\n " , name, expression);
54
- abort ();
64
+ ( void ) fprintf (stderr, " primitive_%s(%s);\n " , name, expression);
65
+ std:: abort ();
55
66
}
56
67
}
57
68
@@ -70,15 +81,15 @@ void nothing() {}
70
81
#endif
71
82
72
83
CPPTRACE_MAYBE_UNUSED
73
- static std::vector<std::string> split (const std::string& s , const std::string& delims) {
84
+ static std::vector<std::string> split (const std::string& str , const std::string& delims) {
74
85
std::vector<std::string> vec;
75
86
size_t old_pos = 0 ;
76
87
size_t pos = 0 ;
77
- while ((pos = s .find_first_of (delims, old_pos)) != std::string::npos) {
78
- vec.emplace_back (s .substr (old_pos, pos - old_pos));
88
+ while ((pos = str .find_first_of (delims, old_pos)) != std::string::npos) {
89
+ vec.emplace_back (str .substr (old_pos, pos - old_pos));
79
90
old_pos = pos + 1 ;
80
91
}
81
- vec.emplace_back (std::string (s .substr (old_pos) ));
92
+ vec.emplace_back (str .substr (old_pos));
82
93
return vec;
83
94
}
84
95
@@ -98,22 +109,22 @@ static std::string join(const C& container, const std::string& delim) {
98
109
return str;
99
110
}
100
111
101
- constexpr const char * const ws = " \t\n\r\f\v " ;
112
+ constexpr const char * const whitespace = " \t\n\r\f\v " ;
102
113
103
114
CPPTRACE_MAYBE_UNUSED
104
- static std::string trim (const std::string& s ) {
105
- if (s == " " ) {
115
+ static std::string trim (const std::string& str ) {
116
+ if (str. empty () ) {
106
117
return " " ;
107
118
}
108
- size_t l = s .find_first_not_of (ws );
109
- size_t r = s .find_last_not_of (ws ) + 1 ;
110
- return s .substr (l, r - l );
119
+ const size_t left = str .find_first_not_of (whitespace );
120
+ const size_t right = str .find_last_not_of (whitespace ) + 1 ;
121
+ return str .substr (left, right - left );
111
122
}
112
123
113
124
CPPTRACE_MAYBE_UNUSED
114
125
static std::string to_hex (uintptr_t addr) {
115
126
std::stringstream sstream;
116
- sstream<<std::hex<<uintptr_t ( addr) ;
127
+ sstream<<std::hex<<addr;
117
128
return std::move (sstream).str ();
118
129
}
119
130
0 commit comments