Skip to content

Commit

Permalink
Move warning suppression macros to H5warnings.h (#4972)
Browse files Browse the repository at this point in the history
  • Loading branch information
derobins authored Oct 18, 2024
1 parent 610648e commit e12f513
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 89 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ set (H5_PUBLIC_HEADERS
set (H5_PRIVATE_HEADERS
${HDF5_SRC_DIR}/H5private.h
${HDF5_SRC_DIR}/H5timer.h
${HDF5_SRC_DIR}/H5warnings.h

${HDF5_SRC_DIR}/H5Apkg.h
${HDF5_SRC_DIR}/H5Aprivate.h
Expand Down
38 changes: 6 additions & 32 deletions src/H5FDmulti.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "hdf5.h"

#include "H5warnings.h"

#ifndef false
#define false 0
#endif
Expand All @@ -40,34 +42,6 @@
#define my_strdup strdup
#endif

/* Macros for enabling/disabling particular GCC / clang warnings
*
* These are duplicated in H5private.h. If you make changes here, be sure to
* update those as well.
*
* (see the following web-sites for more info:
* http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
* http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas
*/
#define H5_MULTI_DIAG_JOINSTR(x, y) x y
#define H5_MULTI_DIAG_DO_PRAGMA(x) _Pragma(#x)
#define H5_MULTI_DIAG_PRAGMA(x) H5_MULTI_DIAG_DO_PRAGMA(GCC diagnostic x)

#define H5_MULTI_DIAG_OFF(x) \
H5_MULTI_DIAG_PRAGMA(push) H5_MULTI_DIAG_PRAGMA(ignored H5_MULTI_DIAG_JOINSTR("-W", x))
#define H5_MULTI_DIAG_ON(x) H5_MULTI_DIAG_PRAGMA(pop)

/* Macros for enabling/disabling particular GCC / clang warnings.
* These macros should be used for warnings supported by both gcc and clang.
*/
#if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)
#define H5_MULTI_GCC_CLANG_DIAG_OFF(x) H5_MULTI_DIAG_OFF(x)
#define H5_MULTI_GCC_CLANG_DIAG_ON(x) H5_MULTI_DIAG_ON(x)
#else
#define H5_MULTI_GCC_CLANG_DIAG_OFF(x)
#define H5_MULTI_GCC_CLANG_DIAG_ON(x)
#endif

/* Loop through all mapped files */
#define UNIQUE_MEMBERS_CORE(MAP, ITER, SEEN, LOOPVAR) \
{ \
Expand Down Expand Up @@ -2032,7 +2006,7 @@ compute_next(H5FD_multi_t *file)
* tmp in the code below, but early (4.4.7, at least) gcc only
* allows diagnostic pragmas to be toggled outside of functions.
*/
H5_MULTI_GCC_CLANG_DIAG_OFF("format-nonliteral")
H5_GCC_CLANG_DIAG_OFF("format-nonliteral")
static int
open_members(H5FD_multi_t *file)
{
Expand Down Expand Up @@ -2070,7 +2044,7 @@ open_members(H5FD_multi_t *file)

return 0;
}
H5_MULTI_GCC_CLANG_DIAG_ON("format-nonliteral")
H5_GCC_CLANG_DIAG_ON("format-nonliteral")

/*-------------------------------------------------------------------------
* Function: H5FD_multi_delete
Expand All @@ -2081,7 +2055,7 @@ H5_MULTI_GCC_CLANG_DIAG_ON("format-nonliteral")
*
*-------------------------------------------------------------------------
*/
H5_MULTI_GCC_CLANG_DIAG_OFF("format-nonliteral")
H5_GCC_CLANG_DIAG_OFF("format-nonliteral")
static herr_t
H5FD_multi_delete(const char *filename, hid_t fapl_id)
{
Expand Down Expand Up @@ -2135,7 +2109,7 @@ H5FD_multi_delete(const char *filename, hid_t fapl_id)

return 0;
} /* end H5FD_multi_delete() */
H5_MULTI_GCC_CLANG_DIAG_ON("format-nonliteral")
H5_GCC_CLANG_DIAG_ON("format-nonliteral")

/*-------------------------------------------------------------------------
* Function: H5FD_multi_ctl
Expand Down
60 changes: 3 additions & 57 deletions src/H5private.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@

#endif /*H5_HAVE_WIN32_API*/

/* Macros for suppressing warnings */
#include "H5warnings.h"

#ifndef F_OK
#define F_OK 00
#define W_OK 02
Expand Down Expand Up @@ -519,63 +522,6 @@
#define LOCK_UN 0x08
#endif /* H5_HAVE_FLOCK */

/* Macros for enabling/disabling particular GCC / clang warnings
*
* These are duplicated in H5FDmulti.c (we don't want to put them in the
* public header and the multi VFD can't use private headers). If you make
* changes here, be sure to update those as well.
*
* (see the following web-sites for more info:
* http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
* http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas
*/
#define H5_DIAG_JOINSTR(x, y) x y
#define H5_DIAG_DO_PRAGMA(x) _Pragma(#x)
#define H5_DIAG_PRAGMA(x) H5_DIAG_DO_PRAGMA(GCC diagnostic x)

/* Allow suppression of compiler diagnostics unless H5_SHOW_ALL_WARNINGS is
* defined (enabled with '--enable-show-all-warnings' configure option).
*/
#ifndef H5_SHOW_ALL_WARNINGS
#define H5_DIAG_OFF(x) H5_DIAG_PRAGMA(push) H5_DIAG_PRAGMA(ignored H5_DIAG_JOINSTR("-W", x))
#define H5_DIAG_ON(x) H5_DIAG_PRAGMA(pop)
#else
#define H5_DIAG_OFF(x)
#define H5_DIAG_ON(x)
#endif

/* Macros for enabling/disabling particular GCC-only warnings.
* These pragmas are only implemented usefully in gcc 4.6+
*/
#if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406)
#define H5_GCC_DIAG_OFF(x) H5_DIAG_OFF(x)
#define H5_GCC_DIAG_ON(x) H5_DIAG_ON(x)
#else
#define H5_GCC_DIAG_OFF(x)
#define H5_GCC_DIAG_ON(x)
#endif

/* Macros for enabling/disabling particular clang-only warnings.
*/
#if defined(__clang__)
#define H5_CLANG_DIAG_OFF(x) H5_DIAG_OFF(x)
#define H5_CLANG_DIAG_ON(x) H5_DIAG_ON(x)
#else
#define H5_CLANG_DIAG_OFF(x)
#define H5_CLANG_DIAG_ON(x)
#endif

/* Macros for enabling/disabling particular GCC / clang warnings.
* These macros should be used for warnings supported by both gcc and clang.
*/
#if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)
#define H5_GCC_CLANG_DIAG_OFF(x) H5_DIAG_OFF(x)
#define H5_GCC_CLANG_DIAG_ON(x) H5_DIAG_ON(x)
#else
#define H5_GCC_CLANG_DIAG_OFF(x)
#define H5_GCC_CLANG_DIAG_ON(x)
#endif

/* If necessary, create a typedef for library usage of the
* _Float16 type to avoid issues when compiling the library
* with the -pedantic flag or similar where we get warnings
Expand Down
77 changes: 77 additions & 0 deletions src/H5warnings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
* Macros for suppressing warnings
*/

#ifndef H5warnings_H
#define H5warnings_H

/* Macros for enabling/disabling particular GCC / clang warnings
*
* These are duplicated in H5FDmulti.c (we don't want to put them in the
* public header and the multi VFD can't use private headers). If you make
* changes here, be sure to update those as well.
*
* (see the following web-sites for more info:
* http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
* http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas
*/
#define H5_DIAG_JOINSTR(x, y) x y
#define H5_DIAG_DO_PRAGMA(x) _Pragma(#x)
#define H5_DIAG_PRAGMA(x) H5_DIAG_DO_PRAGMA(GCC diagnostic x)

/* Allow suppression of compiler diagnostics unless H5_SHOW_ALL_WARNINGS is
* defined (enabled with '--enable-show-all-warnings' configure option).
*/
#ifndef H5_SHOW_ALL_WARNINGS
#define H5_DIAG_OFF(x) H5_DIAG_PRAGMA(push) H5_DIAG_PRAGMA(ignored H5_DIAG_JOINSTR("-W", x))
#define H5_DIAG_ON(x) H5_DIAG_PRAGMA(pop)
#else
#define H5_DIAG_OFF(x)
#define H5_DIAG_ON(x)
#endif

/* Macros for enabling/disabling particular GCC-only warnings.
* These pragmas are only implemented usefully in gcc 4.6+
*/
#if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406)
#define H5_GCC_DIAG_OFF(x) H5_DIAG_OFF(x)
#define H5_GCC_DIAG_ON(x) H5_DIAG_ON(x)
#else
#define H5_GCC_DIAG_OFF(x)
#define H5_GCC_DIAG_ON(x)
#endif

/* Macros for enabling/disabling particular clang-only warnings.
*/
#if defined(__clang__)
#define H5_CLANG_DIAG_OFF(x) H5_DIAG_OFF(x)
#define H5_CLANG_DIAG_ON(x) H5_DIAG_ON(x)
#else
#define H5_CLANG_DIAG_OFF(x)
#define H5_CLANG_DIAG_ON(x)
#endif

/* Macros for enabling/disabling particular GCC / clang warnings.
* These macros should be used for warnings supported by both gcc and clang.
*/
#if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)
#define H5_GCC_CLANG_DIAG_OFF(x) H5_DIAG_OFF(x)
#define H5_GCC_CLANG_DIAG_ON(x) H5_DIAG_ON(x)
#else
#define H5_GCC_CLANG_DIAG_OFF(x)
#define H5_GCC_CLANG_DIAG_ON(x)
#endif

#endif /* H5warnings_H */

0 comments on commit e12f513

Please sign in to comment.