Re: [firebird-devel] constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;

24 views
Skip to first unread message
Message has been deleted

Dimitry Sibiryakov

unread,
Feb 20, 2026, 5:40:25 AM (3 days ago) Feb 20
to firebir...@googlegroups.com
Sergey Khalyutin wrote 20.02.2026 11:38:
> In my build case  INVALID_HANDLE_VALUE

It means that your build doesn't define macro WIN_NT on Windows as it has to.

--
WBR, SD.

Sergey Khalyutin

unread,
Feb 20, 2026, 5:43:23 AM (3 days ago) Feb 20
to firebird-devel
#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
from C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um\handleapi.h

hide  INVALID_HANDLE_VALUE  (-1)
from  src\common\common.h

// In many cases we need to assign wrong handle value to closed handle
// Some OSes define it, others - not
#ifndef WIN_NT
#ifndef INVALID_HANDLE_VALUE
#define INVALID_HANDLE_VALUE (-1)
#endif
#endif


sory,  orign masage deleted unexpected

Dimitry Sibiryakov

unread,
Feb 20, 2026, 5:46:02 AM (3 days ago) Feb 20
to firebir...@googlegroups.com
Sergey Khalyutin wrote 20.02.2026 11:43:
> #defineINVALID_HANDLE_VALUE((HANDLE)(LONG_PTR)-1)
> from C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um\handleapi.h
>
> hide INVALID_HANDLE_VALUE (-1)
> from src\common\common.h

Do you really have file C:\Program Files (x86)\Windows
Kits\10\Include\10.0.26100.0\um\handleapi.h on non-Windows OS?

--
WBR, SD.

Sergey Khalyutin

unread,
Feb 20, 2026, 6:06:32 AM (3 days ago) Feb 20
to firebird-devel
I`m  under win11

INVALID_HANDLE_VALUE (-1)  actual if NOT   WIN_NT and NOT defined befor 


build error is:
constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression

in src\common\common.h
INVALID_HANDLE_VALUE is const INVALID_HANDLE but in C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um\handleapi.h is MACRO #define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)

replace

-- constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE; ++ inline static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
solved compilation error. But how is right?
[build] In file included from /src/remote\../remote/remote.h:35:
[build] /src/remote\../remote\../common/ThreadStart.h:78:26: error: constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression
[build]    78 |         constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
[build]       |                                 ^                ~~~~~~~~~~~~~~~~~~~~
[build] /src/remote\../remote\../common/ThreadStart.h:78:43: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
[build]    78 |         constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
[build]       |                                                  ^
[build] C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um\handleapi.h:27:31: note: expanded from macro 'INVALID_HANDLE_VALUE'
[build]    27 | #define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)



Sergey Khalyutin

unread,
Feb 20, 2026, 6:11:11 AM (3 days ago) Feb 20
to firebird-devel
if (WIN32)
    set(LLVM_win "C:/TOOLSET/LLVM")
    set(clang_rt_lib_dir_win "C:/TOOLSET/LLVM/lib/clang/21/lib/windows")
    set(libtommath_ID   libtommath)
    set(libtomcrypt_ID libtomcrypt)
    add_definitions(-DWIN_NT) <-- direct forfard defenition not solved problem :(

    unset(BUILD_ICU_WITH_VER)
    set(ICU_VERSION 77)
endif()

Dimitry Sibiryakov

unread,
Feb 20, 2026, 6:12:00 AM (3 days ago) Feb 20
to firebir...@googlegroups.com
Sergey Khalyutin wrote 20.02.2026 12:06:
> I`m  under win11
>
> INVALID_HANDLE_VALUE (-1)  actual if NOT WIN_NT and NOT defined befor

Then I repeat my answer:

Every build on Windows has to define macro WIN_NT at command-line level or in
autoconfig.h.

Every build on non-Windows has to not define this macro.

--
WBR, SD.

Dimitry Sibiryakov

unread,
Feb 20, 2026, 6:15:10 AM (3 days ago) Feb 20
to firebir...@googlegroups.com
Sergey Khalyutin wrote 20.02.2026 12:11:
> add_definitions(-DWIN_NT) *<-- direct forfard defenition not solved problem :(*

Check the actual command line and autoconfig.h produced by CMake (in the case
if it undefines the macro).

--
WBR, SD.

Sergey Khalyutin

unread,
Feb 20, 2026, 6:20:16 AM (3 days ago) Feb 20
to firebird-devel
Excuse me, I`m do not understand, why do you think that WIN_NT is not defined in my build?

Sergey Khalyutin

unread,
Feb 20, 2026, 6:27:07 AM (3 days ago) Feb 20
to firebird-devel
Complile error: constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression
class Thread
{
public:
#ifdef WIN_NT
    typedef HANDLE Handle;
    //    inline static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
    constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE; <-- Complile error in this line
#endif
#ifdef USE_POSIX_THREADS
    typedef pthread_t Handle;
    constexpr static Handle INVALID_HANDLE = 0;
#endif

Dimitry Sibiryakov

unread,
Feb 20, 2026, 6:41:08 AM (3 days ago) Feb 20
to firebir...@googlegroups.com
Sergey Khalyutin wrote 20.02.2026 12:20:
> Excuse me, I`m do not understand, why do you think that WIN_NT is not defined in
> my build?

Because of these lines in common.h:

> #ifndef WIN_NT
> #ifndef INVALID_HANDLE_VALUE
> #define INVALID_HANDLE_VALUE (-1)
> #endif
> #endif

They define INVALID_HANDLE_VALUE only if WIN_NT is undefined.

Ok, later you changed your mind, so returning to the right question:

> replace
>
> -- constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
> ++ inline static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
>
> solved compilation error. But how is right?

For me the right thing would be to rollback this part of Vlad's refactoring
because POSIX thread handles are opaque and there is no explicitly invalid value
for them, so introduction of unified INVALID_HANDLE value was a mistake in this
case.

--
WBR, SD.

Alex Peshkoff

unread,
Feb 20, 2026, 9:25:05 AM (2 days ago) Feb 20
to firebir...@googlegroups.com
Why rollback? Use of  separate flag in posix case solves a problem.

On the one hand I do not know posix implementations where 0 can't be
used as invalid thread handle. But taking into an account that we try to
be generic and use dedicated pthread compare function - flag will be better.


Dimitry Sibiryakov

unread,
Feb 20, 2026, 9:29:34 AM (2 days ago) Feb 20
to firebir...@googlegroups.com
Alex Peshkoff wrote 20.02.2026 15:25:
> Why rollback? Use of  separate flag in posix case solves a problem.

Pay attention on "this part". I meant to be the introduction of
INVALID_HANDLE constant.

--
WBR, SD.
Reply all
Reply to author
Forward
0 new messages