Skip to content

[BUG]: token pasting of ',' and __VA_ARGS__ is a GNU extension / pedantic warnings #5310

@N-Wouda

Description

@N-Wouda

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.13.3

Problem description

The most recent release uses , ##__VA_ARGS__ in common.h. This is not technically in the standard (see e.g. here), but most compilers support it. Clang, however, complains about its use when setting -Wpedantic. I can work around this by either not passing -Wpedantic, or passing -Wno-gnu-zero-variadic-macro-arguments, but I'd rather not do that if it can at all be avoided.

Consider the attached example, test.cpp. Compiling it with

clang -Wall -Wextra -Wpedantic -Werror -shared -std=c++20 -fPIC $(python -m pybind11 --includes) test.cpp -o test.so

produces the following:

In file included from test.cpp:1:
In file included from .venv/lib/python3.11/site-packages/pybind11/include/pybind11/pybind11.h:13:
In file included from .venv/lib/python3.11/site-packages/pybind11/include/pybind11/detail/class.h:12:
In file included from .venv/lib/python3.11/site-packages/pybind11/include/pybind11/attr.h:13:
.venv/lib/python3.11/site-packages/pybind11/include/pybind11/detail/common.h:493:57: error: token pasting of ',' and __VA_ARGS__ is a GNU extension [-Werror,-Wgnu-zero-variadic-macro-arguments]
            &PYBIND11_CONCAT(pybind11_module_def_, name),
  \
                                                        ^
1 error generated.

It concerns the following code snippet:

&PYBIND11_CONCAT(pybind11_module_def_, name), \
##__VA_ARGS__); \

I am not sure if pybind needs to consider this a bug or even an issue. But the previous versions of pybind (2.12 and below) worked without a hitch when setting the -Wpedantic option, so I figured I'd let you know about this here.

Reproducible example code

#include <pybind11/pybind11.h>

int test()
{
    return 42;
}

PYBIND11_MODULE(module, m)
{
    m.def("test", &test);
}

Is this a regression? Put the last known working version here if it is.

2.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions