/
warnings.dd
94 lines (72 loc) · 1.96 KB
/
warnings.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Ddoc
$(D_S Warnings,
$(P Depending on one's point of view, warnings are either a symptom
of broken language design or a useful $(SINGLEQUOTE lint) like tool to analyze
code and look for potential trouble spots.
Most of the time, those trouble spots will be legitimate code
intended to be that way. More rarely, it may indicate an
unintentional error on the part of the programmer.
)
$(P Warnings are not a defined part of the D Programming Language.
They exist at the discretion of the compiler vendor, and
will most likely vary from vendor to vendor.
All constructs for which an implementation may generate a warning
message are legal D code.
)
$(P These are the warnings generated by the Digital Mars D compiler
when the $(B -w) switch is thrown. This mode also forces compiler
to stop if any warning is produced.
Most have generated some spirited debate as to whether it should
be a warning, an error, and what the correct way to write D code
in these situations should be. Since no consensus emerged,
they appear as optional warnings, with alternatives on how to
write correct code.
)
$(H3 warning - statement is not reachable)
$(P Consider the following code:)
---
int foo(int i)
{
return i;
$(B return i + 1;)
}
---
$(P The second return statement is not reachable, i.e. it is dead
code. While dead code is poor style in released code, it can
legitimately
happen a lot when rapidly trying to isolate down a bug or experiment
with different bits of code.
)
$(P The warning can be resolved by:
)
$(OL
$(LI Commenting out the dead code with /+ ... +/ comments:
---
int foo(int i)
{
return i;
/+
return i + 1;
+/
}
---
)
$(LI Putting the dead code inside a $(D version(none)) conditional:
---
int foo(int i)
{
return i;
$(B version (none))
{
return i + 1;
}
}
---
)
$(LI Only compile with warnings enabled when doing release builds.
)
)
)
Macros:
TITLE=Warnings
SUBNAV=$(SUBNAV_ARTICLES)