diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2025-07-01 12:44:04 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2025-07-07 21:50:50 +0100 |
commit | 5ca5e1d54f237770ef5f32ff20c69711f720551c (patch) | |
tree | 38e1afb098ae48377bcf1602d2b2f47cd5d5fc6c /libjava/classpath/lib/java/sql | |
parent | 9450fb705caca3df0f968e66768eec6e38458a9f (diff) | |
download | gcc-5ca5e1d54f237770ef5f32ff20c69711f720551c.zip gcc-5ca5e1d54f237770ef5f32ff20c69711f720551c.tar.gz gcc-5ca5e1d54f237770ef5f32ff20c69711f720551c.tar.bz2 |
libstdc++: Make VERIFY a variadic macro
This defines the testsuite assertion macro VERIFY so that it allows
un-parenthesized expressions containing commas. This matches how assert
is defined in C++26, following the approval of P2264R7.
The primary motivation is to allow expressions that the preprocessor
splits into multiple arguments, e.g.
VERIFY( vec == std::vector<int>{1,2,3,4} );
To achieve this, VERIFY is redefined as a variadic macro and then the
arguments are grouped together again through the use of __VA_ARGS__.
The implementation is complex due to the following points:
- The arguments __VA_ARGS__ are contextually-converted to bool, so that
scoped enums and types that are not contextually convertible to bool
cannot be used with VERIFY.
- bool(__VA_ARGS__) is used so that multiple arguments (i.e. those which
are separated by top-level commas) are ill-formed. Nested commas are
allowed, but likely mistakes such as VERIFY( cond, "some string" ) are
ill-formed.
- The bool(__VA_ARGS__) expression needs to be unevaluated, so that we
don't evaluate __VA_ARGS__ more than once. The simplest way to do that
would be just sizeof bool(__VA_ARGS__), without parentheses to avoid a
vexing parse for VERIFY(bool(i)). However that wouldn't work for e.g.
VERIFY( []{ return true; }() ), because lambda expressions are not
allowed in unevaluated contexts until C++20. So we use another
conditional expression with bool(__VA_ARGS__) as the unevaluated
operand.
libstdc++-v3/ChangeLog:
* testsuite/util/testsuite_hooks.h (VERIFY): Define as variadic
macro.
* testsuite/ext/verify_neg.cc: New test.
Reviewed-by: Tomasz KamiĆski <tkaminsk@redhat.com>
Diffstat (limited to 'libjava/classpath/lib/java/sql')
0 files changed, 0 insertions, 0 deletions