[all-commits] [llvm/llvm-project] 091a9f: [libc++][test] Avoid truncation warnings from `dou...
Stephan T. Lavavej via All-commits
all-commits at lists.llvm.org
Sat Dec 2 17:40:56 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 091a9f4957b9bed08e6c1c89eacc90a07d4bb603
https://github.com/llvm/llvm-project/commit/091a9f4957b9bed08e6c1c89eacc90a07d4bb603
Author: Stephan T. Lavavej <stl at nuwen.net>
Date: 2023-12-02 (Sat, 02 Dec 2023)
Changed paths:
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/assign.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/compare_exchange_strong.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/compare_exchange_weak.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/exchange.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/fetch_add.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/fetch_sub.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/load.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/notify_all.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/notify_one.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/operator.float.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/operator.minus_equals.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/operator.plus_equals.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/store.pass.cpp
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/test_helper.h
M libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/wait.pass.cpp
Log Message:
-----------
[libc++][test] Avoid truncation warnings from `double` to `float` (#74184)
Found while running libc++'s test suite with MSVC's STL, where we use
both MSVC's compiler and Clang/LLVM.
MSVC really enjoys emitting "warning C4305: 'initializing': truncation
from 'double' to 'float'". It might look repetitive, but `T(value)`
avoids this warning. (According to my understanding, the compiler looks
at the immediate context, and if it's a functional-style cast, it's
satisfied that the truncation was intentional. Not even the
direct-initialization context of `T unexpected(-9999.99)` is enough to
activate that "ok, the programmer knows what they're getting" codepath.)
I usually prefer to use `static_cast` instead of functional-style casts,
but I chose to remain consistent with the surrounding code.
By the way, you might notice that `1.5` doesn't need these changes. This
is because it's exactly representable as both a `double` and a `float`.
Values like `3.125` instead of `3.1` would similarly avoid truncation
warnings without the need for casts, but I didn't want to intrusively
change the test code.
More information about the All-commits
mailing list