Q_ASSERT(res == local) in QDateTime::currentDateTime() on ios
-
Hi there. I'm trying debug my ios app. I use QDateTime::currentDateTime() and get Q_ASSERT(res == local) which occur in QLocalTime func. I have no idea what's wrong, how can two pointers can be same?
@QOlzhas
Can you pls post a stack trace? -
@QOlzhas
Can you pls post a stack trace?@Axel-Spoerl, sure
-
@QOlzhas
Can you pls post a stack trace?@Axel-Spoerl. I'm a little confused, how can res and locale be the same thing? Are two pointers being compared that cannot be equal, because the addresses are always different, or do I not understand something? The contents of these two pointers are absolutely identical.
-
@Axel-Spoerl. I'm a little confused, how can res and locale be the same thing? Are two pointers being compared that cannot be equal, because the addresses are always different, or do I not understand something? The contents of these two pointers are absolutely identical.
@QOlzhas
That's a bug. Can you file a bug report under https://bugreports.qt.io ?
Thanks! -
@Axel-Spoerl. I'm a little confused, how can res and locale be the same thing? Are two pointers being compared that cannot be equal, because the addresses are always different, or do I not understand something? The contents of these two pointers are absolutely identical.
-
@J-Hilk, nothing criminal
57 QApplication app (argc, argv); 58 if (!AppManager::init (&app)) 59 return 0;
AppManager is an application core class, which has logger:
DapLogger::DapLogger(QObject *parent, QString appType, size_t prefix_width) : QObject(parent) , m_day(QDateTime::currentDateTime().toString("dd"))
In the logger constructor calls QDateTime to get current time, where app assert on res == local.
-
@QOlzhas
That's a bug. Can you file a bug report under https://bugreports.qt.io ?
Thanks! -
@QOlzhas oh my, thats a rookie mistake in the Qt code,
it is
if(tm *res = localtime_r(&utc, local))
but it should be
if(tm *res = localtime_r(&utc, local); res)
someone disabled/ignored warnings during compiling ...
@J-Hilk said in Q_ASSERT(res == local) in QDateTime::currentDateTime() on ios:
if(tm *res = localtime_r(&utc, local); tm)
I don't use this kind of C++ construct, so excuse me if I am off base, but isn't
tm
a type here? Did you meanres
by any chance?And isn't the result of
if(tm *res = localtime_r(&utc, local))
alreadyres
(even if it lacks an extra pair of of()
to keep gcc happy, or test!= nullptr
if you prefer), unless this new-fangled inline declaration of a variable changes that behaviour? -
@J-Hilk said in Q_ASSERT(res == local) in QDateTime::currentDateTime() on ios:
if(tm *res = localtime_r(&utc, local); tm)
I don't use this kind of C++ construct, so excuse me if I am off base, but isn't
tm
a type here? Did you meanres
by any chance?And isn't the result of
if(tm *res = localtime_r(&utc, local))
alreadyres
(even if it lacks an extra pair of of()
to keep gcc happy, or test!= nullptr
if you prefer), unless this new-fangled inline declaration of a variable changes that behaviour?@JonB said in Q_ASSERT(res == local) in QDateTime::currentDateTime() on ios:
I don't use this kind of C++ construct, so excuse me if I am off base, but isn't tm a type here? Did you mean res by any chance?
you're correct, I changed it.
the result is res, but its not checked. Well I think this may be compiler dependent.
I'm not sure anymore, you made me question myself T_T
-
@JonB said in Q_ASSERT(res == local) in QDateTime::currentDateTime() on ios:
I don't use this kind of C++ construct, so excuse me if I am off base, but isn't tm a type here? Did you mean res by any chance?
you're correct, I changed it.
the result is res, but its not checked. Well I think this may be compiler dependent.
I'm not sure anymore, you made me question myself T_T
@J-Hilk said in Q_ASSERT(res == local) in QDateTime::currentDateTime() on ios:
the result is res, but its not checked. Well I think this may be compiler dependent.
I don't know what you mean by this. If you do an assignment in a conditional the result of the condition is the result of the assignment. That is C or C++. The only "wriggle" if that compilers like to warn you that
if (a = b)
might be a mistype forif (a == b)
, so they variously want you to either put in extra parenthesesif ((a = b))
(gcc) or an explicit testif ((a = b) != nullptr)
(MSVC?). Your new-fangledif (a = b; a)
is just an alternative way of writing the same thing it seems to me?