Bug 495204 - huge number of build warnings: declaration of ‘value’ shadows a member of ‘MyMoneyKeyValueContainer’ [-Wshadow]
Summary: huge number of build warnings: declaration of ‘value’ shadows a member of ‘My...
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: buildsystem (show other bugs)
Version: git (master)
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-22 18:37 UTC by Ralf Habacker
Modified: 2024-11-15 20:54 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 5.2
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Habacker 2024-10-22 18:37:38 UTC
STEPS TO REPRODUCE
1. build kmymoney from master branch with g++ version 7.5
2. inspect build log

OBSERVED RESULT
There are tons of messages like this:

cd /home/xxx/src/kmymoney-2-build/kmymoney/mymoney && /usr/bin/ccache /usr/bin/c++ -DKCOREADDONS_LIB -DKF_DEPRECATED_WARNINGS_SINCE=0x60000 -DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x56200C -DQT_CORE_LIB -DQT_DBUS_LIB -DQT_DEPRECATED_WARNINGS_SINCE=0x60000 -DQT_DISABLE_DEPRECATED_BEFORE=0x50f02 -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_CAST_TO_ASCII -DQT_NO_KEYWORDS -DQT_NO_URL_CAST_FROM_STRING -DQT_POSITIONING_LIB -DQT_PRINTSUPPORT_LIB -DQT_QMLMODELS_LIB -DQT_QML_LIB -DQT_QUICK_LIB -DQT_USE_QSTRINGBUILDER -DQT_WEBCHANNEL_LIB -DQT_WEBENGINECORE_LIB -DQT_WEBENGINEWIDGETS_LIB -DQT_WIDGETS_LIB -DQT_XML_LIB -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -Dkmm_mymoney_EXPORTS -I/home/xxx/src/kmymoney-2-build/kmymoney/mymoney -I/home/xxx/src/kmymoney-2/kmymoney/mymoney -I/home/xxx/src/kmymoney-2-build/kmymoney/mymoney/kmm_mymoney_autogen/include -I/home/xxx/src/kmymoney-2 -I/home/xxx/src/kmymoney-2-build -I/home/xxx/src/kmymoney-2/kmymoney -I/home/xxx/src/kmymoney-2-build/kmymoney -I/home/xxx/src/kmymoney-2/kmymoney/settings -I/home/xxx/src/kmymoney-2-build/kmymoney/settings -I/home/xxx/src/kmymoney-2-build/kmymoney/dialogs -I/home/xxx/src/kmymoney-2/kmymoney/widgets -I/home/xxx/src/kmymoney-2-build/kmymoney/widgets -I/home/xxx/src/kmymoney-2/kmymoney/mymoney/storage -I/home/xxx/src/kmymoney-2/kmymoney/interfaces -I/home/xxx/src/kmymoney-2-build/kmymoney/interfaces -I/home/xxx/src/kmymoney-2/kmymoney/plugins -I/home/xxx/src/kmymoney-2-build/kmymoney/plugins -I/home/xxx/src/kmymoney-2/kmymoney/views -I/home/xxx/src/kmymoney-2/kmymoney/dialogs -I/home/xxx/src/kmymoney-2/kmymoney/converter -I/home/xxx/src/kmymoney-2-build/kmymoney/dialogs/settings -I/home/xxx/src/kmymoney-2-build/kmymoney/mymoney/storage -I/home/xxx/src/kmymoney-2/kmymoney/wizards/endingbalancedlg -I/home/xxx/src/kmymoney-2-build/kmymoney/wizards/endingbalancedlg -I/home/xxx/src/kmymoney-2/kmymoney/wizards/newinvestmentwizard -I/home/xxx/src/kmymoney-2-build/kmymoney/wizards/newinvestmentwizard -I/home/xxx/src/kmymoney-2/kmymoney/wizards/newloanwizard -I/home/xxx/src/kmymoney-2-build/kmymoney/wizards/newloanwizard -I/home/xxx/src/kmymoney-2/kmymoney/wizards/wizardpages -I/home/xxx/src/kmymoney-2/kmymoney/models -I/home/xxx/src/kmymoney-2-build/kmymoney/models -I/home/xxx/src/kmymoney-2/kmymoney/icons -I/home/xxx/src/kmymoney-2-build/kmymoney/icons -I/home/xxx/src/kmymoney-2/kmymoney/menus -I/home/xxx/src/kmymoney-2-build/kmymoney/menus -I/home/xxx/src/kmymoney-2/kmymoney/misc -I/home/xxx/src/kmymoney-2-build/kmymoney/misc -I/home/xxx/src/kmymoney-2-build/kmymoney/mymoney/payeeidentifier -I/home/xxx/src/kmymoney-2/kmymoney/mymoney/payeeidentifier -I/home/xxx/src/kmymoney-2-build/kmymoney/plugins/onlinetasks/interfaces -I/home/xxx/src/kmymoney-2/kmymoney/plugins/onlinetasks/interfaces -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtXml -isystem /usr/include/qt5/QtCore -isystem /usr/lib64/qt5/mkspecs/linux-g++ -isystem /usr/include/qt5/QtGui -isystem /usr/include/KF5/KService -isystem /usr/include/KF5 -isystem /usr/include/KF5/KConfig -isystem /usr/include/KF5/KConfigCore -isystem /usr/include/KF5/KCoreAddons -isystem /usr/include/KF5/KI18n -isystem /usr/include/KF5/KItemModels -isystem /home/xxx/src/alkimia-qt5-install/usr/include/alkimia/Qt5 -isystem /home/xxx/src/alkimia-qt5-install/usr/include -isystem /usr/include/qt5/QtWebEngineWidgets -isystem /usr/include/qt5/QtWebEngineCore -isystem /usr/include/qt5/QtQuick -isystem /usr/include/qt5/QtQmlModels -isystem /usr/include/qt5/QtQml -isystem /usr/include/qt5/QtNetwork -isystem /usr/include/qt5/QtWebChannel -isystem /usr/include/qt5/QtPositioning -isystem /usr/include/qt5/QtPrintSupport -isystem /usr/include/qt5/QtWidgets -isystem /usr/include/KF5/KXmlGui -isystem /usr/include/KF5/KConfigWidgets -isystem /usr/include/KF5/KWidgetsAddons -isystem /usr/include/KF5/KConfigGui -isystem /usr/include/KF5/KCodecs -isystem /usr/include/KF5/KAuthWidgets -isystem /usr/include/KF5/KAuthCore -isystem /usr/include/KF5/KAuth -isystem /usr/include/qt5/QtDBus -isystem /usr/include/KF5/KIdentityManagement -isystem /usr/include/KF5/AkonadiCore -isystem /usr/include/KF5/KContacts -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type -Werror=init-self -Wvla -Wdate-time -Wsuggest-override -Wlogical-op -fexceptions -g -std=c++14 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -fdiagnostics-color=always -Wall -Wextra -Wlogical-op -Wno-null-dereference -Wshadow -Wunused -Wno-misleading-indentation -Wsuggest-override -Wcast-qual -Wformat=2 -fno-common -Werror=return-type -fPIC -fexceptions -MD -MT kmymoney/mymoney/CMakeFiles/kmm_mymoney.dir/mymoneyforecast.cpp.o -MF CMakeFiles/kmm_mymoney.dir/mymoneyforecast.cpp.o.d -o CMakeFiles/kmm_mymoney.dir/mymoneyforecast.cpp.o -c /home/xxx/src/kmymoney-2/kmymoney/mymoney/mymoneyforecast.cpp
In file included from /home/xxx/src/kmymoney-2/kmymoney/mymoney/mymoneyaccount.h:23:0,
                 from /home/xxx/src/kmymoney-2/kmymoney/mymoney/mymoneyforecast.cpp:24:
/home/xxx/src/kmymoney-2/kmymoney/mymoney/mymoneykeyvaluecontainer.h: In member function ‘void MyMoneyKeyValueContainer::setValue(const QString&, T, T)’:
/home/xxx/src/kmymoney-2/kmymoney/mymoney/mymoneykeyvaluecontainer.h:117:5: warning: declaration of ‘value’ shadows a member of ‘MyMoneyKeyValueContainer’ [-Wshadow]
     {
     ^
/home/xxx/src/kmymoney-2/kmymoney/mymoney/mymoneykeyvaluecontainer.h:97:7: note: shadowed declaration is here
     T value(const QString& key, T defaultValue) const
       ^~~~~

At the source locations there is: 

 see https://invent.kde.org/office/kmymoney/-/blob/master/kmymoney/mymoney/mymoneykeyvaluecontainer.h#L117
 see https://invent.kde.org/office/kmymoney/-/blob/master/kmymoney/mymoney/mymoneykeyvaluecontainer.h#L97

EXPECTED RESULT
This warnings should not appear.

SOFTWARE/OS VERSIONS
Operating System: openSUSE Leap 15.5
KDE Plasma Version: 5.27.9
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Comment 1 Ralf Habacker 2024-10-22 19:37:59 UTC
Comment from Thomas Baumgart at https://invent.kde.org/office/kmymoney/-/merge_requests/235#note_1057397

> Why does the name of the argument need to be changed?    In case there is a reason, please call it newValue instead of _value.
> Rationale: Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace as per C++ specs.
> So I recommend to avoid using it in this context (even though it does not conflict as we have no global namespace here).
Comment 2 Ralf Habacker 2024-10-22 19:42:44 UTC
As far as I can see from the source locations at 

1.  https://invent.kde.org/office/kmymoney/-/blob/master/kmymoney/mymoney/mymoneykeyvaluecontainer.h#L97 

    /**
     * convenience method for @c enum
     */
    template<typename T>
    T value(const QString& key, T defaultValue) const
    {
        return static_cast<T>(value(key, static_cast<int>(defaultValue)));
    }

2. https://invent.kde.org/office/kmymoney/-/blob/master/kmymoney/mymoney/mymoneykeyvaluecontainer.h#L117 
    /**
     * convenience method for integral types (except bool)
     */
    template<typename T>
    void setValue(const QString& key, T value, T defaultValue)
    {
        return setValue_int(key, static_cast<int>(value), static_cast<int>(defaultValue));
    }

the two templates here have a problem.
Comment 3 Thomas Baumgart 2024-10-23 06:09:31 UTC
Using a more recent compiler (g++-13, g++-14, clang v17) also solves this issue.
Comment 4 Thomas Baumgart 2024-11-15 20:54:51 UTC
Git commit a58a6de82a78bac8de71ca41d00931827bbf73f8 by Thomas Baumgart.
Committed on 15/11/2024 at 20:54.
Pushed by tbaumgart into branch 'master'.

Prevent warning about shadowing a member
FIXED-IN: 5.2

M  +2    -2    kmymoney/mymoney/mymoneyaccountloan.cpp
M  +9    -9    kmymoney/mymoney/mymoneykeyvaluecontainer.cpp
M  +2    -2    kmymoney/mymoney/mymoneykeyvaluecontainer.h

https://invent.kde.org/office/kmymoney/-/commit/a58a6de82a78bac8de71ca41d00931827bbf73f8