Discharge error xstring under structure



  • Please help me understand the mistake?

    The mistake I've been seeing for the first time is compiling the code itself, but it ends with a mistake. Attempting to launch it in debag mode leads to the failure of even the first line, and to move immediately into the xstring file with a mistake:

    return __builtin_strlen(_First);

    Exemption at 0x00007FF607A36C14: 0xC0000005: violation Access rights at 0x00000000.

    The problem is clearly in this line of code: my_struct_class = {0 }; if it is removed, the mistake is gone, but I can't understand, what's wrong with that code?

    main.cpp

     #include <iostream>      
    
    int main()
    {
    
    }
    

    My_func.cpp

     #include <iostream>

    #include "My_class.h"
    
    
         My_class My_class_;
    
    
        int My_func()          
        {
            return 0;
        }
    

    my_class.h

    #pragma once

    #include "My_struct_for_struct.h"

    class My_class
    {
    
    public:
    
    
        My_class()
        {
            my_struct_class = { 0 };
        }
    
    
    private:
    
        My_struct_for_struct my_struct_class;
    
    };
    

    my_struct.h

    #pragma once
    #include <string>

    struct my_struct                                          
    {
        std::string my_string;                                                                            
    };
    
    
    
    struct My_struct_for_struct
    {
        my_struct my_struct_;    
    };
    



  • If you remove the double level of investment and classrooms, you'd like to write this code.

    std::string s{0};
    

    (Yes, the quoted brackets of "universal initialization" are usually "reasonably brutal" when the types are not matched, but zero is a separate topic.

    This code looks interesting, but it's semilegal. The point is, 0 in s+ is converted to NULL / nullptr.

    The line (and the basic_string) has a designer who accepts a line indicator (which would be a software writer like this.

    std::string s = "test";
    

    )

    But the compiler can't always distinguish the index on the line from nullptr (in fact, a special overload can be made, but it's compilation time only).

    And if you look at the docks, https://en.cppreference.com/w/cpp/string/basic_string/basic_string (d) It can be seen that in the 23 standard, the grace was lowered and added.

    constexpr basic_string( std::nullptr_t ) = delete;
    

    But initially, the standard developers made a strange decision - on nullptr in the designer, not to check the case clearly and in no way specifically (yes, strange decision).

    there, https://en.cppreference.com/w/cpp/string/basic_string/basic_string It that this designer covers a little more cases.

    1. Constructs the string with the contents initialized with a copy of the null-terminated character string pointed to by s. The length of the string is determined by the first null character. The behavior is undefined if [s, s + Traits::length(s)) is not a valid range (for example, if s is a null pointer)

    I mean, the length (and end) of the line is defined by a zero symbol. If the range is incorrect, the same behavior. The nullptr case is described separately and as I do, it seems that someone just didn't find a better explanation. (yeah, I guess it was because if a zero symbol was found outside the folded memory under the line, the range was incorrect, but the standard was so hard to avoid a clear mention of simple things that sometimes went so far. And this case of nullptr, I think it's gonna get a lot of ears in here. I guess I just couldn't agree what to do in this case. But that's my guess.

    Right here. https://groups.google.com/a/isocpp.org/g/std-proposals/c/PGdx39Iy8pg They say that this was done for productivity. Maybe.

    As shown http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2166r1.html The problem is much deeper than originally anticipated.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2