Skip to content

Commit fd79f15

Browse files
Daschle-Newberrydnewberry1chrchr-github
authored
Fixed Qt config macro declaration (#8796)
The macro definition of `Q_ASSERT_X` results in false positives. ### Example ```cpp #include <QDebug> void test() { const char *where = "test"; const char *what = "assertion failed"; Q_ASSERT_X(false, where, what); } ```` This code block results in: ```commandline style: Variable 'where' is assigned a value that is never used. [unreadVariable] style: Variable 'what' is assigned a value that is never used. [unreadVariable] ``` The existing definition discards `where` and `what` arguments when modeling `Q_ASSERT_X`. The fix preserves these arguments using `(void) (what)` and `(void) (where)` --------- Co-authored-by: Daschle Newberry <dnewberry@deltamotion.com> Co-authored-by: chrchr-github <78114321+chrchr-github@users.noreply.github.com>
1 parent ff4d7ce commit fd79f15

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ daisuke-chiba
101101
Daniel Friedrich
102102
David Korczynski
103103
Daniel Marjamäki
104+
Daschle Newberry
104105
David Hallas
105106
David Korth
106107
Dávid Slivka

cfg/qt.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5520,7 +5520,7 @@
55205520
<define name="Q_OVERRIDE(x)" value=""/>
55215521
<define name="Q_PLUGIN_METADATA(x)" value=""/>
55225522
<define name="Q_ASSERT(condition)" value="assert(condition)"/>
5523-
<define name="Q_ASSERT_X(condition, where, what)" value="assert(condition)"/>
5523+
<define name="Q_ASSERT_X(condition, where, what)" value="assert(condition); (void)(where); (void)(what)"/>
55245524
<define name="QTC_ASSERT_STRINGIFY_HELPER(x)" value="#x"/>
55255525
<define name="QTC_ASSERT_STRINGIFY(x)" value="QTC_ASSERT_STRINGIFY_HELPER(x)"/>
55265526
<define name="QTC_ASSERT_STRING(cond)" value="::Utils::writeAssertLocation( &quot;\&quot;&quot; cond&quot;\&quot; in file &quot; __FILE__ &quot;, line &quot; QTC_ASSERT_STRINGIFY(__LINE__))"/>

test/cfg/qt.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,13 @@ int qdateIsValid()
894894
return qd.month();
895895
}
896896

897+
void qAssertX()
898+
{
899+
const char *where = "test";
900+
const char *what = "assertion failed";
901+
Q_ASSERT_X(false, where, what);
902+
}
903+
897904
struct S_QTimer_connect : QObject { // #13846
898905
S_QTimer_connect() {
899906
// cppcheck-suppress checkLibraryFunction - timeout() is a signal from QTimer

0 commit comments

Comments
 (0)