From aabc5818e651be550c0fcc53be6f94902c61905e Mon Sep 17 00:00:00 2001 From: "J. Daniel Smith" Date: Wed, 25 Jan 2023 15:57:35 -0500 Subject: [PATCH] remove more C++11 work-arounds (#642) * is_trivially_copyable for old Intel compiler * need to stick with coda_oss::make_unique for now because of old Intel compiler * Revert "need to stick with coda_oss::make_unique for now because of old Intel compiler" This reverts commit 76ebc4f0c101f2834389bbd02c443891984e213d. * trying to get std::make_unique with old Intel compiler * the old Intel compiler does have std::make_unique with C++14 * remove some compiler warnings/diagnostics ... which can cause build failures, depending on options. * don't need to turn off various GCC warnings anymore * compile modules/c++ with -Wall * build cleanly with -Wpedantic * enable more GCC warnings * use the standard (not legacy) C pre-processor doesn't allow "mdspan" to work * still building with older GCC :-( * remove #ifdefs for SGI and Sun * WIN32 -> _WIN32 * remove str::ui16string, in C++14, std::u16string should be fully supported. * save away result of mString.data() * merge develop/reduce-compiler-warnings * no longer using the old compilers --- .../c++/coda_oss/include/coda_oss/CPlusPlus.h | 10 ------- .../c++/coda_oss/include/coda_oss/optional_.h | 30 +++++++------------ .../coda_oss/include/coda_oss/type_traits.h | 14 --------- .../c++/str/include/str/EncodedStringView.h | 4 +-- .../xml.lite/include/xml/lite/Attributes.h | 5 ++-- 5 files changed, 15 insertions(+), 48 deletions(-) diff --git a/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h b/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h index 388cb8fd5..f28d64236 100644 --- a/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h +++ b/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h @@ -53,16 +53,6 @@ #endif // __INTEL_COMPILER #endif // CODA_OSS_cplusplus -#if CODA_OSS_cplusplus < 201402L - // oops ... try to fix - #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER_BUILD_DATE >= 20151021) - // __cplusplus is 201300, not 201402L - // Enough C++14, at least with our std/ work-arounds - #undef CODA_OSS_cplusplus - #define CODA_OSS_cplusplus 201402L - #endif -#endif // CODA_OSS_cplusplus - #if CODA_OSS_cplusplus < 202002L // oops ... try to fix #if defined(__GNUC__) && (__cplusplus >= 201709L) // note > C++ 17 of 201703L diff --git a/modules/c++/coda_oss/include/coda_oss/optional_.h b/modules/c++/coda_oss/include/coda_oss/optional_.h index 9ce2bf2ef..c321b5b70 100644 --- a/modules/c++/coda_oss/include/coda_oss/optional_.h +++ b/modules/c++/coda_oss/include/coda_oss/optional_.h @@ -63,27 +63,21 @@ class optional final using value_type = T; #if defined(_MSC_VER) && _PREFAST_ // Visual Studio /analyze - __pragma(warning(push)) __pragma(warning( - disable : 26495)) // Variable '...' is uninitialized. Always - // initialize a member variable(type.6). + __pragma(warning(push)) __pragma(warning(disable : 26495)) // Variable '...' is uninitialized. Always initialize a member variable(type.6). #endif - optional() noexcept + optional() noexcept { } #if defined(_MSC_VER) && _PREFAST_ __pragma(warning(pop)) #endif - optional(const value_type& v) : - value_(v), has_value_(true) + optional(const value_type& v) : value_(v), has_value_(true) { } #if defined(_MSC_VER) && _PREFAST_ // Visual Studio /analyze - __pragma(warning(push)) __pragma(warning( - disable : 26495)) // Variable '...' is uninitialized. Always - // initialize a member variable(type.6). + __pragma(warning(push)) __pragma(warning(disable : 26495)) // Variable '...' is uninitialized. Always initialize a member variable(type.6). #endif - optional(const optional& other) : - has_value_(other.has_value_) + optional(const optional& other) : has_value_(other.has_value_) { if (has_value()) { @@ -94,18 +88,15 @@ class optional final __pragma(warning(pop)) #endif - template < - typename... Args> // https://en.cppreference.com/w/cpp/utility/Optional/emplace - T& emplace(Args&&... args) + template // https://en.cppreference.com/w/cpp/utility/Optional/emplace + T& emplace(Args&&... args) { value_ = value_type(std::forward(args)...); has_value_ = true; return value_; } - template < - typename U = - T> // https://en.cppreference.com/w/cpp/utility/optional/operator%3D + template // https://en.cppreference.com/w/cpp/utility/optional/operator%3D optional& operator=(U&& value) noexcept { value_ = std::forward(value); @@ -163,11 +154,10 @@ class optional final // contains a value!" } - const T& operator*() const& + const T& operator*() const& noexcept { assert(has_value()); - return value_; // "This operator does not check whether the optional - // contains a value!" + return value_; // "This operator does not check whether the optional contains a value!" } T& operator*() & { diff --git a/modules/c++/coda_oss/include/coda_oss/type_traits.h b/modules/c++/coda_oss/include/coda_oss/type_traits.h index 5bd920a91..5c92c1d32 100644 --- a/modules/c++/coda_oss/include/coda_oss/type_traits.h +++ b/modules/c++/coda_oss/include/coda_oss/type_traits.h @@ -29,21 +29,7 @@ #include "coda_oss/namespace_.h" namespace coda_oss { -// workaround missing "is_trivially_copyable" in g++ < 5.0 -// https://stackoverflow.com/a/31798726/8877 -#if defined(__GNUC__) && (__GNUC__ < 5) -template -struct is_trivially_copyable final -{ - // This old Intel compiler has enough C++14 for our needs; see CPlusPlus.h - #if !(defined(__INTEL_COMPILER) && (__INTEL_COMPILER_BUILD_DATE <= 20151021)) - static_assert(CODA_OSS_cplusplus < 201402L, "C++14 must have is_trivially_copyable."); - #endif - static constexpr bool value = __has_trivial_copy(T); -}; -#else using std::is_trivially_copyable; -#endif } #endif // CODA_OSS_coda_oss_type_traits_h_INCLUDED_ diff --git a/modules/c++/str/include/str/EncodedStringView.h b/modules/c++/str/include/str/EncodedStringView.h index 38beb310b..1fd1e99ac 100644 --- a/modules/c++/str/include/str/EncodedStringView.h +++ b/modules/c++/str/include/str/EncodedStringView.h @@ -110,7 +110,7 @@ class CODA_OSS_API EncodedStringView final std::wstring wstring() const; // UTF-16 on Windows, UTF-32 on Linux // These are for "advanced" use, most "normal" code should use the routines above. - std::string::const_pointer c_str() const + std::string::const_pointer c_str() const noexcept { return mString.data(); } @@ -122,7 +122,7 @@ class CODA_OSS_API EncodedStringView final { return mIsUtf8 ? nullptr : cast(c_str()); } - size_t size() const + size_t size() const noexcept { return mString.size(); } diff --git a/modules/c++/xml.lite/include/xml/lite/Attributes.h b/modules/c++/xml.lite/include/xml/lite/Attributes.h index 17c40e410..8b354844b 100644 --- a/modules/c++/xml.lite/include/xml/lite/Attributes.h +++ b/modules/c++/xml.lite/include/xml/lite/Attributes.h @@ -31,6 +31,7 @@ #include "except/Exception.h" #include "xml/lite/QName.h" #include "str/Convert.h" +#include "gsl/gsl.h" /*! * \file Attributes.h @@ -330,7 +331,7 @@ struct Attributes final } std::string operator[](const xml::lite::QName& name) const { - const size_t idx = getIndex(name); + const auto idx = gsl::narrow(getIndex(name)); return mAttributes[idx].getValue(); } @@ -348,7 +349,7 @@ struct Attributes final } std::string operator[](const std::string& s) const { - const size_t idx = getIndex(s); + const auto idx = gsl::narrow(getIndex(s)); return mAttributes[idx].getValue(); }