summaryrefslogtreecommitdiff
path: root/AK/Checked.h
AgeCommit message (Collapse)Author
2022-12-19AK: Use __has_builtin() in Checked.hAndreas Kling
Instead of avoiding overflow-checking builtins with AK_COMPILER_CLANG, we can use the preprocessor's __has_builtin() mechanism to check if they are available.
2022-12-11AK: Add support for modulo to Checked<T>Ali Mohammad Pur
This is used by the Jakt runtime.
2022-12-11AK: Add a Checked::unchecked_value() functionAli Mohammad Pur
This is used in Jakt.
2022-11-26AK: Make it possible to not `using` AK classes into the global namespaceAndreas Kling
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by default, but can be overridden by build flags. This is a step towards integrating Jakt and AK types.
2022-10-04AK+Everywhere: Add AK_COMPILER_{GCC,CLANG} and use them most placesNico Weber
Doesn't use them in libc headers so that those don't have to pull in AK/Platform.h. AK_COMPILER_GCC is set _only_ for gcc, not for clang too. (__GNUC__ is defined in clang builds as well.) Using AK_COMPILER_GCC simplifies things some. AK_COMPILER_CLANG isn't as much of a win, other than that it's consistent with AK_COMPILER_GCC.
2022-06-23AK: Add saturating addition and subtraction to Checkedkleines Filmröllchen
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2021-11-14AK: Resolve clang-tidy warnings about unusual assignment operatorsAndrew Kaster
Either not returning *this, or in the case of Variant, not checking for self assignment. In AK::Atomic, we can't return *this due to the wrapper semantics Atomic implements.
2021-07-22AK: Make TypeBoundsChecker<UnsignedIntegralT, FloatingPointT> workLinus Groh
By replacing MakeUnsigned<Source> in this specific specialization with a simple negativity check this now works for floating point source types. Previously it would attempt a comparison of the destination type and void.
2021-07-04AK: Explicitly require Checked types to be IntegralIdan Horowitz
These were already implicitly required to be integral via the usage of the is_within_range templated function, but making them explicit should produce nicer error messages when building, and make the IDE highlight the incorrect usage.
2021-06-02AK: Make checked division also check for divide by zeroAli Mohammad Pur
2021-05-07AK: Make Checked<T> check for division overflow as wellAli Mohammad Pur
Signed integer overflow can occur with division when the RHS is -1, as the negative values' range is one larger than the positives.
2021-04-11AK: Annotate Checked functions with [[nodiscard]]Brian Gianforcaro
2021-03-13AK: Add decrement operator to CheckedTom
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-01-30AK: Allow Checked += Checked, and other such operationsAndreas Kling
The overflow state from both Checkeds is OR'ed in the result.
2020-10-20Everywhere: Redundant inline specifier on constexpr functions (#3807)Lenny Maiorani
Problem: - `constexpr` functions are decorated with the `inline` specifier keyword. This is redundant because `constexpr` functions are implicitly `inline`. - [dcl.constexpr], §7.1.5/2 in the C++11 standard): "constexpr functions and constexpr constructors are implicitly inline (7.1.2)". Solution: - Remove the redundant `inline` keyword.
2020-10-20Checked: constexpr supportLenny Maiorani
Problem: - `Checked` is not `constexpr`-aware. Solution: - Decorate member functions with `constexpr` keyword. - Add tests to ensure the functionality where possible.
2020-10-20Checked: Use default compiler-generated functionsLenny Maiorani
Problem: - Compiler-generated functions are being defined which results in extra code to maintain. Solution: - Switch to compiler-generated default functions for default construction, copy assignment, move assignment, copy construction and move construction.
2020-08-26AK: Demonstrate and fix CheckedBen Wiederhake
Specifically: - post-increment actually implemented pre-increment - helper-templates that provided operator{+,-,*,/}() couldn't possibly work, because the interface of add (etc) were incompatible (not taking a Checked<>, and returning void)
2020-05-31AK: Always inline some Checked methodsSergey Bugaev
Once again, we need to hint the compiler that it should inline the function, and then it is able to eliminate the assertion.
2020-05-20AK: Fix Checked::multiplication_would_overflow() signatureSergey Bugaev
The two-argument version doesn't need an extra template parameter.
2020-05-01AK: Make Checked.h work with ClangAndreas Kling
Apparently Clang does not have __builtin_foo_overflow_p() Fixes #2044.
2020-04-30AK: Add Checked::addition_would_overflow()Sergey Bugaev
And switch the two-argument version of Checked::multiplication_would_overflow() to use __builtin_mul_overflow_p(). This helps GCC optimize the code better.
2020-04-15AK: Add Checked<T>::multiplication_would_overflow()Andreas Kling
This allows you to comfortably test if multiply 2 or 3 values would cause arithmetic overflow.
2020-04-15AK: Add a Checked<T> templateAndreas Kling
A Checked<T> is a boxed integer type that asserts if you try to use its value after an arithmetic overflow.