Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
unterminated-case.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\ingroup qmllint-warnings-and-errors
6
7
\title Unterminated non-empty case block
8
\brief [unterminated-case] A non-empty case block was not terminated.
9
10
\qmllintwarningcategory unterminated-case
11
12
\section1 Unterminated non-empty case block
13
14
\section2 What happened?
15
A case block in a switch statement was non-empty but was not terminated by a
16
break, return, or throw statement. There was also no opt-in fallthrough
17
comment.
18
19
\section2 Why is that bad?
20
Fallthrough logic in switch statements can be confusing or overlooked. If it is
21
intentional, it should be marked explicitly with a comment such as
22
"// fallthrough". If it isn't intentional, the warning indicates that a
23
terminating statement was forgotten.
24
25
\section2 Example
26
\qml
27
switch (state) {
28
case Main.State.Reset:
29
clearState() // <--- "Unterminated non-empty case block"
30
case Main.State.Invalid:
31
asyncInitState()
32
return false
33
case Main.State.Initializing:
34
// wait for initialization to complete
35
return false
36
case Main.State.Ready:
37
res = lookup(query)
38
log(res.stats)
39
saveToDisk(res.data) // <--- "Unterminated non-empty case block"
40
default:
41
throw new InvalidStateException("Unknown state")
42
}
43
\endqml
44
To fix this warning, add missing terminating statements or add explicit opt-in
45
comments allowing fallthrough logic:
46
\qml
47
switch (state) {
48
case Main.State.Reset:
49
clearState()
50
// fallthrough // <--- add fallthrough comment
51
case Main.State.Invalid:
52
asyncInitState()
53
return false
54
case Main.State.Initializing:
55
// wait for initialization to complete
56
return false
57
case Main.State.Ready:
58
res = lookup(query)
59
log(res.stats)
60
saveToDisk(res.data)
61
return true // <--- add forgotten terminating statement
62
default:
63
throw new InvalidStateException("Unknown state")
64
}
65
\endqml
66
*/
qtdeclarative
src
qml
doc
src
qmllint
unterminated-case.qdoc
Generated on
for Qt by
1.16.1