-
-
Notifications
You must be signed in to change notification settings - Fork 55
Issue 2282: PatternLanuage changes: [Bug] Crash when hovering on a static array #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shewitt-au
wants to merge
51
commits into
WerWolv:master
Choose a base branch
from
shewitt-au:issue-2282
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
e85418b
issue-2282: PL changes
shewitt-au bbace8d
Remove debugging code
shewitt-au 9d63054
Hard to get every one. time...
shewitt-au db3c947
Hard to get every one
shewitt-au 1b5c8f6
WIP
shewitt-au e1b869d
WIP
shewitt-au fdf3df4
WIP
shewitt-au ad24e44
WIP
shewitt-au c004860
WIP
shewitt-au b2606d8
WIP
shewitt-au 1214cd8
WIP
shewitt-au 4295ce6
WIP
shewitt-au 5e0b38b
WIP
shewitt-au ab9a3a9
WIP
shewitt-au f7d6fc0
WIP
shewitt-au 2ac6ba9
WIP
shewitt-au c5496e1
WIP
shewitt-au 29be2d2
WIP
shewitt-au 4e07ab2
Taking a slightly different approach
shewitt-au 8ea5dc4
Add 'construct_shared_object.hpp'
shewitt-au 324a136
WIP
shewitt-au 3ec6ae2
WIP
shewitt-au 9489b3c
It builds
shewitt-au c6095e6
Change comment
shewitt-au 830d0ee
fix: post_construct not being called on some compilers
shewitt-au ce784c4
Attempt and strange problem casuing build isssues
shewitt-au 32037d1
Attempt and strange problem casuing build isssues
shewitt-au 8a008a2
Attempt and strange problem casuing build isssues
shewitt-au 7c0884b
Replace more make_shared calls
shewitt-au a47cc5f
Work on unit tests
shewitt-au e1fd97a
Work on unit tests
shewitt-au b17db3f
Work on unit tests
shewitt-au 093a4e1
Work on unit tests
shewitt-au c40fbe3
Work on unit tests
shewitt-au ab43e67
Work on unit tests
shewitt-au bb5bc62
Work on unit tests
shewitt-au 36deb13
Fixing tests
shewitt-au 3eb2833
Fixing tests
shewitt-au cab951b
Fixing tests
shewitt-au 8e82fdd
Fixing tests
shewitt-au 6173dfc
Fixing tests
shewitt-au 21fa172
Make all patterns I could find have protected constructors
shewitt-au 3291051
Change static cast to dynamic
shewitt-au 29b7486
Moved friend declations to end of class
shewitt-au c308e82
New allocation method (WIP)
shewitt-au 1fd2401
It's looking like it may actually buid. We'll soon know
shewitt-au e380aeb
Last claims premature
shewitt-au aaae498
Move stuff around
shewitt-au 9694a1c
New allocation method. Other small changes
shewitt-au 13ec0b8
Renamed some stuff
shewitt-au cbd3f62
Renamed some stuff
shewitt-au File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// construct_shared_object.hpp | ||
// | ||
// Written by Stephen Hewitt in 2025 | ||
// GitHub repo: https://github.com/shewitt-au/std-enable_shared_from_this-and-constructors | ||
|
||
#pragma once | ||
/* | ||
The motivation for this code is issues with std::shared_ptr and | ||
std::enable_shared_from_this. | ||
|
||
Consider code like this: | ||
std::shared<SomeClass> ptr = std::make_shared<SomeClass>(); | ||
|
||
Assume that SomeClass's constructor uses shared_from_this. In this case, since | ||
SomeClass is not yet owned by a std::shared_ptr, the shared_from_this call will | ||
not work as expected. There seems to no way around this that I can find. | ||
I wasn't aware of this issue. It was a real kick in the pants. | ||
|
||
The solution implemented here is two-stage construction. First the object is | ||
constructed and assigned to a std::shared_ptr; then, if present, a | ||
post_construct method is called with the same arguments. All code that uses | ||
shared_from_this in the constructors should be moved to a post_construct method. | ||
The intent of the "if present" is to enable incremental migration to two-stage | ||
construction on demand. | ||
|
||
Another issue addressed is with std::make_shared. This function requires that | ||
the constructor be public. If we're making factory methods for creation, we may | ||
want to make the constructors non-public to stop misuse. The solution to this | ||
problem I can't take credit for. | ||
|
||
The code for safe_enable_shared_from_this is based on code found here: | ||
https://stackoverflow.com/questions/8147027/how-do-i-call-stdmake-shared-on-a-class-with-only-protected-or-private-const | ||
Posted by stackoverflow member Carsten. | ||
He adapted old code from stackoverflow member Zsolt Rizsányi, | ||
who in turn says it was invented by Jonathan Wakely (GCC developer). | ||
|
||
I have made minor modifications to suit and added comments. | ||
|
||
Requires C++23 | ||
*/ | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
// Used to enable construct_shared_object to access non-public constructors. | ||
#define BEFRIEND_CONSTRUCT_SHARED_OBJECT(T) \ | ||
friend struct shared_object_creator::safe_enable_shared_from_this::Allocator<T>; | ||
|
||
namespace shared_object_creator { | ||
|
||
// safe_enable_shared_from_this was found here: | ||
// https://stackoverflow.com/questions/8147027/how-do-i-call-stdmake-shared-on-a-class-with-only-protected-or-private-const | ||
// | ||
// Posted by stackoverflow member Carsten. | ||
// He adapted old code from stackoverflow member Zsolt Rizsányi, | ||
// who in turn says it was invented by Jonathan Wakely (GCC developer). | ||
class safe_enable_shared_from_this : public std::enable_shared_from_this<safe_enable_shared_from_this> { | ||
// Our friends. They're not from around here and have long hard to pronounce names. | ||
template<typename T, typename... Args> | ||
requires requires(T t, Args&&... args) { | ||
t.post_construct(std::forward<Args>(args)...); | ||
} | ||
friend std::shared_ptr<T> construct_shared_object(Args&&... args); | ||
|
||
template<typename T, typename... Args> | ||
friend std::shared_ptr<T> construct_shared_object(Args&&... args); | ||
|
||
public: | ||
virtual ~safe_enable_shared_from_this() noexcept = default; | ||
|
||
// The next two functions use C++23's "explicit object parameter" | ||
// syntax to make shared_from_this and weak_from_this, when called | ||
// from derived classes, return a std::shared_ptr<T> with T being | ||
// the derived type. | ||
template <typename TSelf> | ||
auto inline shared_from_this(this TSelf&& self) noexcept | ||
{ | ||
return std::static_pointer_cast<std::remove_reference_t<TSelf>>( | ||
std::forward<TSelf>(self).std::template enable_shared_from_this<safe_enable_shared_from_this>::shared_from_this()); | ||
} | ||
|
||
template <typename TSelf> | ||
auto inline weak_from_this(this TSelf&& self) noexcept -> ::std::weak_ptr<std::remove_reference_t<TSelf>> | ||
{ | ||
return std::static_pointer_cast<std::remove_reference_t<TSelf>>( | ||
std::forward<TSelf>(self).std::template enable_shared_from_this<safe_enable_shared_from_this>::weak_from_this().lock()); | ||
shewitt-au marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
protected: | ||
safe_enable_shared_from_this() noexcept = default; | ||
safe_enable_shared_from_this(safe_enable_shared_from_this&&) noexcept = default; | ||
safe_enable_shared_from_this(const safe_enable_shared_from_this&) noexcept = default; | ||
safe_enable_shared_from_this& operator=(safe_enable_shared_from_this&&) noexcept = default; | ||
safe_enable_shared_from_this& operator=(const safe_enable_shared_from_this&) noexcept = delete; | ||
|
||
template <typename T> | ||
struct Allocator : public std::allocator<T> | ||
{ | ||
template<typename TParent, typename... TArgs> | ||
void construct(TParent* parent, TArgs&&... args) | ||
{ ::new((void *)parent) TParent(std::forward<TArgs>(args)...); } | ||
}; | ||
|
||
private: | ||
// std::allocate_share, like std::make_shared, allocates both the object | ||
// and the control block using only a single allocation. | ||
template <typename T, typename... TArgs> | ||
static inline auto create(TArgs&&... args) -> std::shared_ptr<T> { | ||
return std::allocate_shared<T>(Allocator<T>{}, std::forward<TArgs>(args)...); | ||
} | ||
}; | ||
|
||
// The actual creation functions. | ||
|
||
template<typename T, typename... Args> | ||
requires requires(T t, Args&&... args) { | ||
t.post_construct(std::forward<Args>(args)...); | ||
} | ||
std::shared_ptr<T> construct_shared_object(Args&&... args) { | ||
auto p = safe_enable_shared_from_this::create<T>(std::forward<Args>(args)...); | ||
p->post_construct(std::forward<Args>(args)...); | ||
return p; | ||
} | ||
|
||
template<typename T, typename... Args> | ||
std::shared_ptr<T> construct_shared_object(Args&&... args) { | ||
return safe_enable_shared_from_this::create<T>(std::forward<Args>(args)...); | ||
} | ||
|
||
} // namespace shared_object_creator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.