Commit graph

13 commits

Author SHA1 Message Date
Tom 8a8bdb2cd7 AK: Add decrement operator to Checked 2021-03-13 10:17:28 +01:00
Andreas Kling 5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...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-02-23 20:56:54 +01:00
Andreas Kling dc17e01c99 AK: Allow Checked += Checked, and other such operations
The overflow state from both Checkeds is OR'ed in the result.
2021-01-30 13:52:12 +01:00
Lenny Maiorani d1fe6a0b53
Everywhere: Redundant inline specifier on constexpr functions (#3807)
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-20 18:08:13 +02:00
Lenny Maiorani a40abd6ce3 Checked: constexpr support
Problem:
- `Checked` is not `constexpr`-aware.

Solution:
- Decorate member functions with `constexpr` keyword.
- Add tests to ensure the functionality where possible.
2020-10-20 16:31:24 +02:00
Lenny Maiorani bd99083436 Checked: Use default compiler-generated functions
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-10-20 16:31:24 +02:00
Ben Wiederhake 0e27a6e39e AK: Demonstrate and fix Checked
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-08-26 00:55:13 +02:00
Sergey Bugaev c3db694d9b AK: Always inline some Checked methods
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-31 21:38:50 +02:00
Sergey Bugaev 000a9cad34 AK: Fix Checked::multiplication_would_overflow() signature
The two-argument version doesn't need an extra template parameter.
2020-05-20 08:31:31 +02:00
Andreas Kling ea839861e5 AK: Make Checked.h work with Clang
Apparently Clang does not have __builtin_foo_overflow_p()

Fixes #2044.
2020-05-01 17:30:47 +02:00
Sergey Bugaev 361a1b54d7 AK: Add Checked::addition_would_overflow()
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-30 11:30:27 +02:00
Andreas Kling 63b8c6913c AK: Add Checked<T>::multiplication_would_overflow()
This allows you to comfortably test if multiply 2 or 3 values would
cause arithmetic overflow.
2020-04-15 17:14:18 +02:00
Andreas Kling 9c54bad241 AK: Add a Checked<T> template
A Checked<T> is a boxed integer type that asserts if you try to use its
value after an arithmetic overflow.
2020-04-15 16:58:46 +02:00