Skip to content

Resolve some compiler warnings#328

Merged
vincent-richard merged 3 commits intokisli:masterfrom
grommunio:clang
Nov 4, 2025
Merged

Resolve some compiler warnings#328
vincent-richard merged 3 commits intokisli:masterfrom
grommunio:clang

Conversation

@jengelh
Copy link
Contributor

@jengelh jengelh commented Oct 28, 2025

clang has turned up a few.

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.
@vincent-richard vincent-richard merged commit a91394a into kisli:master Nov 4, 2025
1 check passed
@jengelh jengelh deleted the clang branch November 7, 2025 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants