Skip to content

Fix: Under Clang compilation constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression#9049

Open
Khalyutin wants to merge 1 commit into
FirebirdSQL:masterfrom
notesoft:prepare-for-CMake-Clang-ThreadStart-h
Open

Fix: Under Clang compilation constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression#9049
Khalyutin wants to merge 1 commit into
FirebirdSQL:masterfrom
notesoft:prepare-for-CMake-Clang-ThreadStart-h

Conversation

@Khalyutin
Copy link
Copy Markdown
Contributor

@Khalyutin Khalyutin commented Jun 2, 2026

The compiler does not consider "#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)" as a constant - compilation error: constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression

In Windows 10.0.26100.0 INVALID_HANDLE_VALUE define C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um\handleapi.h as
#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)

clang interpret "((HANDLE)(.." as reinterpret_cast operation and raise error:

[build]    77 |         constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
[build] /code/src/remote\../remote\../common/ThreadStart.h:77:26: error: constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression
[build]    77 |         constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
[build]       |                                 ^                ~~~~~~~~~~~~~~~~~~~~
[build] /code/src/remote\../remote\../common/ThreadStart.h:77:43: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
[build]    77 |         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)
[build]       |                               ^

No excepton in MSVS compiler. Clang has more hard control of a constant expression...

…ANDLE)(LONG_PTR)-1)" as a constant - compilation error: constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression

```
[build]    77 |         constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
[build] /code/src/remote\../remote\../common/ThreadStart.h:77:26: error: constexpr variable 'INVALID_HANDLE' must be initialized by a constant expression
[build]    77 |         constexpr static Handle INVALID_HANDLE = INVALID_HANDLE_VALUE;
[build]       |                                 ^                ~~~~~~~~~~~~~~~~~~~~
[build] /code/src/remote\../remote\../common/ThreadStart.h:77:43: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
[build]    77 |         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)
[build]       |                               ^
```
@aafemt
Copy link
Copy Markdown
Contributor

aafemt commented Jun 2, 2026

Why not to return to #define INVALID_HANDLE INVALID_HANDLE_VALUE?

@Khalyutin
Copy link
Copy Markdown
Contributor Author

Why not to return to #define INVALID_HANDLE INVALID_HANDLE_VALUE?

We're trying to solve the problem of compiling and building CMake+Clang without changing the approaches adopted in Firebird to avoid things complicating...

@hvlad hvlad self-assigned this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants