Skip to content

[BUG] -Wunused-result warnings in generated code #7934

Open

Description

@Flamefire

Describe the bug

For some functions decorated with warn_unused_result the generated C code shows warnings -Wunused-result

Cause is that the (void)(call_foo()) current pattern is not enough as generated by

result = "(void)(%s)" % result

See https://godbolt.org/z/YvK6f9z6o

An alternative could be a temporary variable or for negatable return types: (void)!(call_foo())

Code to reproduce the behaviour:

from posix cimport unistd

cdef int fd

def foo():
    unistd.write(fd, b"1", 1)

-> Yields (void)(write(__pyx_v_fd, __pyx_k_1, 1));

Expected behaviour

Warning free code

OS

No response

Python version

No response

Cython version

No response

Additional context

No response

Activity

  1. da-woods commented on Aug 26, 2026

    @da-woods
    Collaborator

    This is happening because write is declared with an attribute that says "this really really shouldn't be ignored". And that attribute is strong enough to bypass the (void) cast. If that's the case then surely the warning is appropriate and so Cython shouldn't go to great lengths to override it - it's a genuine error in your code and if you care enough to set -Werror=unused-result then you should want to see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions