Skip to content

Commit

Permalink
Merge pull request #25599 from Jojo-Schmitz/compiler-warnings
Browse files Browse the repository at this point in the history
Fix GCC, CLANG, MSVC and MOC compiler warnings
  • Loading branch information
cbjeukendrup authored Nov 27, 2024
2 parents a60fcde + 1a2798e commit eef395b
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 45 deletions.
16 changes: 11 additions & 5 deletions buildscripts/cmake/SetupCompileWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ function(target_no_warning TARGET WNAME)
elseif(WNAME STREQUAL "-Wno-unused-variable")
set(MSVC_Warning /wd4101 /wd4189)
elseif(WNAME STREQUAL "-Wunused-const-variable=0")

elseif(WNAME STREQUAL "-Wno-type-limits")

elseif(WNAME STREQUAL "-Wno-unknown-pragmas")

elseif(WNAME STREQUAL "-Wno-truncate")
set(MSVC_Warning /wd4310 /wd4311)
unset(GCC_Warning)
elseif(WNAME STREQUAL "-Wno-uninitialized")
set(MSVC_Warning /wd4701 /wd4703)
elseif(WNAME STREQUAL "-Wno-float-conversion")
Expand All @@ -53,8 +51,16 @@ function(target_no_warning TARGET WNAME)
elseif(WNAME STREQUAL "-Wno-implicit-fallthrough")
elseif(WNAME STREQUAL "-Wno-empty-body")
elseif(WNAME STREQUAL "-Wno-attributes")
elseif(WNAME STREQUAL "-Wno-absolute-value")
elseif(WNAME STREQUAL "-Wno-tautological-pointer-compare")
elseif(WNAME STREQUAL "-Wc-no-absolute-value")
set(GCC_Warning $<$<COMPILE_LANGUAGE:C>:-Wno-absolute-value>)
set(CLANG_Warning $<$<COMPILE_LANGUAGE:C>:-Wno-absolute-value>)
elseif(WNAME STREQUAL "-Wc-no-tautological-pointer-compare")
set(GCC_Warning $<$<COMPILE_LANGUAGE:C>:-Wno-tautological-pointer-compare>)
set(CLANG_Warning $<$<COMPILE_LANGUAGE:C>:-Wno-tautological-pointer-compare>)
elseif(WNAME STREQUAL "-Wc-no-array-parameter")
set(GCC_Warning $<$<COMPILE_LANGUAGE:C>:-Wno-array-parameter>)
set(CLANG_Warning $<$<COMPILE_LANGUAGE:C>:-Wno-array-parameter>)
elseif(WNAME STREQUAL "-Wno-unused-but-set-variable")
elseif(WNAME STREQUAL "-Wno-sign-compare")
elseif(WNAME STREQUAL "-Wno-attributes")
elseif(WNAME STREQUAL "-Wno-restrict")
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ EngravingItem* Factory::doCreateItem(ElementType type, EngravingItem* parent)
case ElementType::ROOT_ITEM:
case ElementType::FIGURED_BASS_ITEM:
case ElementType::DUMMY:
case ElementType::SYSTEM_LOCK_INDICATOR:
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/engraving/dom/instrtemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ const InstrumentTemplate* searchTemplate(const String& name)
const InstrumentTemplate* combinedTemplateSearch(const String& mxmlId, const String& name, const int transposition, int bank,
int program)
{
int minLevenshteinDistance = std::numeric_limits<int>::max();
size_t minLevenshteinDistance = std::numeric_limits<size_t>::max();
const InstrumentTemplate* templateWithMinLevenshteinDistance = nullptr;

if (mxmlId.empty() && name.empty() && bank == 0 && program == -1) {
Expand Down Expand Up @@ -810,7 +810,7 @@ const InstrumentTemplate* combinedTemplateSearch(const String& mxmlId, const Str
// if the name has some meaning we calculate the distance
if ((!name.isEmpty()) && (name != u"MusicXML Part") && (name != u"Staff")) {
// We keep the lowest distance with trackName ...
int levenshteinDistance = muse::strings::levenshteinDistance(
size_t levenshteinDistance = muse::strings::levenshteinDistance(
StaffName(name).toString().toStdString(), it->trackName.toStdString());

// ... and longNames
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/ornament.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ bool Ornament::setProperty(Pid propertyId, const PropertyValue& v)
break;
case Pid::ORNAMENT_SHOW_CUE_NOTE:
setShowCueNote(v.value<AutoOnOff>());
break;
case Pid::START_ON_UPPER_NOTE:
setStartOnUpperNote(v.toBool());
break;
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/systemlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void SystemLocks::dump()
#endif

SystemLockIndicator::SystemLockIndicator(System* parent, const SystemLock* lock)
: m_systemLock(lock), EngravingItem(ElementType::SYSTEM_LOCK_INDICATOR, parent, ElementFlag::SYSTEM | ElementFlag::GENERATED) {}
: EngravingItem(ElementType::SYSTEM_LOCK_INDICATOR, parent, ElementFlag::SYSTEM | ElementFlag::GENERATED), m_systemLock(lock) {}

Font SystemLockIndicator::font() const
{
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/infrastructure/eidregister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "eidregister.h"
#include "log.h"

using namespace mu::engraving;

Expand All @@ -37,7 +38,11 @@ EID EIDRegister::newEID(ElementType type)
void EIDRegister::registerItemEID(EID eid, EngravingObject* item)
{
bool inserted = m_register.emplace(eid.toUint64(), item).second;
#ifdef NDEBUG
UNUSED(inserted);
#else
assert(inserted);
#endif
}

EngravingObject* EIDRegister::itemFromEID(EID eid)
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/internal/engravingconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class EngravingConfiguration : public IEngravingConfiguration, public muse::Inje
Color formattingColor() const override;
muse::async::Channel<Color> formattingColorChanged() const override;

Color frameColor() const;
muse::async::Channel<Color> frameColorChanged() const;
Color frameColor() const override;
muse::async::Channel<Color> frameColorChanged() const override;

Color unlinkedColor() const override;
muse::async::Channel<Color> unlinkedColorChanged() const override;
Expand Down
20 changes: 10 additions & 10 deletions src/engraving/rendering/score/horizontalspacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ std::vector<HorizontalSpacing::SegmentPosition> HorizontalSpacing::spaceSegments
std::vector<SegmentPosition> placedSegments;
placedSegments.reserve(segList.size());

for (int i = 0; i < segList.size(); ++i) {
for (size_t i = 0; i < segList.size(); ++i) {
Segment* curSeg = segList[i];
if (ignoreSegmentForSpacing(curSeg)) {
placedSegments.emplace_back(curSeg, ctx.xCur);
continue;
}

if (i < startSegIdx) {
if (static_cast<int>(i) < startSegIdx) {
placedSegments.emplace_back(curSeg, curSeg->xPosInSystemCoords());
ctx.xCur = curSeg->xPosInSystemCoords() + curSeg->width();
continue;
Expand Down Expand Up @@ -320,8 +320,8 @@ void HorizontalSpacing::spaceAgainstPreviousSegments(Segment* segment, std::vect
checkLyricsAgainstLeftMargin(segment, x, ctx);
}

for (int i = static_cast<int>(prevSegPositions.size()) - 1; i >= 0; --i) {
const SegmentPosition& prevSegPos = prevSegPositions[i];
for (size_t i = prevSegPositions.size(); i > 0; --i) {
const SegmentPosition& prevSegPos = prevSegPositions[i - 1];
Segment* prevSeg = prevSegPos.segment;
double xPrevSeg = prevSegPos.xPosInSystemCoords;

Expand All @@ -340,7 +340,7 @@ void HorizontalSpacing::spaceAgainstPreviousSegments(Segment* segment, std::vect
if (prevCRSegmentsCount > 0) {
double spaceIncrease = (x - ctx.xCur) / prevCRSegmentsCount;
double xMovement = spaceIncrease;
for (int j = i + 1; j < prevSegPositions.size(); ++j) {
for (size_t j = i; j < prevSegPositions.size(); ++j) {
SegmentPosition& segPos = prevSegPositions[j];
segPos.xPosInSystemCoords += xMovement;
if (segPos.segment->isChordRestType()) {
Expand Down Expand Up @@ -434,9 +434,9 @@ void HorizontalSpacing::checkLyricsAgainstRightMargin(std::vector<SegmentPositio
{
int chordRestSegmentsCount = 0;

for (int i = int(segPositions.size()) - 1; i > 0; --i) {
for (size_t i = segPositions.size(); i > 1; --i) {
double systemEdge = segPositions.back().xPosInSystemCoords + segPositions.back().segment->minRight();
SegmentPosition& segPos = segPositions[i];
SegmentPosition& segPos = segPositions[i - 1];
double x = segPos.xPosInSystemCoords;
Segment* seg = segPos.segment;
if (!seg->measure()->isLastInSystem()) {
Expand All @@ -459,7 +459,7 @@ void HorizontalSpacing::checkLyricsAgainstRightMargin(std::vector<SegmentPositio
double lyricsOvershoot = xMaxLyrics - systemEdge;
double spaceIncrease = lyricsOvershoot / chordRestSegmentsCount;
double xMovement = spaceIncrease;
for (int j = i + 1; j < segPositions.size(); ++j) {
for (size_t j = i; j < segPositions.size(); ++j) {
SegmentPosition& sp = segPositions[j];
sp.xPosInSystemCoords += xMovement;
if (sp.segment->isChordRestType()) {
Expand Down Expand Up @@ -745,7 +745,7 @@ double HorizontalSpacing::computeMinMeasureWidth(Measure* m)

void HorizontalSpacing::enforceMinimumMeasureWidths(const std::vector<Measure*> measureGroup)
{
for (int i = 0; i < measureGroup.size(); ++i) {
for (size_t i = 0; i < measureGroup.size(); ++i) {
Measure* measure = measureGroup[i];
if (measure->isMMRest()) {
continue; // minimum mmRest width is already enforced during spacing
Expand All @@ -754,7 +754,7 @@ void HorizontalSpacing::enforceMinimumMeasureWidths(const std::vector<Measure*>
double diff = minWidth - measure->width();
if (diff > 0) {
stretchMeasureToTargetWidth(measure, minWidth);
for (int j = i + 1; j < measureGroup.size(); ++j) {
for (size_t j = i + 1; j < measureGroup.size(); ++j) {
measureGroup[j]->mutldata()->moveX(diff);
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/engraving/rendering/score/scorehorizontalviewlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,6 @@ void ScoreHorizontalViewLayout::collectLinearSystem(LayoutContext& ctx)
ctx.mutState().setTick(Fraction(0, 1));
MeasureLayout::getNextMeasure(ctx);

static constexpr Fraction minTicks = Fraction(1, 16);
static constexpr Fraction maxTicks = Fraction(4, 4);
// CAUTION: In continuous view, we cannot look fot the shortest (or longest) note
// of the system (as we do in page view), because the whole music is a single big system. Therefore,
// we simply assume a shortest note of 1/16 and longest of 4/4. This ensures perfect spacing consistency,
// even if the actual values may be be different.

while (ctx.state().curMeasure()) {
double ww = 0.0;
if (ctx.state().curMeasure()->isVBox() || ctx.state().curMeasure()->isTBox()) {
Expand Down
6 changes: 4 additions & 2 deletions src/framework/audio/thirdparty/lame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ target_no_warning(${MODULE} -Wno-shift-negative-value)
target_no_warning(${MODULE} -Wno-implicit-fallthrough)
target_no_warning(${MODULE} -Wno-empty-body)
target_no_warning(${MODULE} -Wno-attributes)
target_no_warning(${MODULE} -Wno-absolute-value) # we need this for C code in this module , but not for its C++ code
#target_no_warning(${MODULE} -Wno-tautological-pointer-compare)
target_no_warning(${MODULE} -Wc-no-absolute-value)
target_no_warning(${MODULE} -Wc-no-tautological-pointer-compare)
target_no_warning(${MODULE} -Wc-no-array-parameter)
target_no_warning(${MODULE} -Wno-unused-but-set-variable)
target_no_warning(${MODULE} -WMSVC-no-translation-unit-is-empty)
target_no_warning(${MODULE} -WMSVC-no-nonstandard-extension-used)
target_no_warning(${MODULE} -WMSVC-no-assignment-within-conditional-expression)
Expand Down
20 changes: 10 additions & 10 deletions src/framework/global/stringutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,29 @@ bool muse::strings::lessThanCaseInsensitive(const String& lhs, const String& rhs
return lhsLower < rhsLower;
}

int muse::strings::levenshteinDistance(const std::string& s1, const std::string& s2)
size_t muse::strings::levenshteinDistance(const std::string& s1, const std::string& s2)
{
size_t N1 = s1.length();
size_t N2 = s2.length();
int i, j;
std::vector<int> T(N2 + 1);
size_t i, j;
std::vector<size_t> V(N2 + 1);

for (i = 0; i <= N2; i++) {
T[i] = i;
V[i] = i;
}

for (i = 0; i < N1; i++) {
T[0] = i + 1;
int corner = i;
V[0] = i + 1;
size_t corner = i;
for (j = 0; j < N2; j++) {
int upper = T[j + 1];
size_t upper = V[j + 1];
if (s1[i] == s2[j]) {
T[j + 1] = corner;
V[j + 1] = corner;
} else {
T[j + 1] = std::min(T[j], std::min(upper, corner)) + 1;
V[j + 1] = std::min(V[j], std::min(upper, corner)) + 1;
}
corner = upper;
}
}
return T[N2];
return V[N2];
}
2 changes: 1 addition & 1 deletion src/framework/global/stringutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::string toString(const T& t)
bool lessThanCaseInsensitive(const std::string& lhs, const std::string& rhs);
bool lessThanCaseInsensitive(const String& lhs, const String& rhs);

int levenshteinDistance(const std::string& s1, const std::string& s2);
size_t levenshteinDistance(const std::string& s1, const std::string& s2);
}

#endif // MUSE_GLOBAL_STRINGUTILS_H
2 changes: 1 addition & 1 deletion src/importexport/guitarpro/internal/gtp/gpconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,7 @@ void GPConverter::addHarmonicMark(const GPBeat* gpbeat, ChordRest* cr)

void GPConverter::addFretDiagram(const GPBeat* gpnote, ChordRest* cr, const Context& ctx, bool asHarmony)
{
int GPTrackIdx = muse::indexOf(_score->parts(), cr->part());
int GPTrackIdx = static_cast<int>(muse::indexOf(_score->parts(), cr->part()));
int diaId = gpnote->diagramIdx(GPTrackIdx, ctx.masterBarIndex);

if (_lastDiagramIdx == diaId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Muse.UiComponents 1.0
StyledPopupView {
id: root

property list<bool> voicesVisibility: []
property var voicesVisibility: []
signal voiceVisibilityChangeRequested(int voiceIndex, bool voiceVisible)

contentHeight: contentColumn.childrenRect.height
Expand Down
6 changes: 3 additions & 3 deletions src/notation/view/widgets/editstyle.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10157,7 +10157,7 @@
</layout>
</widget>
<widget class="QWidget" name="PageGlissNoteLines">
<layout class="QVBoxLayout" name="verticalLayout_69">
<layout class="QVBoxLayout" name="verticalLayout_691">
<item>
<widget class="QGroupBox" name="groupBox_glissando">
<property name="title">
Expand Down Expand Up @@ -11004,7 +11004,7 @@
</widget>
</item>
<item>
<spacer name="verticalSpacer_39">
<spacer name="verticalSpacer_391">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
Expand All @@ -11024,7 +11024,7 @@
<property name="title">
<string>Trill cue note</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_691">
<layout class="QVBoxLayout" name="verticalLayout_692">
<item>
<widget class="QRadioButton" name="ornamentShowCueNoteOnlyNonSeconds">
<property name="text">
Expand Down
1 change: 1 addition & 0 deletions thirdparty/beatroot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ set(MODULE_SRC
setup_module()

target_no_warning(${MODULE} -Wno-conversion)
target_no_warning(${MODULE} -Wno-unused-but-set-variable)
1 change: 1 addition & 0 deletions thirdparty/rtf2html/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ set(MODULE_SRC
setup_module()

target_no_warning(${MODULE} -Wno-conversion)
target_no_warning(${MODULE} -Wno-deprecated-declarations)

0 comments on commit eef395b

Please sign in to comment.