Commit a91394a
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
956 | 956 | | |
957 | 957 | | |
958 | 958 | | |
959 | | - | |
960 | 959 | | |
961 | 960 | | |
962 | 961 | | |
| |||
977 | 976 | | |
978 | 977 | | |
979 | 978 | | |
980 | | - | |
981 | 979 | | |
982 | 980 | | |
983 | 981 | | |
| |||
986 | 984 | | |
987 | 985 | | |
988 | 986 | | |
989 | | - | |
990 | 987 | | |
991 | 988 | | |
992 | 989 | | |
| |||
999 | 996 | | |
1000 | 997 | | |
1001 | 998 | | |
1002 | | - | |
1003 | 999 | | |
1004 | 1000 | | |
1005 | 1001 | | |
| |||
3712 | 3708 | | |
3713 | 3709 | | |
3714 | 3710 | | |
3715 | | - | |
| 3711 | + | |
3716 | 3712 | | |
3717 | 3713 | | |
3718 | 3714 | | |
| |||
4501 | 4497 | | |
4502 | 4498 | | |
4503 | 4499 | | |
4504 | | - | |
4505 | | - | |
4506 | | - | |
| 4500 | + | |
4507 | 4501 | | |
4508 | 4502 | | |
4509 | 4503 | | |
| |||
0 commit comments