[gdal-dev] clang-tidy 23 bugprone-signed-bitwise and CPL_LSBINT32PTR macros

Andrew C Aitchison gdal at aitchison.me.uk
Sun May 10 07:02:24 PDT 2026


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
                    andrew at aitchison.me.uk


More information about the gdal-dev mailing list