Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from 22a7eab30..5e0f5d614
Browse files Browse the repository at this point in the history
5e0f5d614 merge main
81285872f build cleanly with all G++ warnings enabled (#649)

git-subtree-dir: externals/coda-oss
git-subtree-split: 5e0f5d614ab88aa74e4c8c84fc90ef2e76335fea
  • Loading branch information
Dan Smith authored and Dan Smith committed Feb 8, 2023
1 parent 4aa2813 commit 8fab46b
Show file tree
Hide file tree
Showing 28 changed files with 140 additions and 58 deletions.
10 changes: 2 additions & 8 deletions modules/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ set(TARGET_LANGUAGE c++)

# turn on warnings as errors
if (MSVC)
add_compile_options(/WX /W4)
add_compile_options(/WX /W4) # /Wall
elseif (UNIX)
# still building with older GCC :-(
#add_compile_options(-Werror)
add_compile_options(-Wall)
#add_compile_options(-Wpedantic -Wextra)
add_compile_options(-Wno-deprecated-copy)
add_compile_options(-Wno-expansion-to-defined -Wno-type-limits)
add_compile_options(-Wno-unused-parameter)
add_compile_options(-Werror -Wall -Wpedantic -Wextra)
endif()

# add an interface library for unittests
Expand Down
43 changes: 43 additions & 0 deletions modules/c++/config/include/config/disable_compiler_warnings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* =========================================================================
* This file is part of config-c++
* =========================================================================
*
* (C) Copyright 2023, Maxar Technologies, Inc.
*
* config-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CODA_OSS_config_disable_compiler_warnings_h_INCLUDED_
#define CODA_OSS_config_disable_compiler_warnings_h_INCLUDED_
#pragma once

#include "compiler_extensions.h"

#if _MSC_VER
// We don't care about any padding added to structs
#pragma warning(disable: 4820) // '...': '...' bytes padding added after data member '...'

// Assume any unreferenced functions will be used in other code
#pragma warning(disable: 4514) // '...': unreferenced inline function has been removed

// ???
#pragma warning(disable: 4668) // '...' is not defined as a preprocessor macro, replacing with '...' for '...'

// ???
#pragma warning(disable: 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified

#endif // _MSC_VER

#endif // CODA_OSS_config_disable_compiler_warnings_h_INCLUDED_
1 change: 1 addition & 0 deletions modules/c++/except/include/except/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ostream>

#include "config/Exports.h"
#include "config/disable_compiler_warnings.h"

/*!
* \file
Expand Down
4 changes: 2 additions & 2 deletions modules/c++/except/include/except/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
_Name##Error_(const except::Throwable& t, const except::Context& c) : _Base(t, c){} \
_Name##Error_(const except::ThrowableEx& t, const except::Context& c) : _Base(t, c){} \
std::string getType() const noexcept override { return #_Name; } \
};
}
#define DECLARE_EXTENDED_ERROR(_Name, _Base) DECLARE_EXTENDED_ERROR_(_Name, Error, _Base)
#define DECLARE_EXTENDED_ERROREX(_Name, _Base) DECLARE_EXTENDED_ERROR_(_Name, ErrorEx, _Base)

// Need to keep this around for existing code
#define DECLARE_ERROR(_Name) \
DECLARE_EXTENDED_ERROR(_Name, except::Error); \
DECLARE_EXTENDED_ERROR(_Name, except::Error); \
DECLARE_EXTENDED_ERROREX(_Name, except::ErrorEx)

namespace except
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/except/include/except/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
_Name##Exception_(const except::ThrowableEx& t, const except::Context& c) : _Base(t, c){} \
CODA_OSS_except_Exception_suppress_26447_BEGIN_ \
std::string getType() const noexcept override { return #_Name #Exception_; } \
CODA_OSS_except_Exception_suppress_26447_END_ };
CODA_OSS_except_Exception_suppress_26447_END_ }
#define DECLARE_EXTENDED_EXCEPTION(_Name, _Base) DECLARE_EXTENDED_EXCEPTION_(_Name, Exception, _Base)
#define DECLARE_EXTENDED_EXCEPTIONEX(_Name, _Base) DECLARE_EXTENDED_EXCEPTION_(_Name, ExceptionEx, _Base)

Expand Down
1 change: 1 addition & 0 deletions modules/c++/except/include/except/Throwable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "config/Exports.h"
#include "config/compiler_extensions.h"
#include "config/disable_compiler_warnings.h"
#include "except/Trace.h"

/* Determine whether except::Throwable derives from std::exception.
Expand Down
2 changes: 2 additions & 0 deletions modules/c++/except/source/Backtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <cstdlib>
#include <sstream>

#include "config/disable_compiler_warnings.h"

#if !CODA_OSS_except_Backtrace

static std::string getBacktrace_(bool& supported, std::vector<std::string>&)
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/hdf5.lite/include/hdf5/lite/SpanRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ struct SpanRC final
}

private:
types::RowCol<size_t> rc_;
coda_oss::span<T> s_;
types::RowCol<size_t> rc_;
};

}
Expand Down
2 changes: 2 additions & 0 deletions modules/c++/hdf5.lite/unittests/test_hdf5write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ TEST_CASE(test_hdf5Create)

// https://www.mathworks.com/help/matlab/ref/h5write.html
hdf5::lite::createFile<float>(path, "/DS1", {10, 20});

TEST_ASSERT_TRUE(true); // need to use hidden "testName" parameter
}

TEST_CASE(test_hdf5Write)
Expand Down
8 changes: 5 additions & 3 deletions modules/c++/io/source/InputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ sys::SSize_T InputStream::streamTo(OutputStream& soi, sys::SSize_T bytesToPipe)
sys::SSize_T bytesRead = 0;
sys::SSize_T totalBytesTransferred = 0;

sys::SSize_T sizeOfVec = (bytesToPipe <= DEFAULT_CHUNK_SIZE) ? (bytesToPipe) : (DEFAULT_CHUNK_SIZE);
constexpr auto defaultChunkSize = static_cast<sys::SSize_T>(DEFAULT_CHUNK_SIZE);

sys::SSize_T sizeOfVec = (bytesToPipe <= defaultChunkSize) ? bytesToPipe : defaultChunkSize;
sys::byte vec[DEFAULT_CHUNK_SIZE];
memset(vec, 0, DEFAULT_CHUNK_SIZE);

Expand All @@ -79,8 +81,8 @@ sys::SSize_T InputStream::streamTo(OutputStream& soi, sys::SSize_T bytesToPipe)
soi.write(vec, bytesRead);
totalBytesTransferred += bytesRead;
memset(vec, 0, DEFAULT_CHUNK_SIZE);
sizeOfVec = (bytesToPipe - totalBytesTransferred <= DEFAULT_CHUNK_SIZE) ?
(bytesToPipe - totalBytesTransferred) : (DEFAULT_CHUNK_SIZE);
sizeOfVec = (bytesToPipe - totalBytesTransferred <= defaultChunkSize) ?
(bytesToPipe - totalBytesTransferred) : defaultChunkSize;
}
// Return the number of bytes we piped
return totalBytesTransferred;
Expand Down
16 changes: 6 additions & 10 deletions modules/c++/logging/include/logging/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace logging
*
* Enumeration used to represent LogLevels
*/
struct LogLevel
struct LogLevel final
{
//! The enumerations allowed
enum
Expand Down Expand Up @@ -124,7 +124,7 @@ struct LogLevel
}

//! destructor
~LogLevel(){}
~LogLevel() = default;

//! Returns string representation of the value
std::string toString() const
Expand All @@ -149,14 +149,10 @@ struct LogLevel
}

//! assignment operator
LogLevel& operator=(const LogLevel& o)
{
if (&o != this)
{
value = o.value;
}
return *this;
}
LogLevel& operator=(const LogLevel&) = default;
LogLevel(const LogLevel&) = default;
LogLevel& operator=(LogLevel&&) = default;
LogLevel(LogLevel&&) = default;

bool operator==(const LogLevel& o) const { return value == o.value; }
bool operator!=(const LogLevel& o) const { return value != o.value; }
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/logging/include/logging/LogRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LogRecord
std::string file, std::string function, int lineNum, std::string timestamp) :
mName(name), mMsg(msg), mLevel(level), mFile(file), mFunction(function),
mLineNum(lineNum), mTimestamp(timestamp){}
virtual ~LogRecord(){}
virtual ~LogRecord() = default;

LogLevel getLevel() const { return mLevel; }
std::string getLevelName() const;
Expand Down
15 changes: 11 additions & 4 deletions modules/c++/logging/source/Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* see <http://www.gnu.org/licenses/>.
*
*/
#include "logging/Setup.h"

#include <stdint.h>
#include <limits>

#include <str/Manip.h>

Expand All @@ -28,8 +32,6 @@
#include "logging/StandardFormatter.h"
#include "logging/XMLFormatter.h"

#include "logging/Setup.h"

std::unique_ptr<logging::Logger>
logging::setupLogger(const std::filesystem::path& program_,
const std::string& logLevel,
Expand Down Expand Up @@ -69,9 +71,14 @@ logging::setupLogger(const std::filesystem::path& program_,
logHandler.reset(new logging::StreamHandler());
else
{
// Existing code was checking whether a 'size_t' was <0; that of course can't
// ever happen because 'size_t' is an unsigned type. But, in the spirit of
// the existing code, assume that somebody thought such a check was meaningful
// ... using the value of a 32-bit integer (we now only build on 64-bit platforms).

// create a rotating logger
logCount = (logCount < 0) ? 0 : logCount;
logBytes = (logBytes < 0) ? 0 : logBytes;
logCount = logCount > std::numeric_limits<uint32_t>::max() ? 0 : logCount; // logCount = (logCount < 0) ? 0 : logCount;
logBytes = logBytes > std::numeric_limits<uint32_t>::max() ? 0 : logBytes; // logBytes = (logBytes < 0) ? 0 : logBytes;
if (logBytes > 0)
{
logHandler.reset(new logging::RotatingFileHandler(logFile,
Expand Down
3 changes: 2 additions & 1 deletion modules/c++/logging/unittests/test_exception_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ TEST_CASE(testExceptionWithBacktrace)
}
catch (const except::Throwable& t)
{
TEST_ASSERT_GREATER(t.getBacktrace().size(), static_cast<size_t>(0));
const auto backtraceSize = static_cast<int64_t>(t.getBacktrace().size());
TEST_ASSERT_GREATER(backtraceSize, 0);
s = t.toString(true /*includeBacktrace*/);
what = t.what();
}
Expand Down
4 changes: 3 additions & 1 deletion modules/c++/math.linear/unittests/test_lin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ TEST_CASE(testSTLVectorAssign)
TEST_CASE(testEmptyDim)
{
math::linear::Matrix2D<double> AScale(3, 0);
TEST_ASSERT_TRUE(true); // need to use hidden "testName" parameter
}

TEST_CASE(testPtrDecorator)
Expand All @@ -100,6 +101,7 @@ TEST_CASE(testPtrAdopt)
{
// valgrind to ensure that we don't have a leak
math::linear::Matrix2D<double> AScale(3, 3, new double[9], true);
TEST_ASSERT_TRUE(true); // need to use hidden "testName" parameter
}

TEST_CASE(testArithmetic)
Expand Down Expand Up @@ -216,4 +218,4 @@ TEST_MAIN(
std::cout << cross(v3, y) << std::endl;
*/
)
)
2 changes: 2 additions & 0 deletions modules/c++/mt/unittests/Runnable1DTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ TEST_CASE(DoRunnable1DTest)
const AddOp op;
std::cout << "Calling run1D\n";
mt::run1D(10, 16, op);
TEST_ASSERT_TRUE(true); // need to use hidden "testName" parameter
}

TEST_CASE(Runnable1DWithCopiesTest)
Expand All @@ -79,6 +80,7 @@ TEST_CASE(Runnable1DWithCopiesTest)
const LocalStorage op;
std::cout << "Calling run1D\n";
mt::run1DWithCopies(47, 16, op);
TEST_ASSERT_TRUE(true); // need to use hidden "testName" parameter
}

TEST_CASE(transform_async_test)
Expand Down
15 changes: 8 additions & 7 deletions modules/c++/net/include/net/URL.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class URLParams
typedef std::list<std::string> ParamValues;
typedef std::map<std::string, ParamValues> Params;

URLParams(const std::string paramString = "");
URLParams(std::string paramString = "");

bool contains(std::string key) const;
ParamValues& get(std::string key);
Expand All @@ -68,17 +68,18 @@ class URL
{
public:

URL(const std::string url = "");
URL(std::string url = "");

/*!
* Copy constructor.
* \param url A right-hand-side URL
*/
URL(const URL& url);
URL(const URL&);
URL& operator=(const URL&);
URL(URL&&) = default;
URL& operator=(URL&&) = default;

virtual ~URL()
{
}
virtual ~URL() = default;

void set(std::string url);

Expand Down Expand Up @@ -106,7 +107,7 @@ class URL
friend class URLBuilder;
std::string mProtocol;
std::string mHost;
int mPort;
int mPort = -1;
std::string mPath;
URLParams mParams;
std::string mFragment;
Expand Down
15 changes: 11 additions & 4 deletions modules/c++/net/source/URL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@
#include <import/str.h>
#include <import/sys.h>

net::URL::URL(const std::string url) :
mPort(-1)
net::URL::URL(std::string url)
{
if (!url.empty())
set(url);
}

net::URL::URL(const net::URL& url)
net::URL& net::URL::operator=(const URL& url)
{
if (this != &url)
{
mProtocol = url.getProtocol();
mHost = url.getHost();
setPort(url.getPort());
mPath = url.getPath();
mFragment = url.getFragment();
mParams = net::URLParams(url.getParams().toString());
}
return *this;
}
net::URL::URL(const URL& url)
{
*this = url;
}

void net::URL::set(std::string url)
Expand Down Expand Up @@ -122,7 +129,7 @@ bool net::URL::operator==(const net::URL& url) const
return toString() == url.toString();
}

net::URLParams::URLParams(const std::string paramString)
net::URLParams::URLParams(std::string paramString)
{
if (!paramString.empty())
{
Expand Down
6 changes: 5 additions & 1 deletion modules/c++/str/unittests/test_base_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ static void test_wide_(const std::string& testName, const char* pStr, std::u16st
const std::string std_str(static_cast<const char*>(wide_str)); // UTF-16 -> Windows-1252
TEST_ASSERT_EQ(encoded.native(), std_str);
TEST_ASSERT_EQ(std_str, pStr);
#else
pUtf16 = pUtf16; // avoid unused-parameter warning
#endif
}

Expand Down Expand Up @@ -436,6 +438,8 @@ TEST_CASE(test_Windows1252_WIN32)
constexpr auto w1252_unassigned = "\x81\x8d\x8f\x90\x9d";
constexpr auto u16_w1252_unassigned = u"\x81\x8d\x8f\x90\x9d";
test_Windows1252_(testName, w1252_unassigned, u16_w1252_unassigned);
#else
TEST_ASSERT_TRUE(true); // need to use hidden "testName" parameter
#endif
}

Expand Down Expand Up @@ -613,4 +617,4 @@ TEST_MAIN(
TEST_CHECK(test_Windows1252);
TEST_CHECK(test_EncodedStringView);
TEST_CHECK(test_EncodedString);
)
)
Loading

0 comments on commit 8fab46b

Please sign in to comment.