[Libreoffice-bugs] [Bug 131117] New: Don't use static_cast with numeric literals

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Wed Mar 4 10:49:17 UTC 2020


https://bugs.documentfoundation.org/show_bug.cgi?id=131117

            Bug ID: 131117
           Summary: Don't use static_cast with numeric literals
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
          Severity: normal
          Priority: medium
         Component: LibreOffice
          Assignee: libreoffice-bugs at lists.freedesktop.org
          Reporter: mikekaganski at hotmail.com
                CC: sbergman at redhat.com

Throughout the codebase, there are places where a numeric literal is used to
create a value of a specified type, using `static_cast<wanted_type>(literal)`
syntax.

I suppose this is not a correct semantically, since static_cast is to cast some
existing value of a different type into wanted other type; while when literals
are involved, what happens is *creation* of a new value of specified type. In
my opinion, it's better to use function-style (ctor-style) cast syntax here,
like `wanted_type(literal)`.

To see the examples of this (like `static_cast< sal_Int64 >(1)` in [1], which
should become simply `sal_Int64(1)` in this task), grep for

    static_cast\s*<[^>]+>\s*\(\s*-?\d+\.?\d*\s*\)

which gives around 2000 matches currently.

[1] https://opengrok.libreoffice.org/xref/core/sal/rtl/math.cxx?r=1782810f#285

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20200304/9e6c0012/attachment.htm>


More information about the Libreoffice-bugs mailing list