Fix #11723 and #11724.
[ghc.git] / mk / warnings.mk
1 # See Note [Order of warning flags].
2 SRC_CC_OPTS += -Wall $(WERROR)
3 SRC_HC_OPTS += -Wall
4 # Don't add -Werror to SRC_HC_OPTS_STAGE0 (or SRC_HC_OPTS), because otherwise
5 # validate may unnecessarily fail when booting with an older compiler.
6 # It would be better to only exclude certain warnings from becoming errors
7 # (e.g. '-Werror -Wno-error=unused-imports -Wno-error=...'), but -Wno-error
8 # isn't supported yet (https://ghc.haskell.org/trac/ghc/wiki/Design/Warnings).
9 #
10 # See Note [Stage number in build variables] in mk/config.mk.in.
11 SRC_HC_OPTS_STAGE1 += $(WERROR)
12 SRC_HC_OPTS_STAGE2 += $(WERROR)
13
14
15 ifneq "$(GccIsClang)" "YES"
16
17 # Debian doesn't turn -Werror=unused-but-set-variable on by default, so
18 # we turn it on explicitly for consistency with other users
19 ifeq "$(GccLT46)" "NO"
20 # Never set the flag on Windows as the host gcc may be too old.
21 ifneq "$(HostOS_CPP)" "mingw32"
22 SRC_CC_WARNING_OPTS += -Werror=unused-but-set-variable
23 endif
24 # gcc 4.6 gives 3 warning for giveCapabilityToTask not being inlined
25 SRC_CC_WARNING_OPTS += -Wno-error=inline
26 endif
27
28 else
29
30 # Don't warn about unknown GCC pragmas when using clang
31 SRC_CC_WARNING_OPTS += -Wno-unknown-pragmas
32
33 endif
34
35 SRC_HC_WARNING_OPTS_STAGE1 += -Wnoncanonical-monad-instances
36 SRC_HC_WARNING_OPTS_STAGE2 += -Wnoncanonical-monad-instances
37
38
39 ######################################################################
40 # Disable some warnings in packages we use
41
42 # NB: The GHC version used for bootstrapping may not support the
43 # `-W`-aliases for `-f(no-)warn` flags introduced in GHC 8.0, so in
44 # some cases (watch out for make-variables with a name containing
45 # "boot") we need to pass the legacy `-f(no-)warn`-flags instead.
46
47 # Libraries that have dubious RULES
48 libraries/bytestring_dist-install_EXTRA_HC_OPTS += -Wno-inline-rule-shadowing
49
50 # Turn off import warnings for bad unused imports
51 utils/haddock_dist_EXTRA_HC_OPTS += -Wno-unused-imports
52 libraries/vector_dist-install_EXTRA_HC_OPTS += -Wno-unused-imports
53
54 # haddock's attoparsec uses deprecated `inlinePerformIO`
55 utils/haddock_dist_EXTRA_HC_OPTS += -Wno-deprecations
56 # binary too
57 libraries/binary_dist-install_EXTRA_HC_OPTS += -Wno-deprecations
58
59 # On Windows, there are/were some unused import warnings
60 ifeq "$(HostOS_CPP)" "mingw32"
61 libraries/time_dist-install_EXTRA_HC_OPTS += -Wno-unused-imports -Wno-identities
62 endif
63
64 # On Windows, the pattern for CallConv is already exaustive. Ignore the warning
65 ifeq "$(HostOS_CPP)" "mingw32"
66 libraries/ghci_dist-install_EXTRA_HC_OPTS += -Wno-overlapping-patterns
67 endif
68
69 # haskeline has warnings about deprecated use of block/unblock
70 libraries/haskeline_dist-install_EXTRA_HC_OPTS += -Wno-deprecations
71 libraries/haskeline_dist-install_EXTRA_HC_OPTS += -Wno-unused-imports
72 libraries/haskeline_dist-install_EXTRA_HC_OPTS += -Wno-redundant-constraints
73
74
75 # temporarily turn off unused-imports warnings for pretty
76 libraries/pretty_dist-install_EXTRA_HC_OPTS += -Wno-unused-imports
77
78 # primitive has a warning about deprecated use of GHC.IOBase
79 libraries/primitive_dist-install_EXTRA_HC_OPTS += -Wno-unused-imports
80 # primitive uses deprecated Control.Monad.Trans.Error
81 libraries/primitive_dist-install_EXTRA_HC_OPTS += -Wno-deprecations
82
83 # See https://github.com/haskell/random/pull/20
84 libraries/random_dist-install_EXTRA_HC_OPTS += -Wno-redundant-constraints
85
86 # temporarily turn off unused-imports warnings for terminfo
87 libraries/terminfo_dist-boot_EXTRA_HC_OPTS += -fno-warn-unused-imports
88 libraries/terminfo_dist-install_EXTRA_HC_OPTS += -Wno-unused-imports
89
90 # vector has some unused match warnings
91 libraries/vector_dist-install_EXTRA_HC_OPTS += -Wwarn
92
93 # temporarily turn off unused-imports warnings for xhtml
94 libraries/xhtml_dist-install_EXTRA_HC_OPTS += -Wno-unused-imports
95 libraries/xhtml_dist-install_EXTRA_HC_OPTS += -Wno-tabs
96
97 libraries/dph/dph-base_dist-install_EXTRA_HC_OPTS += -Wwarn
98 libraries/dph/dph-prim-interface_dist-install_EXTRA_HC_OPTS += -Wwarn
99 libraries/dph/dph-prim-seq_dist-install_EXTRA_HC_OPTS += -Wwarn
100 libraries/dph/dph-prim-par_dist-install_EXTRA_HC_OPTS += -Wwarn
101 libraries/dph/dph-lifted-common-install_EXTRA_HC_OPTS += -Wwarn
102
103 # transformers has unused function parameters warnings
104 libraries/transformers_dist-boot_EXTRA_HC_OPTS += -fno-warn-unused-matches -fno-warn-unused-imports
105 libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wno-unused-matches -Wno-unused-imports
106 libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wno-redundant-constraints
107 libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wno-orphans
108
109 # Turn of trustworthy-safe warning
110 libraries/base_dist-install_EXTRA_HC_OPTS += -Wno-trustworthy-safe
111 libraries/ghc-prim_dist-install_EXTRA_HC_OPTS += -Wno-trustworthy-safe
112 libraries/Win32_dist-install_EXTRA_HC_OPTS += -Wno-trustworthy-safe
113
114 # We need -Wno-deprecated-flags to avoid failure with -Werror
115 GhcLibExtraHcOpts += -Wno-deprecated-flags
116 GhcBootLibExtraHcOpts += -fno-warn-deprecated-flags
117
118 # Note [Order of warning flags]
119 #
120 # In distdir-way-opts, build flags are added in the following order (this
121 # list is not exhaustive):
122 #
123 # * SRC_HC_OPTS(_STAGE$4)
124 # * ghc-options from .cabal files ($1_$2_HC_OPTS)
125 # * SRC_HC_WARNING_OPTS(_STAGE$4)
126 #
127 # Considerations:
128 #
129 # * Most .cabal files specify -Wall. But not all, and not all building we
130 # do relies on .cabal files. So we have to add -Wall ourselves somewhere.
131 #
132 # * Some .cabal also specify warning suppression flags. Because -Wall
133 # overrides any warning suppression flags that come before it, we have to
134 # make sure -Wall comes before any warning suppression flags. So we add it
135 # to SRC_HC_OPTS.
136 #
137 # * Similarly, our own warning suppression should come after the -Wall from
138 # the .cabal files, so we do *not* add them to SRC_HC_OPTS.