Skip to content

Commit 977fa36

Browse files
authored
Enable warnings as error on Linux (#85)
This commit increases warning level and enables warnings as error on Linux build. Doing this pointed out several cases of sign mismatches, variable defintion ordering issues, and unused variables.
1 parent 555d2d4 commit 977fa36

10 files changed

Lines changed: 32 additions & 30 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ else()
6565
-fvisibility=hidden # By default, hide symbols on ELF binaries
6666
-g # add debug symbols for build pdb
6767
-pedantic
68+
-Wall
69+
-Werror
70+
$<$<CXX_COMPILER_ID:GNU>:-Wno-unused-but-set-variable>
71+
-Wno-unused-variable
6872
)
6973

7074
# AppleClang is not accepting -flto as linker option

api/combination.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ ComboStatus Combination::Feasible( int value )
112112
ComboStatus retval = ( COVERED == m_bitvec[ value ] ) ? ComboStatus::CoveredMatch : ComboStatus::Open;
113113
for( ParamCollection::reverse_iterator iter = m_params.rbegin(); iter != m_params.rend(); ++iter )
114114
{
115-
if( ( *iter )->GetBoundCount() && ( *iter )->GetLast() != value % ( *iter )->GetValueCount() )
115+
if( ( *iter )->GetBoundCount() &&
116+
static_cast<int>(( *iter )->GetLast()) != value % ( *iter )->GetValueCount() )
116117
{
117118
return ComboStatus::Excluded;
118119
}
@@ -143,7 +144,7 @@ int Combination::Weight( int value )
143144
//
144145
int Combination::AddBinding()
145146
{
146-
if( ++m_boundCount == m_params.size() )
147+
if( ++m_boundCount == static_cast<int>(m_params.size()) )
147148
{
148149
// compute which zero we're setting
149150
size_t value = 0;
@@ -261,7 +262,7 @@ void Combination::SetOpen( int index )
261262
//
262263
//
263264
Combination::Combination( Model *M ) :
264-
m_bitvec( nullptr ), m_openCount( 0 ), m_boundCount( 0 ), m_range( 0 ), m_model( M )
265+
m_bitvec( nullptr ), m_range( 0 ), m_openCount( 0 ), m_boundCount( 0 ), m_model( M )
265266
{
266267
m_id = ++m_lastUsedId;
267268
DOUT( L"Combination created: " << m_id << endl );

api/generator.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,13 @@ class GenerationError
163163
{
164164
public:
165165

166-
GenerationError( std::string file, int line, ErrorType err = ErrorType::Unknown ) :
167-
_file( file ), _line( line ), _err( err ){}
166+
GenerationError( std::string, int, ErrorType err = ErrorType::Unknown ) :
167+
_err( err ){}
168168

169169
ErrorType GetErrorType() { return (ErrorType) _err; }
170170

171171
private:
172172
ErrorType _err;
173-
std::string _file;
174-
int _line;
175173
};
176174

177175
//
@@ -316,7 +314,7 @@ class Combination
316314
int Bind( int val, WorkList& worklist );
317315
int AddBinding();
318316
int GetBoundCount() const { return m_boundCount; }
319-
bool IsFullyBound() const { return m_boundCount == m_params.size(); }
317+
bool IsFullyBound() const { return m_boundCount == static_cast<int>(m_params.size()); }
320318

321319
void SetOpen ( int n );
322320
bool IsOpen ( int n ) const { return OPEN == m_bitvec[ n ]; }
@@ -375,9 +373,9 @@ class Parameter
375373
{
376374
public:
377375
Parameter( int order, int sequence, int valueCount, std::wstring name, bool expectedResultParam ) :
378-
m_order( order ), m_sequence( sequence ), m_valueCount( valueCount ),
379-
m_name( name ), m_expResultParam( expectedResultParam ), m_valueWeights( 0 ),
380-
m_bound( false ), m_pending( false ), m_avgExclusionSize( 0 )
376+
m_name( name ), m_order( order ), m_sequence( sequence ), m_valueCount( valueCount ),
377+
m_expResultParam( expectedResultParam ), m_bound( false ),
378+
m_pending( false ), m_valueWeights( 0 ), m_avgExclusionSize( 0 )
381379
{
382380
// result params must have order = 1
383381
if ( m_expResultParam ) m_order = 1;
@@ -503,7 +501,7 @@ class Model
503501
{
504502
public:
505503
Model( const std::wstring& id, GenerationType type, int order, long seed = 0 ) :
506-
m_id( id ), m_generationType( type ), m_order( order ), m_maxRows( 0 ), m_lastParamId( UNDEFINED_ID + 1000 * 1000 ) {
504+
m_id( id ), m_order( order ), m_maxRows( 0 ), m_generationType( type ), m_lastParamId( UNDEFINED_ID + 1000 * 1000 ) {
507505
SetRandomSeed( seed );
508506
}
509507
~Model();
@@ -613,7 +611,6 @@ class Model
613611

614612
GenerationType m_generationType;
615613

616-
Parameter* m_currentParam;
617614
unsigned int m_lastParamId;
618615
long m_totalCombinations;
619616
long m_remainingCombinations;

api/model.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void Model::markUndefinedValuesInResultParams()
469469
{
470470
// TODO: when result params are suported check modl/modl021.txt doesn't break here
471471
if( !i_term->first->IsExpectedResultParam()
472-
&& i_row->at( i_term->first->GetSequence() ) != i_term->second )
472+
&& static_cast<int>(i_row->at( i_term->first->GetSequence() )) != i_term->second )
473473
{
474474
matches = false;
475475
break;
@@ -520,7 +520,7 @@ void Model::markUndefinedValuesInResultParams()
520520
for( size_t row = 0; row < ip->second.size(); ++row )
521521
{
522522
// all values have to be excluded except for 1
523-
if( ip->second[ row ].size() != ip->first->GetValueCount() - 1 )
523+
if( static_cast<int>(ip->second[ row ].size()) != ip->first->GetValueCount() - 1 )
524524
{
525525
m_results[ row ][ col ] = Parameter::UndefinedValue;
526526
}
@@ -1061,7 +1061,7 @@ bool Model::mapExclusionsToPseudoParameters()
10611061
break;
10621062
}
10631063
int nParam = static_cast<int>( distance( comps->begin(), ip ) );
1064-
size_t nRealVal = param->GetModel()->GetResults()[ vidx ][ nParam ];
1064+
int nRealVal = static_cast<int>(param->GetModel()->GetResults()[ vidx ][ nParam ]);
10651065
if( nRealVal != irel->second )
10661066
{
10671067
break;
@@ -1227,7 +1227,7 @@ bool Model::rowViolatesExclusion( ResultRow& row )
12271227
bool matches = true;
12281228
for( Exclusion::iterator it = ie->begin(); it != ie->end(); ++it )
12291229
{
1230-
if( row[ it->first->GetSequence() ] != it->second )
1230+
if( static_cast<int>(row[ it->first->GetSequence() ]) != it->second )
12311231
{
12321232
matches = false;
12331233
break;
@@ -1302,7 +1302,7 @@ void Model::mapRowSeedsToPseudoParameters()
13021302
break;
13031303
}
13041304
int nParam = static_cast<int>( distance( comps->begin(), ip ) );
1305-
size_t nRealVal = param->GetModel()->GetResults()[ vidx ][ nParam ];
1305+
int nRealVal = static_cast<int>(param->GetModel()->GetResults()[ vidx ][ nParam ]);
13061306
if( nRealVal != irel->second )
13071307
{
13081308
break;

api/trie.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class trie
7676
{
7777
node = new trienode < typename Col::value_type >;
7878
}
79-
catch( std::bad_alloc e )
79+
catch(const std::bad_alloc& )
8080
{
8181
return( false );
8282
}

cli/ccommon.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ class CTerm
153153
IN std::wstring rawText // raw text of the term, useful for warnings
154154
) :
155155
Parameter ( parameter ),
156-
RelationType ( relationType ),
157156
DataType ( dataType ),
158-
Data ( data ),
159-
RawText ( rawText ) {}
157+
RelationType ( relationType ),
158+
RawText ( rawText ),
159+
Data ( data ) {}
160160

161161
CTerm( CTerm& Term ) :
162162
Parameter ( Term.Parameter ),
163-
RelationType( Term.RelationType ),
164163
DataType ( Term.DataType ),
164+
RelationType( Term.RelationType ),
165165
RawText ( Term.RawText )
166166
{
167167
assert( RelationType < RelationType::Unknown );
@@ -215,8 +215,8 @@ class CTerm
215215
CParameter* Parameter;
216216
TermDataType DataType;
217217
pictcli_constraints::RelationType RelationType;
218-
void* Data;
219218
std::wstring RawText;
219+
void* Data;
220220
};
221221

222222
//

cli/gcdexcl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ bool ConstraintsInterpreter::ConvertToExclusions( OUT CGcdExclusions& gcdExclusi
642642
// last-minute cleanup
643643
removeContradictingExclusions( gcdExclusions );
644644
}
645-
catch( std::bad_alloc e )
645+
catch( const std::bad_alloc& )
646646
{
647647
throw new GenerationError( __FILE__, __LINE__, ErrorType::OutOfMemory );
648648
}

cli/gcdmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool CGcdData::FixParamOrder( IN Model* submodel )
114114
{
115115
auto p = _modelData.FindParameterByGcdPointer( param );
116116
assert( p != _modelData.Parameters.end() );
117-
if( p->Order != UNDEFINED_ORDER )
117+
if( p->Order != static_cast<unsigned int>(UNDEFINED_ORDER) )
118118
{
119119
// TODO: add verification of Order
120120
// if p->Order > model->parameters.count - model.ResultParameters.count then error out

cli/model.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class CModelValue
2323
unsigned int weight,
2424
bool positive
2525
) : _names ( names ),
26-
_weight ( weight ),
2726
_positive ( positive ),
27+
_weight ( weight ),
2828
_currentNameIndex( 0 ) {}
2929

3030
wstrings& GetAllNames() { return( _names ); }
@@ -60,8 +60,8 @@ class CModelParameter
6060

6161
CModelParameter() :
6262
Name(L""),
63-
IsResultParameter(false),
6463
Order(static_cast<unsigned int>(UNDEFINED_ORDER)),
64+
IsResultParameter(false),
6565
GcdPointer(nullptr){}
6666

6767
int GetValueOrdinal( IN std::wstring& name, IN bool caseSensitive );
@@ -123,9 +123,9 @@ class CModelData
123123
CaseSensitive(false),
124124
Verbose(false),
125125
Statistics(false),
126-
RowSeedsFile(L""),
127126
GenerationMode(GenerationMode::Regular),
128127
MaxApproxTries(1000),
128+
RowSeedsFile(L""),
129129
ConstraintPredicates(L""),
130130
m_hasNegativeValues(false),
131131
m_encoding(EncodingType::ANSI),

cli/pict.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ int main
137137
{
138138
loc = std::locale("C.UTF-8");
139139
}
140-
catch ( std::runtime_error )
140+
catch ( const std::runtime_error&)
141141
{
142142
loc = std::locale::classic();
143143
}

0 commit comments

Comments
 (0)