[gdal-dev] port/cpl_json.h and clang -Wsign-conversion

Even Rouault even.rouault at spatialys.com
Tue Jan 27 06:08:04 PST 2026


Hi Andrew,

We don't enable -Wsign-conversion in GDAL builds, hence it went under 
the radar. That said nothing wrong in you enabling it for your own code.

I've fixed the issue in https://github.com/OSGeo/gdal/pull/13785 and 
also added a CI check so that our exported headers pass -Wsign-conversion

Even

Le 27/01/2026 à 13:32, Andrew C Aitchison via gdal-dev a écrit :
>
> The recent commit 76ade06580d5f6b4f710d41214647abf36be9fdc
> includes this change:
>
> @@ -279,6 +299,13 @@ class CPL_DLL CPLJSONArray : public CPLJSONObject
>      /*! @endcond */
>    public:
>      int Size() const;
> +
> +    //! Return the size of the array
> +    inline size_t size() const
> +    {
> +        return Size();
> +    }
> +
>      void AddNull();
>      void Add(const CPLJSONObject &oValue);
>      void Add(const std::string &osValue);
>
> I usually build my driver with clang++ -Werror -Wsign-conversion
> but this compile is catching the change:
>
> clang++-22 -fPIC -I/usr/local/gdal/git.llvm/include -Weffc++ -g -Og 
> -Wall -Wextra -DFRMT_vrc -DVRC_STANDALONE
> -Wno-unknown-pragmas -Wall -Wextra -Werror -Wno-unknown-pragmas 
> -Weverything -Wno-c++17-attribute-extensions
> -Wno-error=unknown-warning-option -Wno-format-pedantic 
> -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded
> -Wno-reserved-identifier -Werror=incompatible-function-pointer-types 
> -Wno-unsafe-buffer-usage -Wno-error=unknown-warning-option
> -c -o VRC.o VRC.cpp
> In file included from VRC.cpp:37:
> In file included from ./VRC.h:61:
> In file included from /usr/local/gdal/git.llvm/include/gdal_pam.h:22:
> In file included from /usr/local/gdal/git.llvm/include/gdal_priv.h:46:
> In file included from /usr/local/gdal/git.llvm/include/ogr_feature.h:20:
> In file included from /usr/local/gdal/git.llvm/include/ogr_geometry.h:19:
> /usr/local/gdal/git.llvm/include/cpl_json.h:306:16: error: implicit 
> conversion changes
>       signedness: 'int' to 'size_t' (aka 'unsigned long') 
> [-Werror,-Wsign-conversion]
>   306 |         return Size();
>       |         ~~~~~~ ^~~~~~
>
> Am I wrong to be using -Wsign-conversion even though it has worked
> until now ?
>
> Thanks,
>
-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the gdal-dev mailing list