Treat warnings as errors (#2490)

This commit is contained in:
Juha Reunanen 2022-04-13 01:53:52 +03:00 committed by GitHub
parent 49314c12d9
commit 0aa8b4cbfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 100 additions and 166 deletions

View File

@ -370,7 +370,7 @@ namespace dlib
and the fact that this has a different name (global swap has the same name as
the member functions called swap) makes them compile right.
So this is a workaround but not too ugly of one. But hopefully I get get
So this is a workaround but not too ugly of one. But hopefully I can get
rid of this in a few years. So this function is already deprecated.
This also means you should NOT use this function in your own code unless

View File

@ -117,14 +117,16 @@ namespace dlib
private:
row(T* data_, long cols) : data(data_), nc_(cols) {}
row(row&& r) = default;
row& operator=(row&& r) = default;
T* data;
long nc_;
T* data = nullptr;
long nc_ = 0;
// restricted functions
row(){}
row& operator=(row&);
row(const row&) = delete;
row& operator=(const row&) = delete;
};
// -----------------------------------

View File

@ -1518,7 +1518,6 @@ namespace dlib
bool message_sent = true;
std::vector<unsigned long>::iterator iter;
while (message_sent)
{
message_sent = false;

View File

@ -26,10 +26,10 @@ namespace dlib
// this is here for backwards compatibility with older versions of dlib.
typedef crc32 kernel_1a;
inline crc32 (
inline crc32 (
);
inline crc32 (
inline crc32 (
const std::string& item
);
@ -65,10 +65,6 @@ namespace dlib
crc32& item
);
inline crc32& operator=(
const crc32&
);
private:
unsigned long checksum;
@ -147,7 +143,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
crc32::
crc32 (
crc32 (
)
{
checksum = 0xFFFFFFFF;
@ -243,17 +239,6 @@ namespace dlib
exchange(checksum,item.checksum);
}
// ----------------------------------------------------------------------------------------
crc32& crc32::
operator=(
const crc32& item
)
{
checksum = item.checksum;
return *this;
}
// ----------------------------------------------------------------------------------------
}

View File

@ -31,7 +31,7 @@ namespace dlib
- #*this is properly initialized
!*/
crc32 (
crc32 (
const std::string& item
);
/*!

View File

@ -2479,7 +2479,7 @@ namespace dlib
float* t = &output(0,0);
// now fill in the Toeplitz output matrix for the n-th sample in data.
size_t cnt = 0;
long cnt = 0;
const long max_r = data.nr() + padding_y-(filter_nr-1);
const long max_c = data.nc() + padding_x-(filter_nc-1);
for (long r = -padding_y; r < max_r; r+=stride_y)

View File

@ -2259,7 +2259,7 @@ namespace dlib
void back_propagate_error(
const tensor& /*x*/,
const tensor& /*gradient_input*/,
zero_gradients zero_grads = zero_gradients::yes
zero_gradients /*zero_grads*/ = zero_gradients::yes
)
{
// nothing to do
@ -3746,7 +3746,7 @@ namespace dlib
typename visitor
>
static void visit(
net_type& net,
net_type&,
const add_tag_layer<tag_id,SUBNET>& next_net,
visitor&& v
)
@ -3760,7 +3760,7 @@ namespace dlib
typename visitor
>
static void visit(
net_type& net,
net_type&,
add_tag_layer<tag_id,SUBNET>& next_net,
visitor&& v
)

View File

@ -476,7 +476,6 @@ namespace dlib
typedef matrix<T,NR,NC,MM,L> input_type;
input() {}
input(const input&) {}
template <typename mm>
input(const input<array2d<T,mm>>&) {}
@ -728,25 +727,25 @@ namespace dlib
}
friend void serialize(const input& item, std::ostream& out)
friend void serialize(const input&, std::ostream& out)
{
serialize("input<array2d>", out);
}
friend void deserialize(input& item, std::istream& in)
friend void deserialize(input&, std::istream& in)
{
std::string version;
deserialize(version, in);
if (version != "input<array2d>")
throw serialization_error("Unexpected version found while deserializing dlib::input.");
}
friend std::ostream& operator<<(std::ostream& out, const input& item)
friend std::ostream& operator<<(std::ostream& out, const input&)
{
out << "input<array2d>";
return out;
}
friend void to_xml(const input& item, std::ostream& out)
friend void to_xml(const input&, std::ostream& out)
{
out << "<input/>";
}

View File

@ -552,7 +552,7 @@ namespace dlib
visitor_net_to_dot(std::ostream& out) : out(out) {}
template <typename input_layer_type>
void operator()(size_t i, input_layer_type& l)
void operator()(size_t i, input_layer_type&)
{
start_node(i, "input");
end_node();
@ -609,7 +609,7 @@ namespace dlib
}
template <template <typename> class TAG, typename U>
void operator()(size_t i, const add_skip_layer<TAG, U>&)
void operator()(size_t, const add_skip_layer<TAG, U>&)
{
const auto t = tag_id<TAG>::id;
from = tag_to_layer.at(t);
@ -887,7 +887,7 @@ namespace dlib
}
template <template <typename> class... TAGS, typename U, typename E>
void operator()(size_t i, const add_layer<concat_<TAGS...>, U, E>& l)
void operator()(size_t i, const add_layer<concat_<TAGS...>, U, E>&)
{
start_node(i, "concat");
end_node();
@ -930,7 +930,7 @@ namespace dlib
}
template <typename T, typename U, typename E>
void operator()(size_t i, const add_layer<T, U, E>& l)
void operator()(size_t i, const add_layer<T, U, E>&)
{
start_node(i, "unhandled layer");
update(i);

View File

@ -750,7 +750,7 @@ namespace dlib
// Circumvent what appears to be a bug in Visual Studio 2019's optimizer
// (see: https://forum.juce.com/t/warning-in-the-lastest-vs2019/38267)
#if defined (_MSVC_VER)
#if defined (_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4723 )
#endif
@ -774,7 +774,7 @@ namespace dlib
return centered_rect(rect, (long)std::round(rect.width()*scale), (long)std::round(rect.height()*scale));
}
}
#if defined (_MSVC_VER)
#if defined (_MSC_VER)
#pragma warning ( pop )
#endif

View File

@ -31,6 +31,9 @@ namespace dlib
typedef T1 key_type;
typedef T2 value_type;
map_pair() = default;
map_pair(const map_pair&) = default;
virtual ~map_pair(
)=0;

View File

@ -710,6 +710,12 @@ namespace dlib
}
// -----------------------------
// Apparently Visual Studio's optimizer complains about branches that would not be taken anyway.
#if defined (_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4756 )
#endif
template < typename P1, typename P2 >
typename enable_if_c<pixel_traits<P1>::grayscale && pixel_traits<P2>::grayscale>::type
assign(P1& dest, const P2& src)
@ -728,6 +734,10 @@ namespace dlib
dest = pixel_traits<P1>::max();
}
#if defined (_MSC_VER)
#pragma warning ( pop )
#endif
// -----------------------------
// -----------------------------
// -----------------------------

View File

@ -47,12 +47,12 @@ namespace dlib
- if (current_element_valid()) then
- element() == mp
!*/
class mpair : public map_pair<domain,range>
{
public:
const domain* d;
range* r;
const domain* d = nullptr;
range* r = nullptr;
const domain& key(
) const { return *d; }

View File

@ -154,7 +154,7 @@ namespace dlib
{
// max_cost_assignment() only works with integer matrices, so convert from
// double to integer.
const double scale = (std::numeric_limits<dlib::int64>::max()/1000)/max(abs(cost));
const double scale = static_cast<double>(std::numeric_limits<dlib::int64>::max())/1000/max(abs(cost));
matrix<dlib::int64> int_cost = matrix_cast<dlib::int64>(round(cost*scale));
assignment = max_cost_assignment(int_cost);
assignment.resize(lhs.size());

View File

@ -43,15 +43,6 @@ namespace dlib
decision_function (
) : b(0), kernel_function(K()) {}
decision_function (
const decision_function& d
) :
alpha(d.alpha),
b(d.b),
kernel_function(d.kernel_function),
basis_vectors(d.basis_vectors)
{}
decision_function (
const scalar_vector_type& alpha_,
const scalar_type& b_,
@ -137,14 +128,6 @@ namespace dlib
probabilistic_function (
) : alpha(0), beta(0), decision_funct(function_type()) {}
probabilistic_function (
const probabilistic_function& d
) :
alpha(d.alpha),
beta(d.beta),
decision_funct(d.decision_funct)
{}
probabilistic_function (
const scalar_type a_,
const scalar_type b_,
@ -232,14 +215,6 @@ namespace dlib
decision_funct(d.decision_funct)
{}
probabilistic_decision_function (
const probabilistic_decision_function& d
) :
alpha(d.alpha),
beta(d.beta),
decision_funct(d.decision_funct)
{}
probabilistic_decision_function (
const scalar_type a_,
const scalar_type b_,
@ -353,16 +328,6 @@ namespace dlib
);
}
distance_function (
const distance_function& d
) :
alpha(d.alpha),
b(d.b),
kernel_function(d.kernel_function),
basis_vectors(d.basis_vectors)
{
}
distance_function (
const scalar_vector_type& alpha_,
const scalar_type& b_,
@ -586,13 +551,6 @@ namespace dlib
normalized_function (
){}
normalized_function (
const normalized_function& f
) :
normalizer(f.normalizer),
function(f.function)
{}
const std::vector<result_type> get_labels(
) const { return function.get_labels(); }
@ -673,10 +631,6 @@ namespace dlib
projection_function (
) {}
projection_function (
const projection_function& f
) : weights(f.weights), kernel_function(f.kernel_function), basis_vectors(f.basis_vectors) {}
projection_function (
const scalar_matrix_type& weights_,
const K& kernel_function_,

View File

@ -64,14 +64,6 @@ namespace dlib
- #basis_vectors.nr() == 0
!*/
decision_function (
const decision_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
decision_function (
const scalar_vector_type& alpha_,
const scalar_type& b_,
@ -169,14 +161,6 @@ namespace dlib
- #decision_funct has its initial value
!*/
probabilistic_function (
const probabilistic_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
probabilistic_function (
const scalar_type a,
const scalar_type b,
@ -282,15 +266,7 @@ namespace dlib
!*/
probabilistic_decision_function (
const probabilistic_decision_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
probabilistic_decision_function (
const probabilistic_function<decision_function<K> >& d
const probabilistic_function<decision_function<K> >& f
);
/*!
ensures
@ -445,17 +421,6 @@ namespace dlib
- #get_basis_vectors() == f.basis_vectors
!*/
distance_function (
const distance_function& f
);
/*!
requires
- f is a valid distance_function. In particular, this means that
f.alpha.size() == f.basis_vectors.size()
ensures
- #*this is a copy of f
!*/
distance_function (
const scalar_vector_type& alpha,
const scalar_type& squared_norm,
@ -679,14 +644,6 @@ namespace dlib
- the members of this object have their default values
!*/
normalized_function (
const normalized_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
normalized_function (
const vector_normalizer<sample_type>& normalizer_,
const function_type& funct
@ -791,14 +748,6 @@ namespace dlib
- #basis_vectors.size() == 0
!*/
projection_function (
const projection_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
projection_function (
const scalar_matrix_type& weights_,
const K& kernel_function_,

View File

@ -655,7 +655,7 @@ namespace dlib
trainer_type trainer;
scalar_type min_learning_rate;
bool verbose;
bool verbose = true;
bool use_cache;
long cache_size;

View File

@ -247,7 +247,7 @@ namespace dlib
{
// max_cost_assignment() only works with integer matrices, so convert from
// double to integer.
const double scale = (std::numeric_limits<dlib::int64>::max()/1000)/max(abs(cost));
const double scale = static_cast<double>(std::numeric_limits<dlib::int64>::max())/1000/max(abs(cost));
matrix<dlib::int64> int_cost = matrix_cast<dlib::int64>(round(cost*scale));
assignment = max_cost_assignment(int_cost);
assignment.resize(samples[idx].first.size());

View File

@ -166,13 +166,22 @@ set (tests
# cmake that they are part of our target (which is the executable named dtest)
ADD_EXECUTABLE(${target_name} main.cpp tester.cpp ${tests})
# Turn on all warnings when using gcc.
if (CMAKE_COMPILER_IS_GNUCXX)
add_definitions("-W -Wall")
# Turn on all warnings, and treat them as errors.
add_definitions("-W -Wall -Wextra -Werror")
# I don't care about unused testing functions though. I like to keep them
# around. Don't warn about it.
add_definitions("-Wno-unused-function")
add_definitions("-Wno-strict-overflow")
add_definitions("-Wno-maybe-uninitialized")
elseif (MSVC)
# Treat warnings as errors.
add_definitions("/WX")
else() # basically Clang
# Treat warnings as errors, but do not turn on all warnings.
add_definitions("-W -Werror")
# This is for the comment in face_detection_ex.cpp that says "faces/*.jpg"
add_definitions("-Wno-comment")
endif()
@ -181,6 +190,12 @@ TARGET_LINK_LIBRARIES(${target_name} dlib::dlib )
if (NOT DLIB_NO_GUI_SUPPORT)
add_subdirectory(gui)
add_subdirectory(examples)
add_subdirectory(tools)
if (CMAKE_COMPILER_IS_GNUCXX)
# The tutorials set some variables that are not used.
add_definitions("-Wno-unused-but-set-variable")
endif()
add_subdirectory(examples)
endif()

View File

@ -75,7 +75,7 @@ namespace
bool detected_error = false;
try {
test.decompress(sin,sout);
} catch ( typename cs::decompression_error& e )
} catch ( typename cs::decompression_error& )
{
detected_error = true;
++count;

View File

@ -367,6 +367,19 @@ namespace
}
}
{
const rectangle input(1,1,6,4);
const rectangle output = set_rect_area(input,4*input.area());
DLIB_TEST(output.area() == 4*input.area());
DLIB_TEST(output.width() == 2*input.width());
DLIB_TEST(output.height() == 2*input.height());
const auto input_center = center(input);
const auto output_center = center(output);
DLIB_TEST(std::abs(input_center.x() - output_center.x()) <= 1);
DLIB_TEST(std::abs(input_center.y() - output_center.y()) <= 1);
}
}
// ----------------------------------------------------------------------------------------

View File

@ -411,7 +411,6 @@ public:
group1(*this),
group2(*this),
group3(*this),
keyboard_count(1),
keydown(*this),
keyup(*this),
l1(*this),
@ -759,7 +758,6 @@ private:
widget_group group1;
widget_group group2;
widget_group group3;
int keyboard_count;
label keydown;
label keyup;
label l1;

View File

@ -323,6 +323,9 @@ namespace
static_assert(dlib::invoke(multiply_ints, 2, 5) == 10, "this should be constexpr");
static_assert(dlib::invoke_r<long>(multiply_ints, 2, 5) == 10, "this should be constexpr");
constexpr constexpr_object constexpr_obj;
#if defined (_MSC_VER)
constexpr_obj; // avoid warning C4101: 'constexpr_obj': unreferenced local variable
#endif
static_assert(dlib::invoke(&constexpr_object::multiply_ints, constexpr_obj, 2, 5) == 10, "this should be constexpr");
static_assert(dlib::invoke_r<long>(&constexpr_object::multiply_ints, constexpr_obj, 2, 5) == 10, "this should be constexpr");
}

View File

@ -65,6 +65,14 @@ namespace dlib
- #first and #second contain copies of the items a and b.
!*/ {}
unordered_pair (
const unordered_pair& p
) = default;
/*!
ensures
- #*this is a copy of p
!*/
template <typename U>
unordered_pair (
const unordered_pair <U>& p

View File

@ -29,9 +29,6 @@
#include <dlib/dir_nav.h>
#include <iterator>
#include <thread>
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
#include <execution>
#endif // __cplusplus >= 201703L
using namespace std;
using namespace dlib;
@ -555,14 +552,13 @@ std::vector<std::vector<truth_instance>> load_all_truth_instances(const std::vec
{
std::vector<std::vector<truth_instance>> truth_instances(listing.size());
std::transform(
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
std::execution::par,
#endif // __cplusplus >= 201703L
listing.begin(),
listing.end(),
truth_instances.begin(),
load_truth_instances
parallel_for(
0,
listing.size(),
[&](size_t index)
{
truth_instances[index] = load_truth_instances(listing[index]);
}
);
return truth_instances;

View File

@ -179,7 +179,7 @@ public:
inline friend void serialize ( const very_simple_feature_extractor& item, std::ostream& out) { serialize(item.feat_image, out); }
inline friend void deserialize ( very_simple_feature_extractor& item, std::istream& in ) { deserialize(item.feat_image, in); }
void copy_configuration ( const very_simple_feature_extractor& item){}
void copy_configuration ( const very_simple_feature_extractor&){}
private:
array2d<unsigned char> feat_image;

View File

@ -34,10 +34,10 @@ class serv : public server_iostream
std::istream& in,
std::ostream& out,
const std::string& foreign_ip,
const std::string& local_ip,
unsigned short foreign_port,
unsigned short local_port,
uint64 connection_id
const std::string& /*local_ip*/,
unsigned short /*foreign_port*/,
unsigned short /*local_port*/,
uint64 /*connection_id*/
)
{
// The details of the connection are contained in the last few arguments to