mirror of
https://github.com/MariaDB/server.git
synced 2025-02-19 03:45:35 +01:00
![]() ### Preamble C++ initializes objects in three stages: 1. Optionally, zero-initializes the object fields. 2. Member-initializes fields that are explicitly set. 3. If applicable, calls a constructor. The following expressions: x = new T[N]; x = new T; T x; only member-initialize and call a default constructor. Stage 1 is skipped, because () braces are omitted. This is known as default-initialization. Apart from Stage 2, the following: x = new T[N](); x = new T(); const T &x = T(); Is known as value-initialization: If no default constructor is present, infer zero-initialization. Otherwise, the default constructor is called. Note that it's not possible to write `T x();`, as it is ambiguous to a function call. Since C++11, it's also possible to zero initialize objects with '{}' braces: x = new T[N]{}; x = new T{}; T x{}; This also both zero-initializes and calls a default constructor. There is no much difference in between empty-braced () and {}. Both call a default constructor or initializer-list constructor, when available. Having both constructors is ambiguous. Scalars (i.e. fundamental data types) and POD types have no constructor. Therefore, stage 2 for them is skipped. Other than that, there is no much difference in the result Exambles: new char[123] -- would return an uninitialized array of char. new char[123]() -- forces zero-initialization new char[123]{} -- forces zero-initialization new char[123]{123} -- forces zero-initialization, and also value-initializes the first element to 123 struct A { int x = 0xaf; int y; } All of the following: A a; A *a = new A; A *a = new A[123]; Causes member A::x be initialized to 0xaf, since it happens at value-initialization stage. A::y is left uninitialized. A *a = new A[123] {}; and other similars result in {.x=0xaf, .y=0}. ### In this commit Change all the calls to thd->calloc() to new(thd) T[N]{}, or new(thd) T{}. POD types will be zero-initialized, so a special attention should be put to classes with default constructors. Among all uses, two cases of interest were found: 1. TABLE_LIST: has a default constructor TABLE_LIST() = default. This infers zero-initialization behavior (i.e. as if there's no constructor). 2. USER_AUTH: has a default constructor, that initializes all fields. Strings are initialized to "", which is fine. 3. Security_context: had a custom default constructor, initializing only two fields. It was removed, and fields are made member-initialized. |
||
---|---|---|
.. | ||
mysql-test/storage_engine | ||
CMakeLists.txt | ||
ha_myisammrg.cc | ||
ha_myisammrg.h | ||
myrg_close.c | ||
myrg_create.c | ||
myrg_def.h | ||
myrg_delete.c | ||
myrg_extra.c | ||
myrg_info.c | ||
myrg_locking.c | ||
myrg_open.c | ||
myrg_panic.c | ||
myrg_queue.c | ||
myrg_range.c | ||
myrg_records.c | ||
myrg_rfirst.c | ||
myrg_rkey.c | ||
myrg_rlast.c | ||
myrg_rnext.c | ||
myrg_rnext_same.c | ||
myrg_rprev.c | ||
myrg_rrnd.c | ||
myrg_rsame.c | ||
myrg_static.c | ||
myrg_update.c | ||
myrg_write.c |