Skip to content

Struct Initialize with string failed? #2891

Description

@jungjin09

Hi,
this code runs fine in debug mode but in release mode, i get an error as soon as i get out of the loop. (I'm using vs2022-v143-msvc14.32)

struct functioninfo
{
	std::wstring var;
	std::wstring name;
	std::vector<std::wstring> vec;
};

for(unsigned i=0;i<1;++i)
{
	functioninfo func_finfo{ std::wstring{},std::wstring{L"abc"},{} };
}

The error I get is: Exception thrown: read access violation.
this was 0x6300620061.

Program crash when call: _Destroy_range(_Myfirst, _Mylast, _Al);

_CONSTEXPR20 void _Tidy() noexcept { // free all storage
        auto& _Al         = _Getal();
        auto& _My_data    = _Mypair._Myval2;
        pointer& _Myfirst = _My_data._Myfirst;
        pointer& _Mylast  = _My_data._Mylast;
        pointer& _Myend   = _My_data._Myend;

        _My_data._Orphan_all();

        if (_Myfirst) { // destroy and deallocate old array
            _Destroy_range(_Myfirst, _Mylast, _Al);
            _ASAN_VECTOR_REMOVE;
            _Al.deallocate(_Myfirst, static_cast<size_type>(_Myend - _Myfirst));

            _Myfirst = nullptr;
            _Mylast  = nullptr;
            _Myend   = nullptr;
        }
    }

then,
xstring
line4632

_CONSTEXPR20 void _Tidy_deallocate() noexcept { // initialize buffer, deallocating any storage
        _Mypair._Myval2._Orphan_all();
        **if (_Mypair._Myval2._Large_string_engaged()) {** 
            const pointer _Ptr = _Mypair._Myval2._Bx._Ptr;
            auto& _Al          = _Getal();
            _Destroy_in_place(_Mypair._Myval2._Bx._Ptr);
            _Al.deallocate(_Ptr, _Mypair._Myval2._Myres + 1);
        }

#if _HAS_CXX20
        if (_STD is_constant_evaluated()) {
            _Mypair._Myval2._Bx._Ptr = nullptr;
            _Mypair._Myval2._Mysize  = 0;
            _Mypair._Myval2._Myres   = 0;
        } else
#endif // _HAS_CXX20
        {
            _Mypair._Myval2._Mysize = 0;
            _Mypair._Myval2._Myres  = _BUF_SIZE - 1;
            // the _Traits::assign is last so the codegen doesn't think the char write can alias this
            _Traits::assign(_Mypair._Myval2._Bx._Buf[0], _Elem());
        }
    }

I searched many post but couldn't find the answer.
Is it a certain c++ setting that turns things upside down?
I hope someone can help me find the cause.

Thanks you.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis issue is incorrect or by design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions