-
Notifications
You must be signed in to change notification settings - Fork 2.2k
"anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]" #1204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've run into this as well. Since I'm using the provided CMake macros (thank you for this, btw), I would be fine with a solution like this: diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake
index a7c471a..b8bfb1c 100644
--- a/tools/pybind11Tools.cmake
+++ b/tools/pybind11Tools.cmake
@@ -130,7 +130,7 @@ function(pybind11_add_module target_name)
add_library(${target_name} ${lib_type} ${exclude_from_all} ${ARG_UNPARSED_ARGUMENTS})
- target_include_directories(${target_name}
+ target_include_directories(${target_name} SYSTEM
PRIVATE ${PYBIND11_INCLUDE_DIR} # from project CMakeLists.txt
PRIVATE ${pybind11_INCLUDE_DIR} # from pybind11Config
PRIVATE ${PYTHON_INCLUDE_DIRS}) |
I'm not a big fan of this approach -- it would be better to suppress this warning as is already done for others. The include files should be warning-free without any special compiler flags. |
Was just a suggestion in case getting the headers warning free was too intrusive. Obviously I'd prefer a solution that works for everyone as well. |
So rather diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h
index 82f8a48..ad152f3 100644
--- a/include/pybind11/pybind11.h
+++ b/include/pybind11/pybind11.h
@@ -38,6 +38,9 @@
# if __GNUC__ >= 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
# endif
+#elif defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wnested-anon-types"
#endif
#include "attr.h"
@@ -1979,4 +1982,6 @@ NAMESPACE_END(PYBIND11_NAMESPACE)
/* Leave ignored warnings on */
#elif defined(__GNUG__) && !defined(__clang__)
# pragma GCC diagnostic pop
+#elif defined(__clang__)
+# pragma clang diagnostic pop
#endif Should I open a PR for that? |
Thank you -- yes, please do. |
The anonymous struct nested in a union triggers a -Wnested-anon-type warning ("anonymous types declared in an anonymous union are an extension") under clang (pybind#1204). This names the struct and defines it out of the definition of `instance` to get around to warning (and makes the code slightly simpler).
The anonymous struct nested in a union triggers a -Wnested-anon-type warning ("anonymous types declared in an anonymous union are an extension") under clang (#1204). This names the struct and defines it out of the definition of `instance` to get around to warning (and makes the code slightly simpler).
Fixed by #1248 |
The anonymous struct nested in a union triggers a -Wnested-anon-type warning ("anonymous types declared in an anonymous union are an extension") under clang (pybind#1204). This names the struct and defines it out of the definition of `instance` to get around to warning (and makes the code slightly simpler).
The anonymous struct nested in a union triggers a -Wnested-anon-type warning ("anonymous types declared in an anonymous union are an extension") under clang (#1204). This names the struct and defines it out of the definition of `instance` to get around to warning (and makes the code slightly simpler).
Issue description
Compiling a file that includes pybind11/detail/common.h (it is private but obviously included by other public headers) with clang -Wpedantic triggers the warning
Reproducible example code
Add
#include <pybind11/detail/common.h>
to python_example and compile withThe text was updated successfully, but these errors were encountered: