Skip to content

Commit

Permalink
2035: fix gcc 7.2 warnings (#2036)
Browse files Browse the repository at this point in the history
* 2035: fix gcc 7.2 warnings

* 2035: try older attribute syntax for g++ 4.8.4 compatibility

* 2035: check for gcc7 for [[gnu::fallthrough]] attribute

* 2035: remove two unintended switch fallthroughs

* 2035: change brace style in Allocator.h
  • Loading branch information
ericwa committed Mar 6, 2018
1 parent 5961f25 commit 6bbad15
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 6 deletions.
9 changes: 5 additions & 4 deletions common/src/Allocator.h
Expand Up @@ -138,11 +138,12 @@ class Allocator {
assert(!chunk->full());
T* block = chunk->allocate();

if (chunk->full())
if (chunk->full()) {
fullChunks().push_back(chunk);
else
mixedChunks().push_back(chunk);
return block;
} else {
mixedChunks().push_back(chunk);
}
return block;
}

void operator delete(void* block) {
Expand Down
3 changes: 3 additions & 0 deletions common/src/IO/DefParser.cpp
Expand Up @@ -54,13 +54,15 @@ namespace TrenchBroom {
break;
}
// fall through and try to read as word
switchFallthrough();
}
case '*': {
if (lookAhead() == '/') {
advance();
return Token(DefToken::CDefinition, c, curPos(), offset(c), startLine, startColumn);
}
// fall through and try to read as word
switchFallthrough();
}
case '(':
advance();
Expand All @@ -82,6 +84,7 @@ namespace TrenchBroom {
return Token(DefToken::Semicolon, c, c + 1, offset(c), startLine, startColumn);
case '\r':
advance();
switchFallthrough();
case '\n':
advance();
return Token(DefToken::Newline, c, c + 1, offset(c), startLine, startColumn);
Expand Down
1 change: 1 addition & 0 deletions common/src/IO/StandardMapParser.cpp
Expand Up @@ -88,6 +88,7 @@ namespace TrenchBroom {
advance();
return Token(QuakeMapToken::Eol, c, c+1, offset(c), startLine, startColumn);
}
switchFallthrough();
case '\r':
case ' ':
case '\t':
Expand Down
9 changes: 9 additions & 0 deletions common/src/Macros.h
Expand Up @@ -37,6 +37,15 @@
#define switchDefault() default: assert(false); throw "Unhandled switch case";
#endif

// Annotate an intended switch fallthrough
#ifdef __clang__
#define switchFallthrough() [[clang::fallthrough]]
#elif __GNUC__ >= 7
#define switchFallthrough() [[gnu::fallthrough]]
#else
#define switchFallthrough()
#endif

#define assertResult(funexp) { const bool result = (funexp); unused(result); assert(result); }

#define deleteCopyAndAssignment(classname) private: classname(const classname& other); classname& operator=(const classname& other);
Expand Down
2 changes: 2 additions & 0 deletions common/src/Model/ChangeBrushFaceAttributesRequest.cpp
Expand Up @@ -127,6 +127,7 @@ namespace TrenchBroom {
case ChangeBrushFaceAttributesRequest::ValueOp_Set:
myOp = theirOp;
myValue = theirValue;
return true;
case ChangeBrushFaceAttributesRequest::ValueOp_Add:
return false;
case ChangeBrushFaceAttributesRequest::ValueOp_Mul:
Expand All @@ -144,6 +145,7 @@ namespace TrenchBroom {
case ChangeBrushFaceAttributesRequest::FlagOp_None:
myOp = theirOp;
myValue = theirValue;
return true;
case ChangeBrushFaceAttributesRequest::FlagOp_Replace:
switch (theirOp) {
case ChangeBrushFaceAttributesRequest::FlagOp_None:
Expand Down
2 changes: 2 additions & 0 deletions common/src/Polyhedron_ConvexHull.h
Expand Up @@ -397,6 +397,7 @@ typename Polyhedron<T,FP,VP>::Vertex* Polyhedron<T,FP,VP>::addFurtherPointToPoly
case Math::PointStatus::PSAbove:
face->flip();
callback.faceWasFlipped(face);
switchFallthrough();
case Math::PointStatus::PSBelow:
return makePolyhedron(position, callback);
}
Expand Down Expand Up @@ -1045,6 +1046,7 @@ class Polyhedron<T,FP,VP>::SplittingCriterion {
switch (result) {
case MatchResult_Second:
edge->flip();
switchFallthrough();
case MatchResult_First:
return edge;
case MatchResult_Both:
Expand Down
1 change: 1 addition & 0 deletions common/src/Renderer/IndexRangeMap.cpp
Expand Up @@ -54,6 +54,7 @@ namespace TrenchBroom {
break;
}
}
switchFallthrough();
}
case GL_LINE_STRIP:
case GL_LINE_LOOP:
Expand Down
2 changes: 1 addition & 1 deletion common/src/View/CellLayout.h
Expand Up @@ -531,7 +531,7 @@ namespace TrenchBroom {
ensure(index >= 0 && index < m_groups.size(), "index out of range");
if (!m_valid)
validate();
return m_groups[index];
return m_groups[index];
}

CellLayout(const size_t maxCellsPerRow = 0) :
Expand Down
3 changes: 2 additions & 1 deletion test/src/Model/BrushTest.cpp
Expand Up @@ -3204,8 +3204,9 @@ namespace TrenchBroom {
brush->removeVertices(worldBounds, toRemove);

for (size_t l = 0; l < 8; ++l) {
if (l != i && l != j && l != k)
if (l != i && l != j && l != k) {
ASSERT_TRUE(brush->hasVertex(vertices[l]));
}
}

delete brush;
Expand Down

0 comments on commit 6bbad15

Please sign in to comment.