On Fri, 1 Oct 2021, 23:30 Martin Sebor via Gcc, <gcc@gcc.gnu.org> wrote:

> On 10/1/21 11:44 AM, Florian Weimer wrote:
> > * Martin Sebor via Gcc:
> >
> >> I'd expect TYPE_NEEDS_CONSTRUCTING to be non-zero in the middle end
> >> for any C++ type with a user-defined ctor, but in some of my testing
> >> I see it's actually zero for std::string, at least in some instances
> >> (but nonzero for other types with ctors).  Is there something special
> >> about std::string that makes it so?  (If this is intentional, how can
> >> I create my own type that has a user-defined ctor and also a zero
> >> TYPE_NEEDS_CONSTRUCTING?)
> >
> > I assume by writing an explicit default constructor:
> >
> >    T() = default;
>
> Yes, but in a class that also defines (non-defaulted) ctors
> TYPE_NEEDS_CONSTRUCTING() is nonzero.
>
> I'm looking for a type that defines a ctor (the above just declares
> one) that has a zero for TYPE_NEEDS_CONSTRUCTING(T).  GCC documents
> the macro as:
>
> /* Indicates that objects of this type must be initialized by calling a
>     function when they are created.  */
>
> So assuming TYPE_NEEDS_CONSTRUCTING(std::string) is supposed to return
> zero (i.e., it's not a bug or some oddity I'm seeing) I want to know
> how to define a class like it, with one or more user-defined ctors,
> for which TYPE_NEEDS_CONSTRUCTING() also returns zero.  Otherwise,
> if it's a bug, I'll see if I can come up with a test case for it.
>


This seems surprising, I don't know why std string would need or get any
special treatment in this respect. I'm not aware of any magic for std::
string except for the custom mangling that is defined by the ABI for it
(which doesn't apply to our new std::__cxx11::string anyway).

>

Reply via email to