summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-09-18 11:46:55 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-09-23 17:00:00 +0200
commitdf4cbaf8dc59a5c62ad82a56de8e3596bfecebcd (patch)
tree9398b08bf2f2b1a5cb1e3ede3c1e914e56581886
parent1ec67b5e266864fb9d37f04e0239277b8e8978e2 (diff)
Assert some conditions instead of testing for them
In one case, handle an error by an early return so that we can do so. Change-Id: If98eaaf2dfd47c1df1d09497fcc3e9ab784dc6df Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/time/qdatetimeparser.cpp21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp
index 5e072b10ca..8ab6f73a31 100644
--- a/src/corelib/time/qdatetimeparser.cpp
+++ b/src/corelib/time/qdatetimeparser.cpp
@@ -733,11 +733,8 @@ QDateTimeParser::parseSection(const QDateTime &currentValue, int sectionIndex,
{
ParsedSection result; // initially Invalid
const SectionNode &sn = sectionNode(sectionIndex);
- if (sn.type & Internal) {
- qWarning("QDateTimeParser::parseSection Internal error (%ls %d)",
- qUtf16Printable(sn.name()), sectionIndex);
- return result;
- }
+ Q_ASSERT_X(!(sn.type & Internal),
+ "QDateTimeParser::parseSection", "Internal error");
const int sectionmaxsize = sectionMaxSize(sectionIndex);
QStringView sectionTextRef = QStringView{*text}.mid(offset, sectionmaxsize);
@@ -1226,27 +1223,23 @@ QDateTimeParser::scanString(const QDateTime &defaultValue,
default:
qWarning("QDateTimeParser::parse Internal error (%ls)",
qUtf16Printable(sn.name()));
- break;
+ return StateNode();
}
+ Q_ASSERT(current);
+ Q_ASSERT(sect.state != Invalid);
if (sect.used > 0)
pos += sect.used;
QDTPDEBUG << index << sn.name() << "is set to"
<< pos << "state is" << stateName(state);
- if (!current) {
- qWarning("QDateTimeParser::parse Internal error 2");
- return StateNode();
- }
if (isSet & sn.type && *current != sect.value) {
QDTPDEBUG << "CONFLICT " << sn.name() << *current << sect.value;
conflicts = true;
- if (index != currentSectionIndex || sect.state == Invalid) {
+ if (index != currentSectionIndex)
continue;
- }
}
- if (sect.state != Invalid)
- *current = sect.value;
+ *current = sect.value;
// Record the present section:
isSet |= sn.type;