Skip to content

Commit

Permalink
Merge pull request #149 from biojppm/fix/wundef
Browse files Browse the repository at this point in the history
fix warnings with -Wundef
  • Loading branch information
biojppm authored Feb 14, 2025
2 parents f455f20 + c8cc412 commit fd42d5f
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 76 deletions.
30 changes: 10 additions & 20 deletions .github/docker/ubuntu24.04/c4core-install
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ case $what in
$script arm-linux-gnueabihf
$script qemu
;;
g++-4.8|gcc-4.8)
g++-4.8|gcc-4.8|gcc4.8)
apt-get update
apt-get install -y \
software-properties-common
Expand All @@ -59,7 +59,7 @@ case $what in
gcc-4.8 --version
g++-4.8 --version
;;
g++-4.9|gcc-4.9)
g++-4.9|gcc-4.9|gcc4.9)
apt-get update
apt-get install -y \
wget \
Expand All @@ -74,7 +74,7 @@ case $what in
gcc-4.9 --version
g++-4.9 --version
;;
g++-5|gcc-5)
g++-5|gcc-5|gcc5)
apt-get update
apt-get install -y \
wget \
Expand Down Expand Up @@ -340,65 +340,55 @@ case $what in
arm-none-eabi-gcc --version
arm-none-eabi-g++ --version
;;
armv7)
arm-linux-gnueabihf)
armv7|arm-linux-gnueabihf)
apt-get update
apt-get install -y \
gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf
arm-linux-gnueabihf-gcc --version
arm-linux-gnueabihf-g++ --version
;;
armv6)
arm-linux-gnueabi)
armv6|arm-linux-gnueabi)
apt-get update
apt-get install -y \
gcc-arm-linux-gnueabi \
g++-arm-linux-gnueabi
arm-linux-gnueabi-gcc --version
arm-linux-gnueabi-g++ --version
;;
aarch64)
aarch64-linux-gnu)
aarch64|aarch64-linux-gnu)
apt-get update
apt-get install -y \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu
aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-g++ --version
;;
s390)
s390x)
s390x-linux-gnu)
s390|s390x|s390x-linux-gnu)
apt-get update
apt-get install -y \
gcc-s390x-linux-gnu \
g++-s390x-linux-gnu
s390x-linux-gnu-gcc --version
s390x-linux-gnu-g++ --version
;;
ppc64le)
powerpc64le)
ppc64le-linux-gnu)
ppc64le|powerpc64le|ppc64le-linux-gnu)
apt-get update
apt-get install -y \
gcc-powerpc64le-linux-gnu \
g++-powerpc64le-linux-gnu
powerpc64le-linux-gnu-gcc --version
powerpc64le-linux-gnu-g++ --version
;;
ppc64)
powerpc64)
ppc64-linux-gnu)
ppc64|powerpc64|ppc64-linux-gnu)
apt-get update
apt-get install -y \
gcc-powerpc64-linux-gnu \
g++-powerpc64-linux-gnu
powerpc64-linux-gnu-gcc --version
powerpc64-linux-gnu-g++ --version
;;
riscv64)
riscv64-linux-gnu)
riscv64|riscv64-linux-gnu)
apt-get update
apt-get install -y \
gcc-riscv64-linux-gnu \
Expand Down
4 changes: 2 additions & 2 deletions bm/bm_charconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ xtoa_std_to_chars(bm::State& st)
}
#endif

#if C4CORE_BM_HAVE_TOCHARS
#if defined(C4CORE_BM_HAVE_TOCHARS)
C4FOR(T, isreal)
xtoa_std_to_chars(bm::State& st)
{
Expand Down Expand Up @@ -1177,7 +1177,7 @@ atox_std_from_chars(bm::State& st)
}
#endif

#if C4CORE_BM_HAVE_TOCHARS
#if defined(C4CORE_BM_HAVE_TOCHARS)
C4FOR(T, isreal)
atox_std_from_chars(bm::State& st)
{
Expand Down
32 changes: 16 additions & 16 deletions bm/float/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@
#endif


#if C4FLOAT_STD_ATOF
#if defined(C4FLOAT_STD_ATOF)
#include <cstdlib>
double doit(const char *s) { return atof(s); }
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_SSCANF_F
#elif defined(C4FLOAT_SSCANF_F)
float doit(const char *s) { float val; sscanf(s, "%f", &val); return val; }
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_SSCANF_D
#elif defined(C4FLOAT_SSCANF_D)
double doit(const char *s) { double val; sscanf(s, "%lf", &val); return val; }
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_IOSTREAM_F
#elif defined(C4FLOAT_IOSTREAM_F)
#include <sstream>
float doit(const char *s) { std::stringstream ss; ss << s; float val; ss >> val; return val; }
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_IOSTREAM_D
#elif defined(C4FLOAT_IOSTREAM_D)
#include <sstream>
double doit(const char *s) { std::stringstream ss; ss << s; double val; ss >> val; return val; }
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_IOSTREAM_D
#elif defined(C4FLOAT_IOSTREAM_D)
#include <sstream>
double doit(const char *s) { std::stringstream ss; ss << s; double val; ss >> val; return val; }
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_FP_F_LIMITED
#elif defined(C4FLOAT_FP_F_LIMITED)
#include <jkj/fp/from_chars/from_chars.h>
float doit(const char *s)
{
Expand All @@ -54,7 +54,7 @@ float doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_FP_D_LIMITED
#elif defined(C4FLOAT_FP_D_LIMITED)
#include <jkj/fp/from_chars/from_chars.h>
double doit(const char *s)
{
Expand All @@ -63,7 +63,7 @@ double doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_FP_F_UNLIMITED
#elif defined(C4FLOAT_FP_F_UNLIMITED)
#include <jkj/fp/from_chars/from_chars.h>
float doit(const char *s)
{
Expand All @@ -72,7 +72,7 @@ float doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_FP_D_UNLIMITED
#elif defined(C4FLOAT_FP_D_UNLIMITED)
#include <jkj/fp/from_chars/from_chars.h>
double doit(const char *s)
{
Expand All @@ -81,7 +81,7 @@ double doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_FASTFLOAT_F
#elif defined(C4FLOAT_FASTFLOAT_F)
#include <c4/ext/fast_float.hpp>
#include <cstring>
float doit(const char *s)
Expand All @@ -92,7 +92,7 @@ float doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_FASTFLOAT_D
#elif defined(C4FLOAT_FASTFLOAT_D)
#include <c4/ext/fast_float.hpp>
#include <cstring>
double doit(const char *s)
Expand All @@ -103,7 +103,7 @@ double doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_STD_FROM_CHARS_F
#elif defined(C4FLOAT_STD_FROM_CHARS_F)
#include <charconv>
#include <cstring>
float doit(const char *s)
Expand All @@ -114,7 +114,7 @@ float doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_STD_FROM_CHARS_D
#elif defined(C4FLOAT_STD_FROM_CHARS_D)
#include <charconv>
#include <cstring>
double doit(const char *s)
Expand All @@ -125,7 +125,7 @@ double doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_RYU_F
#elif defined(C4FLOAT_RYU_F)
#include <ryu/ryu_parse.h>
float doit(const char *s)
{
Expand All @@ -135,7 +135,7 @@ float doit(const char *s)
}
#define C4_TO_REAL(s) doit(s)

#elif C4FLOAT_RYU_D
#elif defined(C4FLOAT_RYU_D)
#include <ryu/ryu_parse.h>
double doit(const char *s)
{
Expand Down
2 changes: 1 addition & 1 deletion cmake
Submodule cmake updated 1 files
+1 −0 c4Project.cmake
46 changes: 18 additions & 28 deletions src/c4/charconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@
# define C4CORE_HAVE_FAST_FLOAT 1
# endif
# if C4CORE_HAVE_FAST_FLOAT
C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wsign-conversion")
C4_SUPPRESS_WARNING_GCC("-Warray-bounds")
# if defined(__GNUC__) && __GNUC__ >= 5
C4_SUPPRESS_WARNING_GCC("-Wshift-count-overflow")
# endif
# include "c4/ext/fast_float.hpp"
C4_SUPPRESS_WARNING_GCC_POP
# endif
#elif (C4_CPP >= 17)
# define C4CORE_HAVE_FAST_FLOAT 0
Expand Down Expand Up @@ -101,15 +95,13 @@
#endif


#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__clang__)
# pragma warning(push)
# pragma warning(disable: 4996) // snprintf/scanf: this function or variable may be unsafe
# if C4_MSVC_VERSION != C4_MSVC_VERSION_2017
# pragma warning(disable: 4800) //'int': forcing value to bool 'true' or 'false' (performance warning)
# endif
#endif

#if defined(__clang__)
#elif defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
# pragma clang diagnostic ignored "-Wformat-nonliteral"
Expand Down Expand Up @@ -241,7 +233,7 @@ struct is_fixed_length
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
# pragma warning(push)
#elif defined(__clang__)
# pragma clang diagnostic push
Expand Down Expand Up @@ -1607,7 +1599,7 @@ C4_ALWAYS_INLINE size_t atou_first(csubstr str, T *v)

/** @} */

#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
# pragma warning(pop)
#elif defined(__clang__)
# pragma clang diagnostic pop
Expand Down Expand Up @@ -2236,8 +2228,8 @@ inline size_t atod_first(csubstr str, double * C4_RESTRICT v) noexcept
/** @cond dev */
// on some platforms, (unsigned) int and (unsigned) long
// are not any of the fixed length types above
#define _C4_IF_NOT_FIXED_LENGTH_I(T, ty) C4_ALWAYS_INLINE typename std::enable_if<std:: is_signed<T>::value && !is_fixed_length<T>::value_i, ty>
#define _C4_IF_NOT_FIXED_LENGTH_U(T, ty) C4_ALWAYS_INLINE typename std::enable_if<std::is_unsigned<T>::value && !is_fixed_length<T>::value_u, ty>
#define _C4_IF_NOT_FIXED_LENGTH_I(T, ty) typename std::enable_if<std:: is_signed<T>::value && !is_fixed_length<T>::value_i, ty>
#define _C4_IF_NOT_FIXED_LENGTH_U(T, ty) typename std::enable_if<std::is_unsigned<T>::value && !is_fixed_length<T>::value_u, ty>
/** @endcond*/


Expand Down Expand Up @@ -2279,8 +2271,8 @@ C4_ALWAYS_INLINE size_t xtoa(substr s, int64_t v, int64_t radix, size_t num_di
C4_ALWAYS_INLINE size_t xtoa(substr s, float v, int precision, RealFormat_e formatting=FTOA_FLEX) noexcept { return ftoa(s, v, precision, formatting); }
C4_ALWAYS_INLINE size_t xtoa(substr s, double v, int precision, RealFormat_e formatting=FTOA_FLEX) noexcept { return dtoa(s, v, precision, formatting); }

template <class T> _C4_IF_NOT_FIXED_LENGTH_I(T, size_t)::type xtoa(substr buf, T v) noexcept { return itoa(buf, v); }
template <class T> _C4_IF_NOT_FIXED_LENGTH_U(T, size_t)::type xtoa(substr buf, T v) noexcept { return write_dec(buf, v); }
template <class T> C4_ALWAYS_INLINE auto xtoa(substr buf, T v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_I(T, size_t)::type { return itoa(buf, v); }
template <class T> C4_ALWAYS_INLINE auto xtoa(substr buf, T v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_U(T, size_t)::type { return write_dec(buf, v); }
template <class T>
C4_ALWAYS_INLINE size_t xtoa(substr s, T *v) noexcept { return itoa(s, (intptr_t)v, (intptr_t)16); }

Expand All @@ -2304,8 +2296,8 @@ C4_ALWAYS_INLINE bool atox(csubstr s, int64_t *C4_RESTRICT v) noexcept { return
C4_ALWAYS_INLINE bool atox(csubstr s, float *C4_RESTRICT v) noexcept { return atof(s, v); }
C4_ALWAYS_INLINE bool atox(csubstr s, double *C4_RESTRICT v) noexcept { return atod(s, v); }

template <class T> _C4_IF_NOT_FIXED_LENGTH_I(T, bool )::type atox(csubstr buf, T *C4_RESTRICT v) noexcept { return atoi(buf, v); }
template <class T> _C4_IF_NOT_FIXED_LENGTH_U(T, bool )::type atox(csubstr buf, T *C4_RESTRICT v) noexcept { return atou(buf, v); }
template <class T> C4_ALWAYS_INLINE auto atox(csubstr buf, T *C4_RESTRICT v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_I(T, bool)::type { return atoi(buf, v); }
template <class T> C4_ALWAYS_INLINE auto atox(csubstr buf, T *C4_RESTRICT v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_U(T, bool)::type { return atou(buf, v); }
template <class T>
C4_ALWAYS_INLINE bool atox(csubstr s, T **v) noexcept { intptr_t tmp; bool ret = atox(s, &tmp); if(ret) { *v = (T*)tmp; } return ret; }

Expand Down Expand Up @@ -2344,8 +2336,8 @@ C4_ALWAYS_INLINE size_t to_chars(substr buf, int64_t v) noexcept { return itoa(
C4_ALWAYS_INLINE size_t to_chars(substr buf, float v) noexcept { return ftoa(buf, v); }
C4_ALWAYS_INLINE size_t to_chars(substr buf, double v) noexcept { return dtoa(buf, v); }

template <class T> _C4_IF_NOT_FIXED_LENGTH_I(T, size_t)::type to_chars(substr buf, T v) noexcept { return itoa(buf, v); }
template <class T> _C4_IF_NOT_FIXED_LENGTH_U(T, size_t)::type to_chars(substr buf, T v) noexcept { return write_dec(buf, v); }
template <class T> C4_ALWAYS_INLINE auto to_chars(substr buf, T v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_I(T, size_t)::type { return itoa(buf, v); }
template <class T> C4_ALWAYS_INLINE auto to_chars(substr buf, T v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_U(T, size_t)::type { return write_dec(buf, v); }
template <class T>
C4_ALWAYS_INLINE size_t to_chars(substr s, T *v) noexcept { return itoa(s, (intptr_t)v, (intptr_t)16); }

Expand Down Expand Up @@ -2379,8 +2371,8 @@ C4_ALWAYS_INLINE bool from_chars(csubstr buf, int64_t *C4_RESTRICT v) noexcept
C4_ALWAYS_INLINE bool from_chars(csubstr buf, float *C4_RESTRICT v) noexcept { return atof(buf, v); }
C4_ALWAYS_INLINE bool from_chars(csubstr buf, double *C4_RESTRICT v) noexcept { return atod(buf, v); }

template <class T> _C4_IF_NOT_FIXED_LENGTH_I(T, bool )::type from_chars(csubstr buf, T *C4_RESTRICT v) noexcept { return atoi(buf, v); }
template <class T> _C4_IF_NOT_FIXED_LENGTH_U(T, bool )::type from_chars(csubstr buf, T *C4_RESTRICT v) noexcept { return atou(buf, v); }
template <class T> C4_ALWAYS_INLINE auto from_chars(csubstr buf, T *C4_RESTRICT v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_I(T, bool)::type { return atoi(buf, v); }
template <class T> C4_ALWAYS_INLINE auto from_chars(csubstr buf, T *C4_RESTRICT v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_U(T, bool)::type { return atou(buf, v); }
template <class T>
C4_ALWAYS_INLINE bool from_chars(csubstr buf, T **v) noexcept { intptr_t tmp; bool ret = from_chars(buf, &tmp); if(ret) { *v = (T*)tmp; } return ret; }

Expand All @@ -2407,8 +2399,8 @@ C4_ALWAYS_INLINE size_t from_chars_first(csubstr buf, int64_t *C4_RESTRICT v) n
C4_ALWAYS_INLINE size_t from_chars_first(csubstr buf, float *C4_RESTRICT v) noexcept { return atof_first(buf, v); }
C4_ALWAYS_INLINE size_t from_chars_first(csubstr buf, double *C4_RESTRICT v) noexcept { return atod_first(buf, v); }

template <class T> _C4_IF_NOT_FIXED_LENGTH_I(T, size_t)::type from_chars_first(csubstr buf, T *C4_RESTRICT v) noexcept { return atoi_first(buf, v); }
template <class T> _C4_IF_NOT_FIXED_LENGTH_U(T, size_t)::type from_chars_first(csubstr buf, T *C4_RESTRICT v) noexcept { return atou_first(buf, v); }
template <class T> C4_ALWAYS_INLINE auto from_chars_first(csubstr buf, T *C4_RESTRICT v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_I(T, size_t)::type { return atoi_first(buf, v); }
template <class T> C4_ALWAYS_INLINE auto from_chars_first(csubstr buf, T *C4_RESTRICT v) noexcept -> _C4_IF_NOT_FIXED_LENGTH_U(T, size_t)::type { return atou_first(buf, v); }
template <class T>
C4_ALWAYS_INLINE size_t from_chars_first(csubstr buf, T **v) noexcept { intptr_t tmp; bool ret = from_chars_first(buf, &tmp); if(ret) { *v = (T*)tmp; } return ret; }

Expand Down Expand Up @@ -2667,11 +2659,9 @@ inline size_t to_chars(substr buf, const char * C4_RESTRICT v) noexcept

// NOLINTEND(hicpp-signed-bitwise)

#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
# pragma warning(pop)
#endif

#if defined(__clang__)
#elif defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__GNUC__)
# pragma GCC diagnostic pop
Expand Down
4 changes: 4 additions & 0 deletions src/c4/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct fail_type__ {};
#else
# ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"
# if !defined(__APPLE_CC__)
# if __clang_major__ >= 10
# pragma clang diagnostic ignored "-Wgnu-inline-cpp-without-extern" // debugbreak/debugbreak.h:50:16: error: 'gnu_inline' attribute without 'extern' in C++ treated as externally available, this changed in Clang 10 [-Werror,-Wgnu-inline-cpp-without-extern]
Expand All @@ -73,12 +74,15 @@ struct fail_type__ {};
# endif
# endif
# elif defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wundef"
# endif
# include <c4/ext/debugbreak/debugbreak.h>
# define C4_DEBUG_BREAK() if(c4::is_debugger_attached()) { ::debug_break(); }
# ifdef __clang__
# pragma clang diagnostic pop
# elif defined(__GNUC__)
# pragma GCC diagnostic pop
# endif
#endif

Expand Down
Loading

0 comments on commit fd42d5f

Please sign in to comment.