Explicitly disable MSVC warnings.
These warnings used to be disabled via Chromium's build rules. However,
those were removed in https://crrev.com/927183, so when PDFium rolls
DEPS for //build past that CL, the MSVC build will fail. To avoid this
failure, explicitly disable the same MSVC warnings that Chromium used to
disable in PDFium's own build config.
Change-Id: I42e7b4e577e7edfcd938a2264757cb9f167cf8d6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/85790
Reviewed-by: Hui Yingst <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 885c2bb..bdb5dae 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -17,6 +17,7 @@
config("pdfium_common_config") {
cflags = []
+ cflags_cc = []
ldflags = []
include_dirs = [ "." ]
defines = [
@@ -43,8 +44,168 @@
if (is_win) {
# Assume UTF-8 by default to avoid code page dependencies.
cflags += [ "/utf-8" ]
- if (msvc_use_sse2 && !is_clang && current_cpu == "x86") {
- cflags += [ "/arch:SSE2" ]
+
+ if (!is_clang) {
+ cflags += [
+ # Warnings permanently disabled:
+
+ # C4091: 'typedef ': ignored on left of 'X' when no variable is
+ # declared.
+ # This happens in a number of Windows headers. Dumb.
+ "/wd4091",
+
+ # C4127: conditional expression is constant
+ # This warning can in theory catch dead code and other problems, but
+ # triggers in far too many desirable cases where the conditional
+ # expression is either set by macros or corresponds some legitimate
+ # compile-time constant expression (due to constant template args,
+ # conditionals comparing the sizes of different types, etc.). Some of
+ # these can be worked around, but it's not worth it.
+ "/wd4127",
+
+ # C4251: 'identifier' : class 'type' needs to have dll-interface to be
+ # used by clients of class 'type2'
+ # This is necessary for the shared library build.
+ "/wd4251",
+
+ # C4275: non dll-interface class used as base for dll-interface class
+ # This points out a potential (but rare) problem with referencing static
+ # fields of a non-exported base, through the base's non-exported inline
+ # functions, or directly. The warning is subtle enough that people just
+ # suppressed it when they saw it, so it's not worth it.
+ "/wd4275",
+
+ # C4312 is a VS 2015 64-bit warning for integer to larger pointer.
+ # TODO(brucedawson): fix warnings, crbug.com/554200
+ "/wd4312",
+
+ # C4324 warns when padding is added to fulfill alignas requirements,
+ # but can trigger in benign cases that are difficult to individually
+ # suppress.
+ "/wd4324",
+
+ # C4351: new behavior: elements of array 'array' will be default
+ # initialized
+ # This is a silly "warning" that basically just alerts you that the
+ # compiler is going to actually follow the language spec like it's
+ # supposed to, instead of not following it like old buggy versions did.
+ # There's absolutely no reason to turn this on.
+ "/wd4351",
+
+ # C4355: 'this': used in base member initializer list
+ # It's commonly useful to pass |this| to objects in a class' initializer
+ # list. While this warning can catch real bugs, most of the time the
+ # constructors in question don't attempt to call methods on the passed-in
+ # pointer (until later), and annotating every legit usage of this is
+ # simply more hassle than the warning is worth.
+ "/wd4355",
+
+ # C4503: 'identifier': decorated name length exceeded, name was
+ # truncated
+ # This only means that some long error messages might have truncated
+ # identifiers in the presence of lots of templates. It has no effect on
+ # program correctness and there's no real reason to waste time trying to
+ # prevent it.
+ "/wd4503",
+
+ # Warning C4589 says: "Constructor of abstract class ignores
+ # initializer for virtual base class." Disable this warning because it
+ # is flaky in VS 2015 RTM. It triggers on compiler generated
+ # copy-constructors in some cases.
+ "/wd4589",
+
+ # C4611: interaction between 'function' and C++ object destruction is
+ # non-portable
+ # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
+ # suggests using exceptions instead of setjmp/longjmp for C++, but
+ # Chromium code compiles without exception support. We therefore have to
+ # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
+ # have to turn off this warning (and be careful about how object
+ # destruction happens in such cases).
+ "/wd4611",
+
+ # Warnings to evaluate and possibly fix/reenable later:
+
+ "/wd4100", # Unreferenced formal function parameter.
+ "/wd4121", # Alignment of a member was sensitive to packing.
+ "/wd4244", # Conversion: possible loss of data.
+ "/wd4505", # Unreferenced local function has been removed.
+ "/wd4510", # Default constructor could not be generated.
+ "/wd4512", # Assignment operator could not be generated.
+ "/wd4610", # Class can never be instantiated, constructor required.
+ "/wd4838", # Narrowing conversion. Doesn't seem to be very useful.
+ "/wd4995", # 'X': name was marked as #pragma deprecated
+ "/wd4996", # Deprecated function warning.
+
+ # These are variable shadowing warnings that are new in VS2015. We
+ # should work through these at some point -- they may be removed from
+ # the RTM release in the /W4 set.
+ "/wd4456",
+ "/wd4457",
+ "/wd4458",
+ "/wd4459",
+
+ # All of our compilers support the extensions below.
+ "/wd4200", # nonstandard extension used: zero-sized array in
+ # struct/union
+ "/wd4201", # nonstandard extension used: nameless struct/union
+ "/wd4204", # nonstandard extension used : non-constant aggregate
+ # initializer
+
+ "/wd4221", # nonstandard extension used : 'identifier' : cannot be
+ # initialized using address of automatic variable
+
+ # http://crbug.com/588506 - Conversion suppressions waiting on Clang
+ # -Wconversion.
+ "/wd4245", # 'conversion' : conversion from 'type1' to 'type2',
+ # signed/unsigned mismatch
+
+ "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss
+ # of
+ # data
+
+ "/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
+ "/wd4389", # 'operator' : signed/unsigned mismatch
+
+ "/wd4702", # unreachable code
+
+ # http://crbug.com/848979 - MSVC is more conservative than Clang with
+ # regards to variables initialized and consumed in different branches.
+ "/wd4701", # Potentially uninitialized local variable 'name' used
+ "/wd4703", # Potentially uninitialized local pointer variable 'name'
+ # used
+
+ # http://crbug.com/848979 - Remaining Clang permitted warnings.
+ "/wd4661", # 'identifier' : no suitable definition provided for
+ # explicit
+ # template instantiation request
+
+ "/wd4706", # assignment within conditional expression
+ # MSVC is stricter and requires a boolean expression.
+
+ "/wd4715", # 'function' : not all control paths return a value'
+ # MSVC does not analyze switch (enum) for completeness.
+ ]
+
+ cflags_cc += [
+ # Allow "noexcept" annotations even though we compile with exceptions
+ # disabled.
+ "/wd4577",
+ ]
+
+ if (current_cpu == "x86") {
+ cflags += [
+ # VC++ 2015 changes 32-bit size_t truncation warnings from 4244 to
+ # 4267. Example: short TruncTest(size_t x) { return x; }
+ # Since we disable 4244 we need to disable 4267 during migration.
+ # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
+ "/wd4267",
+ ]
+
+ if (msvc_use_sse2) {
+ cflags += [ "/arch:SSE2" ]
+ }
+ }
}
}