Commit graph

755 commits

Author SHA1 Message Date
Nicholas Wilson
a6ad856d51
Fix self assignment for https://github.com/dlang/dmd/pull/20696 2025-01-14 06:05:25 +08:00
Martin Kinkelin
b0ef9ac009 Merge remote-tracking branch 'origin/stable' into merge_stable 2024-11-17 01:17:07 +01:00
Vladiwostok
354781f229
Fix UndocumentedDeclarationCheck linting issue in typecons.d (#9075) 2024-10-27 16:37:36 -07:00
Vladiwostok
231ae8b68a
Fix D-Scanner linting issues (#9070)
* Fix UndocumentedDeclarationCheck linting issue

* Fix IfConstraintsIndentCheck linting issue

* Address feedback

* Fix publictests CI

* Fix old (libdparse) D-Scanner linting warn
2024-10-27 01:21:56 -07:00
Jonathan M Davis
f0c3e4a66b
Fix Bugzilla issue 24827: maxElement does not handle opAssign correctly. (#9067)
Rebindable2 did not handle types with opAssign correctly, which affected
both minElement and maxElement. Namely, Rebindable2 assigned to memory
which was not properly initialized when the correct solution in such a
situation is to use copyEmplace. Assignment works when assignment is
just a memcpy, but in the general case, opAssign needs to have a
properly initialized object in order to work correctly. copyEmplace
instead copies the object and then places the copy into the unitialized
memory, so it avoids assigning to uninitialized memory.

This commit also adds additional tests for types with destructors (which
do get opAssign automatically) and types with postblit constructors or
copy constructors to try to ensure that the code is doing the correct
thing in those cases with regards to copying, assignment, and
destruction.

https://issues.dlang.org/show_bug.cgi?id=24829 was found in the process,
and this does not fix that. Namely, types which cannot be assigned to
and which also have a postblit constructor or copy constructor do not
get copied correctly. So, among the tests added here are commented out
tests for that case, since they're an altered version of some of the
enabled tests. However, fixing that issue would be involved enough that
I'm not attempting to fix it at this time.
2024-10-27 01:16:22 -07:00
Paul Backus
ebd24da8ad
Fix Bugzilla 22293: opCast!bool for Nullable (#9039)
The second opCast overload is necessary to allow built-in implicit
conversions (e.g., mutable to const) to be performed explicitly via a
cast expression. Nullable.opEquals depends on this behavior.
2024-08-01 17:09:38 +08:00
Nick Treleaven
9ffe71fea3
Fix Bugzilla 15315 - can break immutable with std.algorithm.move (#9032) 2024-07-29 06:49:54 +08:00
FeepingCreature
539dc473ba
Fix bugzilla issue 24596: std.typecons.Rebindable2: Don't destroy classes! Only destroy structs! (#9012) 2024-06-10 23:10:18 +08:00
Iain Buclaw
045b632950 Merge remote-tracking branch 'upstream/stable' into merge_stable 2024-04-01 20:59:13 +00:00
Jonathan M Davis
7858069343 Fix bugzilla #24465: Make Tuple work with copy constructors
If there's a constructor that looks like a copy constructor except that
it takes an rvalue instead of taking the argument by ref, then that type
can't have a copy constructor, and one of Tuple's constructors was
causing that problem. So, this fixes it so that it doesn't.
2024-04-01 20:15:25 +02:00
Walter Bright
1591ce9fe7 swap-and-destroy called too eagerly 2024-03-18 09:24:00 -07:00
Jonathan M Davis
115b7f61a9 fix Bugzilla Issue 24403 - Nullable doesn't work with non-mutable types with a destructor
This should make it so that a variable of type Nullable!T has the same
behavior with regards to destruction as a variable of type T even when
it's const, immutable, or shared.
2024-02-21 19:06:29 +08:00
Vladimir Panteleev
73a54e2fab std.typecons: Support non-copyable types
Fixes issue 24318.
2024-01-05 07:38:16 +08:00
Vladimir Panteleev
826b00ff58 std.typecons: Avoid a copy in Nullable.opAssign
Use `move` directly.
2024-01-05 07:38:16 +08:00
Vladimir Panteleev
bc2ad75289 std.typecons: Allow calling destructor on default value in unittest
Generally, if a type has a default value, it should be safe to assume
that it's OK to call the destructor on a default-initialized variable.

The converse is not compatible with `move`, and goes against
implementing non-copyable types.
2024-01-05 07:38:16 +08:00
Vladimir Panteleev
03a961d5a5 std.typecons: Refactor a unit test for clarity 2024-01-05 07:38:16 +08:00
Mathis Beer
10601cc046 Add std.typecons.Rebindable2 for internal use.
Rebindable2 is a simplified version of std.typecons.Rebindable that clears up every special case: classes, arrays and structs now have the same struct.
Whichever type you instantiate `Rebindable2` with, you always get the same type out by calling `value.get` on the resulting container.
Also use this type to simplify the parts of Phobos we previously used `Rebindable` for.
2023-06-19 13:24:30 +02:00
Johan Engelen
75a507f883
typecons: fix use-after-scope bug in RefCounted unittest (#8751)
* typecons: fix use-after-scope bug in RefCounted unittest

The access through `p` to `rc1` outside the scope of `rc1` is undefined behavior. We have to artificially end the scope of `rc1` and `rc2`, such that within the same scope we can check that the destructor calls do the correct thing of nulling the `_store`.

* fixup

* fixup
2023-05-29 16:00:15 +03:00
Mathis Beer
2f6b2efaf7 Change struct Rebindable to just use cast() if this is sufficient.
This works better at compiletime.
2023-04-19 22:59:43 +00:00
FeepingCreature
c26d25eecd
Implement Rebindable for non-class/non-array types. (#8722)
Note that you cannot access a reference to the contained value in struct Rebindable.
2023-04-18 11:33:17 +03:00
Mathis Beer
19eaf8a1bd Fix issue 23640: Use Nullable[] to allow iterating Nullable of immutable type. 2023-01-19 12:20:06 +01:00
Nick Treleaven
fdab7cdef9 Remove unnecessary @trusted 2022-12-24 13:07:22 +00:00
Nick Treleaven
c27f250eb5 Tweak 2 tests 2022-12-24 13:06:37 +00:00
Nick Treleaven
d5c1067131
Fix Issue 23561 - std.typecons.Unique!struct does not destroy struct … (#8651)
Fix Issue 23561 - std.typecons.Unique!struct does not destroy struct …

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
Signed-off-by: Razvan Nitu <razvan.nitu1305@gmail.com>
Merged-on-behalf-of: Razvan Nitu <razvan.nitu1305@gmail.com>
2022-12-24 13:40:54 +01:00
Walter Bright
2c7e732236 replace isImplicitlyConvertible with is expression 2022-12-01 00:52:55 -08:00
Lucian Danescu
322fed7bf7 add local imports 2022-11-12 19:29:28 +02:00
Lucian Danescu
cdee7e6939 remove redundant attributes in typecons.d 2022-11-04 21:52:10 +01:00
Mathias LANG
3c97810b36
Re-instate accidentally reverted fixes on RefCounted (#8599)
Those fixes were done in PR #8509 but PR #8368 accidentally reverted them.
2022-10-14 06:23:22 +08:00
Ate Eskola
bbd03c9351 Added the needed AliasSeq import to betterC tests. 2022-09-21 23:08:14 +03:00
Ate Eskola
d7b6838fc2 Took copies of most SafeRefCounted unit tests for RefCounted. 2022-09-17 19:48:05 +03:00
Ate Eskola
c277df5547 Applied suggested documentation fixes. 2022-09-17 18:57:22 +03:00
Ate Eskola
490caa7090 RefCounted -> SafeRefCounted, OldRefCounted -> RefCounted. 2022-09-11 01:35:35 +03:00
Ate Eskola
bb145a09a6 Ate's work on safe ref counted 2022-09-11 01:35:35 +03:00
Atila Neves
be598abbeb Atila's work on safe ref counted 2022-09-11 01:35:35 +03:00
Martin Nowak
85d0520220 Merge remote-tracking branch 'upstream/stable' into merge_stable 2022-09-10 15:23:06 +02:00
wolframw
7ce739c5ff
fix issue 23238 - Cannot write a const Nullable(T, T nullValue) 2022-08-26 00:15:55 +02:00
Walter Bright
056606ea56 get std.typecons to compile with PR #14364 2022-08-15 11:48:45 +00:00
Geod24
501a3ab35a std.typecons: Remove workaround for fixed issue 15862 2022-07-18 17:11:59 +02:00
Iain Buclaw
a9a504f406 Merge remote-tracking branch 'upstream/stable' into merge_stable 2022-07-09 17:08:41 +02:00
Razvan Nitu
7e0dbdf1a3
Merge pull request #8500 from RazvanN7/fix_scope_failure
Use try-catch instead of scope(failure) for block that returns
2022-07-07 16:08:38 +03:00
RazvanN7
52935b182a Use try-catch instead of scope(failure) for block that returns 2022-07-07 15:28:43 +03:00
Martin Kinkelin
b20444aca4 Use new __traits(classInstanceAlignment)
Tackling the Phobos part of issue 16508.
2022-05-13 18:38:09 +00:00
Hiroki Noda
5429908c4a Fix: add missing FunctionAttribute 2022-04-25 15:22:59 +00:00
Cameron Ross
90f65d49fb Add range interface to Nullable 2022-03-27 19:18:11 +00:00
Arne Ludwig
3a2cf7f3cb Fixed negation of BitFlags
- negation did not work with unsigned integers with dmd v2.099.0
- also made double negation of flags possible
2022-03-22 12:47:36 +00:00
Iain Buclaw
68ae00efbc Merge branch 'stable' into merge_stable 2022-02-11 22:11:48 +01:00
Mathis Beer
ac5c8d0c85 Fix issue 22701: Remove is(typeof()) callable check in std.typecons.apply.
It creates unreadable template errors for no benefit.
2022-01-26 13:03:29 +01:00
The Dlang Bot
a86c1eba9f
Merge pull request #6876 from thaven/enhancement/autoimplement-add-abstract-parent
Also expose 'parent' when it's abstract

Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com>
Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2022-01-18 03:54:04 +00:00
Martin Kinkelin
9db3a9afdf Work around issue 22619 - Avoid Nullable copy ctor unless required
Copy ctors are still buggy, so unconditionally adding one for Nullable
is everything but a non-breaking change (and was added in the 2.098.1
point release).
2022-01-10 16:48:29 +01:00
Nick Treleaven
9f336484dc [typecons] Tweak Tuple example and split out Rebindable example 2022-01-10 14:03:09 +00:00