clang-tidy 23 bugprone-signed-bitwise and CPL_LSBINT32PTR macros

Andrew C Aitchison via gdal-dev <[email protected]>
Newsgroups gmane.comp.gis.gdal.devel
Message-ID <[email protected]>
clang-tidy 23 (I'm using Ubuntu 26.04 with build
++20260508083129+d791e3a6f4c8-1~exp1~20260508083148.481
from llvm-toolchain-snapshot at https://www.llvm.org/)
has a new? check bugprone-signed-bitwise.

This check objects to macros like CPL_LSBINT32PTR:

clang-tidy --config="{Checks: 'bugprone-signed-bitwise', CheckOptions: {bugprone-signed-bitwise.IgnorePositiveIntegerLiterals: true}}" frmts/raw/lcpdataset.cpp

reports 63 warnings of [bugprone-signed-bitwise], starting with:

/home/werdna/gdal/git/frmts/raw/lcpdataset.cpp:171:10: warning: use of a signed integer operand with a binary bitwise operator [bugprone-signed-bitwise]
   171 |     if ((CPL_LSBSINT32PTR(poOpenInfo->pabyHeader) != 20 &&
       |          ^
/usr/local/gdal/git.llvm/include/cpl_port.h:799:53: note: expanded from macro 'CPL_LSBSINT32PTR'
   799 | #define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
       | 
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/local/gdal/git.llvm/include/cpl_port.h:786:6: note: expanded from macro 'CPL_LSBINT32PTR'
   786 |     ((*CPL_REINTERPRET_CAST(const GByte *, x)) |                  \
       |      ^
   787 |      (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8U) |    \
   788 |      (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 2) << 16U) |   \
       |                                                               ~
/usr/local/gdal/git.llvm/include/cpl_port.h:181:55: note: expanded from 
macro 'CPL_STATIC_CAST'
   181 | #define CPL_STATIC_CAST(type, expr) static_cast<type>(expr)
       |                                                       ^~~~

I suspect that default type-promotion from an unsigned GByte
to a *signed* int does not help here.

Not exactly a bug, but annoying.

-- 
Andrew C. Aitchison                      Kendal, UK
                    [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.