Skip to content

Unused code warning in _testembed.c #125517

Closed
@sobolevn

Description

@sobolevn

Bug report

Link: https://github.com/python/cpython/actions/runs/11333284963/job/31517440086#step:6:1315

Report:

./Programs/_testembed.c:1904:5: warning: code will never be executed [-Wunreachable-code]
    const char *err_msg;
    ^~~~~~~~~~~~~~~~~~~~
sed -e "s,/usr/bin/env python3,/usr/local/bin/python3.14," < ./Tools/scripts/pydoc3 > build/scripts-3.14/pydoc3.14
./Programs/_testembed.c:2052:5: warning: code will never be executed [-Wunreachable-code]
    const char *err_msg;
sed -e "s,@EXENAME@,/usr/local/bin/python3.14," < ./Misc/python-config.in >python-config.py
    ^~~~~~~~~~~~~~~~~~~~

Source of problem:

  • We cannot have goto targets on variable declarations.
  • So, they are declared right above:

    cpython/Programs/_testembed.c

    Lines 1903 to 1910 in cc5a225

    return 0;
    const char *err_msg;
    error:
    (void)PyInitConfig_GetError(config, &err_msg);
    printf("Python init failed: %s\n", err_msg);
    exit(1);
    }
  • So, this warning marks const char *err_msg; as unreachable code

I propose to declare this variable before the first goto. This way we can remove this warning. And since this is just a test, we can do that freely.

Linked PRs

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions