Date: Tue, 22 Jul 2025 14:15:45 +0100
On Tue, Jul 22, 2025 at 1:38 PM Jan Schultke wrote:
>
> Another way to use the c_str() member function you've mentioned,
> without involving a variable would be:
>
> > void f(const char*);
> > wxString mystr( wxS("Hello I'm a monkey") );
> > f(mystr.c_str());
We want an attribute to express the following:
"The object returned from this function can generate handles that
become invalid when the object is destroyed (i.e. the generated handle
does not out-live the object). Therefore, if you use the returned
object to generate a handle, then you must ensure that the object is
still in existence when the handle is used. To ensure this, either (a)
store the object in a local variable, or (b) use any generated handles
before the full expression is evaluated.".
I think we would need a pair of attributes to make this work. For
instance 'wxString' would need a method marked as 'must_store':
struct wxString {
[[must_store]] wxCStr c_str(void) const;
};
And the the class 'wxCStr' would need to mark a method to indicate
that it generates a handle that does not out-live the object:
struct wxCStr {
[[generates_temporary_handle]] operator wchar_t const *(void) const;
};
Actually on second thought, if "wxCStr::operator wchar_t*" is marked
as [[generates_temporary_handle]], then maybe "wxString::c_str"
doesn't need to be marked at all. Actually I think the marking in the
'wxCStr' class is enough.
So forget about [[must_store]]. Instead I'd like to propose
[[generates_temporary_handle]].
>
> Another way to use the c_str() member function you've mentioned,
> without involving a variable would be:
>
> > void f(const char*);
> > wxString mystr( wxS("Hello I'm a monkey") );
> > f(mystr.c_str());
We want an attribute to express the following:
"The object returned from this function can generate handles that
become invalid when the object is destroyed (i.e. the generated handle
does not out-live the object). Therefore, if you use the returned
object to generate a handle, then you must ensure that the object is
still in existence when the handle is used. To ensure this, either (a)
store the object in a local variable, or (b) use any generated handles
before the full expression is evaluated.".
I think we would need a pair of attributes to make this work. For
instance 'wxString' would need a method marked as 'must_store':
struct wxString {
[[must_store]] wxCStr c_str(void) const;
};
And the the class 'wxCStr' would need to mark a method to indicate
that it generates a handle that does not out-live the object:
struct wxCStr {
[[generates_temporary_handle]] operator wchar_t const *(void) const;
};
Actually on second thought, if "wxCStr::operator wchar_t*" is marked
as [[generates_temporary_handle]], then maybe "wxString::c_str"
doesn't need to be marked at all. Actually I think the marking in the
'wxCStr' class is enough.
So forget about [[must_store]]. Instead I'd like to propose
[[generates_temporary_handle]].
Received on 2025-07-22 13:15:59