Skip to content

Commit

Permalink
remove more C++11 work-arounds (#642)
Browse files Browse the repository at this point in the history
* 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 76ebc4f.

* 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
  • Loading branch information
J. Daniel Smith authored Jan 25, 2023
1 parent b04ccca commit aabc581
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 48 deletions.
10 changes: 0 additions & 10 deletions modules/c++/coda_oss/include/coda_oss/CPlusPlus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 10 additions & 20 deletions modules/c++/coda_oss/include/coda_oss/optional_.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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 <typename... Args> // https://en.cppreference.com/w/cpp/utility/Optional/emplace
T& emplace(Args&&... args)
{
value_ = value_type(std::forward<Args>(args)...);
has_value_ = true;
return value_;
}

template <
typename U =
T> // https://en.cppreference.com/w/cpp/utility/optional/operator%3D
template <typename U = T> // https://en.cppreference.com/w/cpp/utility/optional/operator%3D
optional& operator=(U&& value) noexcept
{
value_ = std::forward<U>(value);
Expand Down Expand Up @@ -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*() &
{
Expand Down
14 changes: 0 additions & 14 deletions modules/c++/coda_oss/include/coda_oss/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
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_
4 changes: 2 additions & 2 deletions modules/c++/str/include/str/EncodedStringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -122,7 +122,7 @@ class CODA_OSS_API EncodedStringView final
{
return mIsUtf8 ? nullptr : cast<str::W1252string::const_pointer>(c_str());
}
size_t size() const
size_t size() const noexcept
{
return mString.size();
}
Expand Down
5 changes: 3 additions & 2 deletions modules/c++/xml.lite/include/xml/lite/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "except/Exception.h"
#include "xml/lite/QName.h"
#include "str/Convert.h"
#include "gsl/gsl.h"

/*!
* \file Attributes.h
Expand Down Expand Up @@ -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<size_t>(getIndex(name));
return mAttributes[idx].getValue();
}

Expand All @@ -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<size_t>(getIndex(s));
return mAttributes[idx].getValue();
}

Expand Down

0 comments on commit aabc581

Please sign in to comment.