[pcre-dev] [Bug 2474] Fix a few warnings reported by Visual …

Top Page

Reply to this message
Author: admin
To: pcre-dev
Subject: [pcre-dev] [Bug 2474] Fix a few warnings reported by Visual Studio

--- Comment #2 from Lucas Trzesniewski <lucas.trzesniewski@???> ---

I tried to understand the 3rd case, and here's what I found:
- This function is not compiled on x64, that's why there's no warning on that
- The culprit seems to be the + operator applying a "usual arithmetic
conversion": Both operands are PCRE2_UCHAR16 in my case, therefore unsigned
short, and they get promoted to int. The result type of the + operation is also
int, which gets compared against a sljit_u32, which emits the warning.

Here's the Microsoft documentation page about usual arithmetic conversions in
C: https://docs.microsoft.com/en-us/cpp/c-language/usual-arithmetic-conversions

The relevant parts are:
- Most C operators perform type conversions to bring the operands of an
expression to a common type or to extend short values to the integer size used
in machine operations.
- If none of the above conditions are met, both operands are converted to type

Just to be sure this is not a Microsoft-specific quirk, I checked what the C
standard says, and it seems to agree. See paragraph of
http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf - it contains
information similar to the Microsoft docs, but formulated differently. It
specifies that operands go through an "integer promotion" step which is
described in
- If an int can represent all values of the original type (as restricted by
the width, for a bit-field), the value is converted to an int; otherwise, it is
converted to an unsigned int.

I think this explains why the left operand is converted to a signed integer,
and therefore the warning.

You are receiving this mail because:
You are on the CC list for the bug.