[QGIS-Developer] cppcheck false positive

Alessandro Pasotti apasotti at gmail.com
Tue Sep 29 09:15:07 PDT 2020


On Tue, Sep 29, 2020 at 5:54 PM Matthias Kuhn <matthias at opengis.ch> wrote:
>
>
> On Tue, Sep 29, 2020 at 1:07 PM Alessandro Pasotti <apasotti at gmail.com> wrote:
>>
>> On Tue, Sep 29, 2020 at 12:57 PM Denis Rouzaud <denis.rouzaud at gmail.com> wrote:
>> >
>> > Side question, is there a technical reason to prefer this syntax over the = one?
>> >
>> > The = is more readable to me, but that's a matter of experience I guess.
>> > More generally, it would be nice to decide for one syntax and have a coherence over the source code.
>> >
>> > Cheers,
>> > Denis
>> >
>>
>> Hi Denis,
>>
>> I agree about the need for coherence, we currently have a mix of = ()
>> and {} initialization.
>>
>> I'm not such an expert to tell you which is the best, but I've found
>> this explanations quite convincing:
>>
>> https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es23-prefer-the--initializer-syntax
>> https://stackoverflow.com/questions/18222926/why-is-list-initialization-using-curly-braces-better-than-the-alternatives
>>
>> That is the reason why I switched to {} as my preferred method.
>>
>> Cheers
>>
>> > Le mar. 29 sept. 2020 à 11:55, Alessandro Pasotti <apasotti at gmail.com> a écrit :
>> >>
>> >> Looks like cppcheck is not smart enough...
>> >>
>> >> const double factor { std::pow( 10, - mPrecisionSpinBox->value() ) };
>> >>
>> >> https://github.com/qgis/QGIS/pull/39079/checks?check_run_id=1181360827#step:4:1693
>> >>
>> >> --
>> >> Alessandro Pasotti
>> >> QCooperative:  www.qcooperative.net
>> >> ItOpen:   www.itopen.it
>> >> _______________________________________________
>> >> QGIS-Developer mailing list
>> >> QGIS-Developer at lists.osgeo.org
>> >> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> >> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>>
>>
> There are certainly some advantages of {} (guessing since it wouldn't have been added to the standard otherwise).
>
> However... We have been bitten by incompatibilities (compiler and/or c++ version) more than once. And the more I read about it, the more I am convinced that proper and conscious usage is not a simple task. See also the controversial discussion in the stackoverflow link Alessandro posted.
> So far it has failed to convince me as an adequate mitigation for the problems it tries to solve.
>
> Matthias
>

Hi Matthias,

I agree with you, I hope the compilers will catch up sooner or later,
but I must also say that especially when working on the providers or
other "low" level parts of the code I appreciated the fact that
narrowcasting is prohibited with brace initializers and it made my
code a little more robust and type safe.

OTOH when working with templates and list initializers (like the json
library) things can go south pretty fast.

Anyway, the sad truth is that C++ initialization totally sucks, this
is an interesting reading about that:
http://mikelui.io/2019/01/03/seriously-bonkers.html

Cheers

-- 
Alessandro Pasotti
QCooperative:  www.qcooperative.net
ItOpen:   www.itopen.it


More information about the QGIS-Developer mailing list