summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-11-25 11:06:00 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-11-25 14:08:20 +0100
commitb1404b5919f8c18bde715f68b229d2c030de5b2a (patch)
treed82079af2daf693364aca6c111d9dcbecbaba12c /include
parent69372bf111c0a85e754d72248bcd22b455f11938 (diff)
-Wc++11-narrowing (clang-cl)
MSVC seems not to mind, but a Windows 64-bit build with clang-cl fails with "error: non-constant-expression cannot be narrowed from type 'tools::Long' (aka 'long long') to 'LONG' (aka 'long') in initializer list". But adding explicit casts would have the downside of preventing tools like -fsanitize=implict-conversion (if we ever use that on Windows) from detecting truncation, so introduce o3tl::narrowing. Change-Id: Ia33a9ae4d8134b5ad0c8b7cf6812fbdd625ca89e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106577 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/o3tl/safeint.hxx5
1 files changed, 5 insertions, 0 deletions
diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 6d8d1304fdf3..a5c212244c7c 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -234,6 +234,11 @@ make_unsigned(T value)
return value;
}
+// An implicit conversion from T2 to T1, useful in places where an explicit conversion from T2 to
+// T1 is needed (e.g., in list initialization, if the implicit conversion would be narrowing) but
+// tools like -fsanitize=implict-conversion should still be able to detect truncation:
+template<typename T1, typename T2> constexpr T1 narrowing(T2 value) { return value; }
+
}
#endif