Resolve some compiler warnings#328
Merged
vincent-richard merged 3 commits intokisli:masterfrom Nov 4, 2025
Merged
Conversation
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.
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; ```
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
clang has turned up a few.