Bug in the cross-compiler?

17 views
Skip to first unread message

Igor Korot

unread,
Sep 20, 2021, 12:40:20 AM9/20/21
to wx-dev
Hi,, (Vadim),

According to https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmenuitemid#return-value,
the function can return -1and it compiles successfully on WIndows
with MSVC 2017 here on my laptop.

However it looks like the cross-compiler can't compile the -1 comparison
(see https://github.com/wxWidgets/wxWidgets/pull/2517/checks?check_run_id=3647822172)).

What is the proper way to fix it?

Thank you.

Vadim Zeitlin

unread,
Sep 20, 2021, 6:10:55 AM9/20/21
to wx-...@googlegroups.com
On Sun, 19 Sep 2021 23:39:45 -0500 Igor Korot wrote:

IK> Hi,, (Vadim),
IK>
IK> According to https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmenuitemid#return-value,
IK> the function can return -1and it compiles successfully on WIndows
IK> with MSVC 2017 here on my laptop.
IK>
IK> However it looks like the cross-compiler can't compile the -1 comparison
IK> (see https://github.com/wxWidgets/wxWidgets/pull/2517/checks?check_run_id=3647822172)).

You're comparing signed value (-1) with an unsigned one (UINT), this has
nothing to do with cross-compiling.

IK> What is the proper way to fix it?

Cast -1 to UINT, just as you already do above. Or define a symbolic
constant INVALID_MENU_ID to avoid having to do the cast twice.

Regards,
VZ

Igor Korot

unread,
Sep 20, 2021, 9:35:46 AM9/20/21
to wx-dev
Vadim,

---------- Forwarded message ---------
From: Vadim Zeitlin <va...@wxwidgets.org>
Date: Mon, Sep 20, 2021 at 5:10 AM
Subject: Re: [wx-dev] Bug in the cross-compiler?
To: <wx-...@googlegroups.com>


On Sun, 19 Sep 2021 23:39:45 -0500 Igor Korot wrote:

IK> Hi,, (Vadim),
IK>
IK> According to
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmenuitemid#return-value,
IK> the function can return -1and it compiles successfully on WIndows
IK> with MSVC 2017 here on my laptop.
IK>
IK> However it looks like the cross-compiler can't compile the -1 comparison
IK> (see https://github.com/wxWidgets/wxWidgets/pull/2517/checks?check_run_id=3647822172)).

You're comparing signed value (-1) with an unsigned one (UINT), this has
nothing to do with cross-compiling.

But then why MSVC is happy?


IK> What is the proper way to fix it?

Cast -1 to UINT, just as you already do above. Or define a symbolic
constant INVALID_MENU_ID to avoid having to do the cast twice.

OK.

Thank you.


Regards,
VZ
noname

Vadim Zeitlin

unread,
Sep 20, 2021, 1:13:22 PM9/20/21
to wx-...@googlegroups.com
On Mon, 20 Sep 2021 08:35:31 -0500 Igor Korot wrote:

IK> But then why MSVC is happy?

Have you really checked that it doesn't give a warning here? I'm almost
sure it does, too.

VZ

David Connet

unread,
Sep 20, 2021, 1:38:18 PM9/20/21
to wx-...@googlegroups.com
It does - sometimes.

"size_t i = -1;" will.

"size_t i = 0; i = -1;" will.

"size_t i = 0; if (i != -1) ..." won't.

I was compiling 64bit/debug/vs2019.

I'm guessing either the warning for that is disabled by default, or is
pragma'd out somewhere. (I run at L4/warnings-as-errors)

Dave

Reply all
Reply to author
Forward
0 new messages