Unverified Commit 0aa8b4cb authored by Juha Reunanen's avatar Juha Reunanen Committed by GitHub
Browse files

Treat warnings as errors (#2490)

parent 49314c12
...@@ -370,7 +370,7 @@ namespace dlib ...@@ -370,7 +370,7 @@ namespace dlib
and the fact that this has a different name (global swap has the same name as 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. 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. 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 This also means you should NOT use this function in your own code unless
......
...@@ -117,14 +117,16 @@ namespace dlib ...@@ -117,14 +117,16 @@ namespace dlib
private: private:
row(T* data_, long cols) : data(data_), nc_(cols) {} row(T* data_, long cols) : data(data_), nc_(cols) {}
row(row&& r) = default;
row& operator=(row&& r) = default;
T* data; T* data = nullptr;
long nc_; long nc_ = 0;
// restricted functions // restricted functions
row(){} row(const row&) = delete;
row& operator=(row&); row& operator=(const row&) = delete;
}; };
// ----------------------------------- // -----------------------------------
......
...@@ -1518,7 +1518,6 @@ namespace dlib ...@@ -1518,7 +1518,6 @@ namespace dlib
bool message_sent = true; bool message_sent = true;
std::vector<unsigned long>::iterator iter;
while (message_sent) while (message_sent)
{ {
message_sent = false; message_sent = false;
......
...@@ -26,10 +26,10 @@ namespace dlib ...@@ -26,10 +26,10 @@ namespace dlib
// this is here for backwards compatibility with older versions of dlib. // this is here for backwards compatibility with older versions of dlib.
typedef crc32 kernel_1a; typedef crc32 kernel_1a;
inline crc32 ( inline crc32 (
); );
inline crc32 ( inline crc32 (
const std::string& item const std::string& item
); );
...@@ -65,10 +65,6 @@ namespace dlib ...@@ -65,10 +65,6 @@ namespace dlib
crc32& item crc32& item
); );
inline crc32& operator=(
const crc32&
);
private: private:
unsigned long checksum; unsigned long checksum;
...@@ -147,7 +143,7 @@ namespace dlib ...@@ -147,7 +143,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
crc32:: crc32::
crc32 ( crc32 (
) )
{ {
checksum = 0xFFFFFFFF; checksum = 0xFFFFFFFF;
...@@ -243,17 +239,6 @@ namespace dlib ...@@ -243,17 +239,6 @@ namespace dlib
exchange(checksum,item.checksum); exchange(checksum,item.checksum);
} }
// ----------------------------------------------------------------------------------------
crc32& crc32::
operator=(
const crc32& item
)
{
checksum = item.checksum;
return *this;
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -31,7 +31,7 @@ namespace dlib ...@@ -31,7 +31,7 @@ namespace dlib
- #*this is properly initialized - #*this is properly initialized
!*/ !*/
crc32 ( crc32 (
const std::string& item const std::string& item
); );
/*! /*!
......
...@@ -2479,7 +2479,7 @@ namespace dlib ...@@ -2479,7 +2479,7 @@ namespace dlib
float* t = &output(0,0); float* t = &output(0,0);
// now fill in the Toeplitz output matrix for the n-th sample in data. // 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_r = data.nr() + padding_y-(filter_nr-1);
const long max_c = data.nc() + padding_x-(filter_nc-1); const long max_c = data.nc() + padding_x-(filter_nc-1);
for (long r = -padding_y; r < max_r; r+=stride_y) for (long r = -padding_y; r < max_r; r+=stride_y)
......
...@@ -2259,7 +2259,7 @@ namespace dlib ...@@ -2259,7 +2259,7 @@ namespace dlib
void back_propagate_error( void back_propagate_error(
const tensor& /*x*/, const tensor& /*x*/,
const tensor& /*gradient_input*/, const tensor& /*gradient_input*/,
zero_gradients zero_grads = zero_gradients::yes zero_gradients /*zero_grads*/ = zero_gradients::yes
) )
{ {
// nothing to do // nothing to do
...@@ -3746,7 +3746,7 @@ namespace dlib ...@@ -3746,7 +3746,7 @@ namespace dlib
typename visitor typename visitor
> >
static void visit( static void visit(
net_type& net, net_type&,
const add_tag_layer<tag_id,SUBNET>& next_net, const add_tag_layer<tag_id,SUBNET>& next_net,
visitor&& v visitor&& v
) )
...@@ -3760,7 +3760,7 @@ namespace dlib ...@@ -3760,7 +3760,7 @@ namespace dlib
typename visitor typename visitor
> >
static void visit( static void visit(
net_type& net, net_type&,
add_tag_layer<tag_id,SUBNET>& next_net, add_tag_layer<tag_id,SUBNET>& next_net,
visitor&& v visitor&& v
) )
......
...@@ -476,7 +476,6 @@ namespace dlib ...@@ -476,7 +476,6 @@ namespace dlib
typedef matrix<T,NR,NC,MM,L> input_type; typedef matrix<T,NR,NC,MM,L> input_type;
input() {} input() {}
input(const input&) {}
template <typename mm> template <typename mm>
input(const input<array2d<T,mm>>&) {} input(const input<array2d<T,mm>>&) {}
...@@ -728,25 +727,25 @@ namespace dlib ...@@ -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); serialize("input<array2d>", out);
} }
friend void deserialize(input& item, std::istream& in) friend void deserialize(input&, std::istream& in)
{ {
std::string version; std::string version;
deserialize(version, in); deserialize(version, in);
if (version != "input<array2d>") if (version != "input<array2d>")
throw serialization_error("Unexpected version found while deserializing dlib::input."); 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>"; out << "input<array2d>";
return out; return out;
} }
friend void to_xml(const input& item, std::ostream& out) friend void to_xml(const input&, std::ostream& out)
{ {
out << "<input/>"; out << "<input/>";
} }
......
...@@ -552,7 +552,7 @@ namespace dlib ...@@ -552,7 +552,7 @@ namespace dlib
visitor_net_to_dot(std::ostream& out) : out(out) {} visitor_net_to_dot(std::ostream& out) : out(out) {}
template <typename input_layer_type> 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"); start_node(i, "input");
end_node(); end_node();
...@@ -609,7 +609,7 @@ namespace dlib ...@@ -609,7 +609,7 @@ namespace dlib
} }
template <template <typename> class TAG, typename U> 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; const auto t = tag_id<TAG>::id;
from = tag_to_layer.at(t); from = tag_to_layer.at(t);
...@@ -887,7 +887,7 @@ namespace dlib ...@@ -887,7 +887,7 @@ namespace dlib
} }
template <template <typename> class... TAGS, typename U, typename E> 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"); start_node(i, "concat");
end_node(); end_node();
...@@ -930,7 +930,7 @@ namespace dlib ...@@ -930,7 +930,7 @@ namespace dlib
} }
template <typename T, typename U, typename E> 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"); start_node(i, "unhandled layer");
update(i); update(i);
......
...@@ -750,7 +750,7 @@ namespace dlib ...@@ -750,7 +750,7 @@ namespace dlib
// Circumvent what appears to be a bug in Visual Studio 2019's optimizer // 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) // (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 ( push )
#pragma warning ( disable: 4723 ) #pragma warning ( disable: 4723 )
#endif #endif
...@@ -774,7 +774,7 @@ namespace dlib ...@@ -774,7 +774,7 @@ namespace dlib
return centered_rect(rect, (long)std::round(rect.width()*scale), (long)std::round(rect.height()*scale)); 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 ) #pragma warning ( pop )
#endif #endif
......
...@@ -31,6 +31,9 @@ namespace dlib ...@@ -31,6 +31,9 @@ namespace dlib
typedef T1 key_type; typedef T1 key_type;
typedef T2 value_type; typedef T2 value_type;
map_pair() = default;
map_pair(const map_pair&) = default;
virtual ~map_pair( virtual ~map_pair(
)=0; )=0;
......
...@@ -710,6 +710,12 @@ namespace dlib ...@@ -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 > template < typename P1, typename P2 >
typename enable_if_c<pixel_traits<P1>::grayscale && pixel_traits<P2>::grayscale>::type typename enable_if_c<pixel_traits<P1>::grayscale && pixel_traits<P2>::grayscale>::type
assign(P1& dest, const P2& src) assign(P1& dest, const P2& src)
...@@ -728,6 +734,10 @@ namespace dlib ...@@ -728,6 +734,10 @@ namespace dlib
dest = pixel_traits<P1>::max(); dest = pixel_traits<P1>::max();
} }
#if defined (_MSC_VER)
#pragma warning ( pop )
#endif
// ----------------------------- // -----------------------------
// ----------------------------- // -----------------------------
// ----------------------------- // -----------------------------
......
...@@ -47,12 +47,12 @@ namespace dlib ...@@ -47,12 +47,12 @@ namespace dlib
- if (current_element_valid()) then - if (current_element_valid()) then
- element() == mp - element() == mp
!*/ !*/
class mpair : public map_pair<domain,range> class mpair : public map_pair<domain,range>
{ {
public: public:
const domain* d; const domain* d = nullptr;
range* r; range* r = nullptr;
const domain& key( const domain& key(
) const { return *d; } ) const { return *d; }
......
...@@ -154,7 +154,7 @@ namespace dlib ...@@ -154,7 +154,7 @@ namespace dlib
{ {
// max_cost_assignment() only works with integer matrices, so convert from // max_cost_assignment() only works with integer matrices, so convert from
// double to integer. // 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)); matrix<dlib::int64> int_cost = matrix_cast<dlib::int64>(round(cost*scale));
assignment = max_cost_assignment(int_cost); assignment = max_cost_assignment(int_cost);
assignment.resize(lhs.size()); assignment.resize(lhs.size());
......
...@@ -43,15 +43,6 @@ namespace dlib ...@@ -43,15 +43,6 @@ namespace dlib
decision_function ( decision_function (
) : b(0), kernel_function(K()) {} ) : 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 ( decision_function (
const scalar_vector_type& alpha_, const scalar_vector_type& alpha_,
const scalar_type& b_, const scalar_type& b_,
...@@ -137,14 +128,6 @@ namespace dlib ...@@ -137,14 +128,6 @@ namespace dlib
probabilistic_function ( probabilistic_function (
) : alpha(0), beta(0), decision_funct(function_type()) {} ) : 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 ( probabilistic_function (
const scalar_type a_, const scalar_type a_,
const scalar_type b_, const scalar_type b_,
...@@ -232,14 +215,6 @@ namespace dlib ...@@ -232,14 +215,6 @@ namespace dlib
decision_funct(d.decision_funct) 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 ( probabilistic_decision_function (
const scalar_type a_, const scalar_type a_,
const scalar_type b_, const scalar_type b_,
...@@ -353,16 +328,6 @@ namespace dlib ...@@ -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 ( distance_function (
const scalar_vector_type& alpha_, const scalar_vector_type& alpha_,
const scalar_type& b_, const scalar_type& b_,
...@@ -586,13 +551,6 @@ namespace dlib ...@@ -586,13 +551,6 @@ namespace dlib
normalized_function ( normalized_function (
){} ){}
normalized_function (
const normalized_function& f
) :
normalizer(f.normalizer),
function(f.function)
{}
const std::vector<result_type> get_labels( const std::vector<result_type> get_labels(
) const { return function.get_labels(); } ) const { return function.get_labels(); }
...@@ -673,10 +631,6 @@ namespace dlib ...@@ -673,10 +631,6 @@ namespace dlib
projection_function ( projection_function (
) {} ) {}
projection_function (
const projection_function& f
) : weights(f.weights), kernel_function(f.kernel_function), basis_vectors(f.basis_vectors) {}
projection_function ( projection_function (
const scalar_matrix_type& weights_, const scalar_matrix_type& weights_,
const K& kernel_function_, const K& kernel_function_,
......
...@@ -64,14 +64,6 @@ namespace dlib ...@@ -64,14 +64,6 @@ namespace dlib
- #basis_vectors.nr() == 0 - #basis_vectors.nr() == 0
!*/ !*/
decision_function (
const decision_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
decision_function ( decision_function (
const scalar_vector_type& alpha_, const scalar_vector_type& alpha_,
const scalar_type& b_, const scalar_type& b_,
...@@ -169,14 +161,6 @@ namespace dlib ...@@ -169,14 +161,6 @@ namespace dlib
- #decision_funct has its initial value - #decision_funct has its initial value
!*/ !*/
probabilistic_function (
const probabilistic_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
probabilistic_function ( probabilistic_function (
const scalar_type a, const scalar_type a,
const scalar_type b, const scalar_type b,
...@@ -282,15 +266,7 @@ namespace dlib ...@@ -282,15 +266,7 @@ namespace dlib
!*/ !*/
probabilistic_decision_function ( probabilistic_decision_function (
const probabilistic_decision_function& f const probabilistic_function<decision_function<K> >& f
);
/*!
ensures
- #*this is a copy of f
!*/
probabilistic_decision_function (
const probabilistic_function<decision_function<K> >& d
); );
/*! /*!
ensures ensures
...@@ -445,17 +421,6 @@ namespace dlib ...@@ -445,17 +421,6 @@ namespace dlib
- #get_basis_vectors() == f.basis_vectors - #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 ( distance_function (
const scalar_vector_type& alpha, const scalar_vector_type& alpha,
const scalar_type& squared_norm, const scalar_type& squared_norm,
...@@ -679,14 +644,6 @@ namespace dlib ...@@ -679,14 +644,6 @@ namespace dlib
- the members of this object have their default values - the members of this object have their default values
!*/ !*/
normalized_function (
const normalized_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
normalized_function ( normalized_function (
const vector_normalizer<sample_type>& normalizer_, const vector_normalizer<sample_type>& normalizer_,
const function_type& funct const function_type& funct
...@@ -791,14 +748,6 @@ namespace dlib ...@@ -791,14 +748,6 @@ namespace dlib
- #basis_vectors.size() == 0 - #basis_vectors.size() == 0
!*/ !*/
projection_function (
const projection_function& f
);
/*!
ensures
- #*this is a copy of f
!*/
projection_function ( projection_function (
const scalar_matrix_type& weights_, const scalar_matrix_type& weights_,
const K& kernel_function_, const K& kernel_function_,
......
...@@ -655,7 +655,7 @@ namespace dlib ...@@ -655,7 +655,7 @@ namespace dlib
trainer_type trainer; trainer_type trainer;
scalar_type min_learning_rate; scalar_type min_learning_rate;
bool verbose; bool verbose = true;
bool use_cache; bool use_cache;
long cache_size; long cache_size;
......
...@@ -247,7 +247,7 @@ namespace dlib ...@@ -247,7 +247,7 @@ namespace dlib
{ {
// max_cost_assignment() only works with integer matrices, so convert from // max_cost_assignment() only works with integer matrices, so convert from
// double to integer. // 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)); matrix<dlib::int64> int_cost = matrix_cast<dlib::int64>(round(cost*scale));
assignment = max_cost_assignment(int_cost); assignment = max_cost_assignment(int_cost);
assignment.resize(samples[idx].first.size()); assignment.resize(samples[idx].first.size());
......
...@@ -166,13 +166,22 @@ set (tests ...@@ -166,13 +166,22 @@ set (tests
# cmake that they are part of our target (which is the executable named dtest) # cmake that they are part of our target (which is the executable named dtest)
ADD_EXECUTABLE(${target_name} main.cpp tester.cpp ${tests}) ADD_EXECUTABLE(${target_name} main.cpp tester.cpp ${tests})
# Turn on all warnings when using gcc.
if (CMAKE_COMPILER_IS_GNUCXX) 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 # I don't care about unused testing functions though. I like to keep them
# around. Don't warn about it. # around. Don't warn about it.
add_definitions("-Wno-unused-function") add_definitions("-Wno-unused-function")
add_definitions("-Wno-strict-overflow") 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() endif()
...@@ -181,6 +190,12 @@ TARGET_LINK_LIBRARIES(${target_name} dlib::dlib ) ...@@ -181,6 +190,12 @@ TARGET_LINK_LIBRARIES(${target_name} dlib::dlib )
if (NOT DLIB_NO_GUI_SUPPORT) if (NOT DLIB_NO_GUI_SUPPORT)
add_subdirectory(gui) add_subdirectory(gui)
add_subdirectory(examples)
add_subdirectory(tools) 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() endif()
...@@ -75,7 +75,7 @@ namespace ...@@ -75,7 +75,7 @@ namespace
bool detected_error = false; bool detected_error = false;
try { try {
test.decompress(sin,sout); test.decompress(sin,sout);
} catch ( typename cs::decompression_error& e ) } catch ( typename cs::decompression_error& )
{ {
detected_error = true; detected_error = true;
++count; ++count;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment