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
\page qmllint-warnings-and-errors-unterminated-case.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Unterminated non-empty case block
9
\brief [unterminated-case] A non-empty case block was not terminated.
10
11
\qmllintwarningcategory unterminated-case
12
13
\section1 Unterminated non-empty case block
14
15
\section2 What happened?
16
A case block in a switch statement was non-empty but was not terminated by a
17
break, return, or throw statement. There was also no opt-in fallthrough
18
comment.
19
20
\section2 Why is that bad?
21
Fallthrough logic in switch statements can be confusing or overlooked. If it is
22
intentional, it should be marked explicitly with a comment such as
23
"// fallthrough". If it isn't intentional, the warning indicates that a
24
terminating statement was forgotten.
25
26
\section2 Example
27
\qml
28
switch (state) {
29
case Main.State.Reset:
30
clearState() // <--- "Unterminated non-empty case block"
31
case Main.State.Invalid:
32
asyncInitState()
33
return false
34
case Main.State.Initializing:
35
// wait for initialization to complete
36
return false
37
case Main.State.Ready:
38
res = lookup(query)
39
log(res.stats)
40
saveToDisk(res.data) // <--- "Unterminated non-empty case block"
41
default:
42
throw new InvalidStateException("Unknown state")
43
}
44
\endqml
45
To fix this warning, add missing terminating statements or add explicit opt-in
46
comments allowing fallthrough logic:
47
\qml
48
switch (state) {
49
case Main.State.Reset:
50
clearState()
51
// fallthrough // <--- add fallthrough comment
52
case Main.State.Invalid:
53
asyncInitState()
54
return false
55
case Main.State.Initializing:
56
// wait for initialization to complete
57
return false
58
case Main.State.Ready:
59
res = lookup(query)
60
log(res.stats)
61
saveToDisk(res.data)
62
return true // <--- add forgotten terminating statement
63
default:
64
throw new InvalidStateException("Unknown state")
65
}
66
\endqml
67
*/
qtdeclarative
src
qml
doc
src
qmllint
unterminated-case.qdoc
Generated on
for Qt by
1.14.0