Skip to content

The Python library will not compile with a C++2020 compiler because the code uses the reserved “module” keyword #83536

Closed

Description

@aCuria
mannequin
BPO 39355
Nosy @vstinner, @encukou, @serhiy-storchaka, @corona10, @erlend-aasland, @aCuria, @AliyevH
PRs
  • bpo-39355: Renamed module argument to pyModule in header files #28359
  • bpo-39355: Renamed module argument to pyModule in header files #28373
  • bpo-39355: making Python.h compatible with C++20 compilers #31282
  • gh-91321: Add _testcppext C++ extension #32175
  • 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 2022-03-29.13:39:30.927>
    created_at = <Date 2020-01-16.09:25:21.719>
    labels = ['easy', '3.9', '3.10', '3.11', 'expert-C-API', 'type-feature', 'invalid']
    title = 'The Python library will not compile with a C++2020 compiler because the code uses the reserved \xe2\x80\x9cmodule\xe2\x80\x9d keyword'
    updated_at = <Date 2022-03-30.14:14:56.748>
    user = 'https://github.com/aCuria'

    bugs.python.org fields:

    activity = <Date 2022-03-30.14:14:56.748>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-29.13:39:30.927>
    closer = 'vstinner'
    components = ['C API']
    creation = <Date 2020-01-16.09:25:21.719>
    creator = 'aCuria'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39355
    keywords = ['patch', 'easy (C)']
    message_count = 19.0
    messages = ['360103', '360106', '360110', '360115', '398915', '399073', '399975', '401109', '401778', '413056', '414646', '414654', '416253', '416254', '416255', '416256', '416257', '416259', '416360']
    nosy_count = 7.0
    nosy_names = ['vstinner', 'petr.viktorin', 'serhiy.storchaka', 'corona10', 'erlendaasland', 'aCuria', 'AliyevH']
    pr_nums = ['28359', '28373', '31282', '32175']
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue39355'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. aCuria commented on Jan 16, 2020

      aCuriamannequin
      MannequinAuthor
      The Python library will not compile with a C++2020 compiler because the code uses the reserved “module” keyword
       
      For example, in warnings.h, we have the following code:
       
      #ifndef Py_LIMITED_API
      PyAPI_FUNC(int) PyErr_WarnExplicitObject(
          PyObject *category,
          PyObject *message,
          PyObject *filename,
          int lineno,
          PyObject *module,
      PyObject *registry);
       
       
      In modsupport.h we have the following code:
      PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
       
      We can fix this by using a different identifier, for example “pyModule” instead of “module”
    2. serhiy-storchaka commented on Jan 16, 2020

      @serhiy-storchaka
      Member

      Names of arguments can be just removed from function declarations in header files.

    3. vstinner commented on Jan 16, 2020

      @vstinner
      Member

      Qt has a similar issue with "slots": bpo-1086854 and bpo-38007.

    4. 14 remaining items

    5. added
      3.11only security fixes
      and removed on Mar 29, 2022
    6. vstinner commented on Mar 29, 2022

      @vstinner
      Member

      I wrote the draft PR #76356 to test https://bugs.python.org/issue39355 and #75463. Problem: I don't get any compiler warning or error about the "module" C++20 keyword. I tested GCC 11.2.1 and clang 13.0.0 of Fedora 35.

    7. vstinner commented on Mar 29, 2022

      @vstinner
      Member

      The C++20 "module" keyword is "contextual keyword". It's only a keyword if the first line if a file contains "module".

      It's not the case in any .h file of the Python C API, so Python doesn't need to be changed. I close the issue.

    8. erlend-aasland commented on Mar 29, 2022

      @erlend-aasland
      Contributor

      The C++20 "module" keyword is "contextual keyword". It's only a keyword if the first line if a file contains "module".

      Great! No changes needed. Thanks for investigating.

    9. vstinner commented on Mar 30, 2022

      @vstinner
      Member

      Follow-up issue: bpo-47165 "[C API] Test that the Python C API is compatible with C++".

    10. 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