Skip to content

clang warns "warning: redefinition of typedef 'PyTypeObject' is a C11 feature [-Wtypedef-redefinition]" #83752

Closed

Description

@colesbury
BPO 39571
Nosy @vstinner, @colesbury
PRs
  • bpo-39571: Fix clang warning on PyTypeObject typedef #18385
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-02-07.00:49:45.257>
    created_at = <Date 2020-02-06.17:09:38.996>
    labels = ['expert-C-API', '3.9']
    title = 'clang warns "warning: redefinition of typedef \'PyTypeObject\' is a C11 feature [-Wtypedef-redefinition]"'
    updated_at = <Date 2020-02-07.00:49:45.256>
    user = 'https://github.com/colesbury'

    bugs.python.org fields:

    activity = <Date 2020-02-07.00:49:45.256>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-02-07.00:49:45.257>
    closer = 'vstinner'
    components = ['C API']
    creation = <Date 2020-02-06.17:09:38.996>
    creator = 'colesbury'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39571
    keywords = ['patch']
    message_count = 7.0
    messages = ['361497', '361506', '361507', '361509', '361512', '361520', '361521']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'colesbury']
    pr_nums = ['18385']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue39571'
    versions = ['Python 3.9']

    Activity

    1. colesbury commented on Feb 6, 2020

      @colesbury
      ContributorAuthor

      A recent commit added a typedef for PyTypeObject in Include/object.h

      0e4e735

      This duplicates the typedef in Include/cpython/object.h. Building with clang now issues a warning:

      ./Include/cpython/object.h:274:3: warning: redefinition of typedef 'PyTypeObject' is a C11 feature [-Wtypedef-redefinition]

      This is due to the combination of -Wall and -std=c99. GCC will only warn if the -pedantic option is specified.

    2. vstinner commented on Feb 6, 2020

      @vstinner
      Member

      Sorry, I only tested GCC and I forgot that clang is more pedantic on duplicated typedef. I looked better with PyTypeObject, but the fix is easy: just revert my change: PR 18384.

    3. colesbury commented on Feb 6, 2020

      @colesbury
      ContributorAuthor

      Alternatively I think you can just remove the typedef from Include/cpython/object.h since Include/object.h is always included first. i.e.:

      typedef struct _typeobject {
        ...
      } PyTypeObject;

      to simply

      struct _typeobject {
        ...
      };
    4. vstinner commented on Feb 6, 2020

      @vstinner
      Member

      Alternatively I think you can just remove the typedef from Include/cpython/object.h since Include/object.h is always included first. i.e.:

      Oh, nice! I proposed PR 18385. Would you mind to confirm that it fix the issue for you? At least, I tested manually and the clang warning goes away with this change.

    5. colesbury commented on Feb 6, 2020

      @colesbury
      ContributorAuthor

      Yes, that fixes the warnings for me. Thanks!

    6. vstinner commented on Feb 7, 2020

      @vstinner
      Member

      New changeset f95cd19 by Victor Stinner in branch 'master':
      bpo-39571: Fix clang warning on PyTypeObject typedef (GH-18385)
      f95cd19

    7. vstinner commented on Feb 7, 2020

      @vstinner
      Member

      Thanks Sam Gross for the hint, it's now fixed.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions