Skip to content

Cast error with _Py_TryIncrefCompareStackRef and -Wc++11-narrowing #131782

@nascheme

Description

@nascheme

Bug report

Bug description:

The current main branch fails to build if the -Wc++11-narrowing option is used:

internal/pycore_stackref.h:649:39: error: non-constant-expression cannot be narrowed from type 'intptr_t' (aka 'long') to 'uintptr_t' (aka 'unsigned long') in initializer list [-Wc++11-narrowing]

        649 |         *out = (_PyStackRef){ .bits = (intptr_t)op | Py_TAG_DEFERRED };
            |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The fix is to change the cast to uintptr_t which matches the type of .bits.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions