Skip to content

Commit a91394a

Browse files
authored
Resolve some compiler warnings (#328)
* build: resolve 2 instances of -Wpessimizing-move clang 19 on FreeBSD 14.3 warns: ``` /usr/bin/c++ -DDEBUG -Dwmime_EXPORTS -I/home/ej/vmime -I/home/ej/vmime/src -I/usr/local/include -D_REENTRANT=1 -W -Wall -pedantic -Warray-bounds-pointer-arithmetic -Wold-style-cast -Wconversion -Wcast-align -Wno-sign-conversion -fvisibility=hidden -fvisibility-inlines-hidden -O0 -g -std=c++17 -fPIC -DVMIME_SHARED -MD -MT CMakeFiles/wmime.dir/src/vmime/net/imap/IMAPCommand.cpp.o -MF CMakeFiles/wmime.dir/src/vmime/net/imap/IMAPCommand.cpp.o.d -o CMakeFiles/wmime.dir/src/vmime/net/imap/IMAPCommand.cpp.o -c /home/ej/vmime/src/vmime/net/imap/IMAPCommand.cpp In file included from IMAPCommand.cpp:31: In file included from IMAPConnection.hpp:40: IMAPParser.hpp:3715:20: warning: moving a temporary object prevents copy elision [-Wpessimizing-move] | items.push_back(std::move(std::unique_ptr <msg_att_item>(parser.get <msg_att_item>(line, &pos)))); IMAPParser.hpp:3715:20: note: remove std::move call here | items.push_back(std::move(std::unique_ptr <msg_att_item>(parser.get <msg_att_item>(line, &pos)))); IMAPParser.hpp:4504:6: warning: moving a temporary object prevents copy elision [-Wpessimizing-move] | std::move( IMAPParser.hpp:4504:6: note: remove std::move call here | std::move( ``` std::unique_ptr<T>(expr) is already an rvalue; invoking move() is just redundant there. * build: resolve 1 instance of -Wunused-but-set-variable clang 19 on FreeBSD 14.3 warns: ``` In file included from IMAPCommand.cpp:31: In file included from IMAPConnection.hpp:40: IMAPParser.hpp:959:11: warning: variable 'len' set but not used [-Wunused-but-set-variable] | size_t len = 0; ``` * build: resolve 2 instances of -Wimplicit-int-conversion clang 19 on FreeBSD 14.3 warns: ``` IMAPMessage.cpp:112:11: warning: higher order bits are zeroes after implicit conversion [-Wimplicit-int-conversion] 112 | m_size(-1U), | ~^~~ IMAPMessage.cpp:183:16: warning: higher order bits are zeroes after implicit conversion [-Wimplicit-int-conversion] 183 | if (m_size == -1U) { | ~~ ^~~ ``` -1U is UINT_MAX; assigning that to size_t does not change the value (stays UINT_MAX, does not become SIZE_MAX). What is really intended here is ``size_t(-1)`` (or syntactically equivalents). This is equal to ``size_t(0) - 1`` as per https://en.cppreference.com/w/c/language/conversion.html § Integer conversions ("repeatedly subtracted"), and because unsigned integers implement modulo arithmetic, we get SIZE_MAX as desired.
1 parent 7046a43 commit a91394a

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

src/vmime/net/imap/IMAPMessage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ IMAPMessage::IMAPMessage(
109109
)
110110
: m_folder(folder),
111111
m_num(num),
112-
m_size(-1U),
112+
m_size(-1),
113113
m_flags(FLAG_UNDEFINED),
114114
m_expunged(false),
115115
m_modseq(0),
@@ -180,7 +180,7 @@ vmime_uint64 IMAPMessage::getModSequence() const {
180180

181181
size_t IMAPMessage::getSize() const {
182182

183-
if (m_size == -1U) {
183+
if (m_size == static_cast<size_t>(-1)) {
184184
throw exceptions::unfetched_object();
185185
}
186186

src/vmime/net/imap/IMAPParser.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,6 @@ class VMIME_EXPORT IMAPParser : public object {
956956
bool parseImpl(IMAPParser& parser, string& line, size_t* currentPos) {
957957

958958
size_t pos = *currentPos;
959-
size_t len = 0;
960959
bool valid = false;
961960

962961
value.reserve(line.length() - pos);
@@ -977,7 +976,6 @@ class VMIME_EXPORT IMAPParser : public object {
977976
quoted = false;
978977

979978
++pos;
980-
++len;
981979

982980
} else {
983981

@@ -986,7 +984,6 @@ class VMIME_EXPORT IMAPParser : public object {
986984
quoted = true;
987985

988986
++pos;
989-
++len;
990987

991988
} else if (c == '"') {
992989

@@ -999,7 +996,6 @@ class VMIME_EXPORT IMAPParser : public object {
999996
value += c;
1000997

1001998
++pos;
1002-
++len;
1003999

10041000
} else {
10051001

@@ -3712,7 +3708,7 @@ class VMIME_EXPORT IMAPParser : public object {
37123708

37133709
VIMAP_PARSER_CHECK(one_char <'('> );
37143710

3715-
items.push_back(std::move(std::unique_ptr <msg_att_item>(parser.get <msg_att_item>(line, &pos))));
3711+
items.push_back(std::unique_ptr <msg_att_item>(parser.get <msg_att_item>(line, &pos)));
37163712

37173713
while (!VIMAP_PARSER_TRY_CHECK(one_char <')'> )) {
37183714
VIMAP_PARSER_CHECK(SPACE);
@@ -4501,9 +4497,7 @@ class VMIME_EXPORT IMAPParser : public object {
45014497
while ((resp = parser.get <IMAPParser::continue_req_or_response_data>(curLine, &pos))) {
45024498

45034499
continue_req_or_response_data.push_back(
4504-
std::move(
4505-
std::unique_ptr <IMAPParser::continue_req_or_response_data>(resp)
4506-
)
4500+
std::unique_ptr <IMAPParser::continue_req_or_response_data>(resp)
45074501
);
45084502

45094503
// Partial response (continue_req)

0 commit comments

Comments
 (0)