Skip to content

Fix invalid const-qualified function pointer in delayimp.cpp (breaks x86 clang-cl build) - #98

Open
TomJoey wants to merge 1 commit into
ethindp:masterfrom
TomJoey:fix/x86-clang-cl-delayimp-const-auto
Open

Fix invalid const-qualified function pointer in delayimp.cpp (breaks x86 clang-cl build)#98
TomJoey wants to merge 1 commit into
ethindp:masterfrom
TomJoey:fix/x86-clang-cl-delayimp-const-auto

Conversation

@TomJoey

@TomJoey TomJoey commented Aug 16, 2026

Copy link
Copy Markdown

Summary

  • GetProcAddress returns FARPROC (a function pointer). The line
    if (auto const *real = GetProcAddress(...); real != nullptr) in the
    #if defined(_M_IX86) || defined(__i386__) branch of
    DelayLoadFailureHook deduces real as a pointer to a
    const-qualified function type, which isn't a meaningful
    declaration.
  • clang-cl rejects this outright when targeting x86 (-m32):
    error: variable 'real' with type 'const auto *' has incompatible
    initializer of type 'FARPROC' (aka 'int (*)() __attribute__((stdcall)))')
    
  • This branch is only compiled for _M_IX86/__i386__, and the
    project's own build-windows.yml matrix only builds x64/arm64, so
    the build break was never caught by CI.
  • Every other raw pointer in this file (e.g. the LoadLibrary results
    a few lines above, auto *const h = ...) uses auto *const — a
    non-reassignable pointer to non-const data. That's almost certainly
    what was intended here too; real is never reassigned in this
    scope. Switching to that form fixes the x86 clang-cl build without
    changing behavior (MSVC accepted the original spelling as a
    non-conforming extension).

Test plan

GetProcAddress returns FARPROC (a function pointer), and `auto const
*real = ...` deduces `real` as a pointer to a const-qualified function
type, which is not a meaningful/well-formed declaration. clang-cl
rejects it outright under -m32:

    error: variable 'real' with type 'const auto *' has incompatible
    initializer of type 'FARPROC'

This branch is guarded by `#if defined(_M_IX86) || defined(__i386__)`,
which the project's own Windows CI matrix (x64/arm64 only) never
builds, so the break went unnoticed. Every other pointer in this file
(e.g. the `LoadLibrary` results a few lines up) uses the `auto *const`
form instead — a non-reassignable pointer to non-const data — which is
almost certainly what was intended here too. Switching to that form
fixes the x86 clang-cl build without changing behavior.
@ethindp

ethindp commented Aug 17, 2026

Copy link
Copy Markdown
Owner

I currently lack the energy of supporting 32-bit platforms given their increasing rarity, but I will merge this PR if the checks pass. Please note that in order for this PR to be merged you must now add your sign-off per the DCO. (I have been implementing these processes so that contributing is smoother and there is less arbitrary-ness about it.)

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.

2 participants