From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 7D5BF3851C02 for ; Tue, 28 Apr 2020 08:45:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7D5BF3851C02 Received: by mail-il1-x132.google.com with SMTP id b18so19490206ilf.2 for ; Tue, 28 Apr 2020 01:45:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=b8H5vwRRScQWtVTPMUiKk1cS+qS5ZMAgq+bX0f2+BLo=; b=q5fccZ4aGkulZFipn9ThZn1+GEnGJqztmXnOrtjhM7UIVi4kQrM2xCwL0KcNA9Pk9D O0w1Endn7Ky6B1Qg2VanjwbuDtup8K+I/9+Mo+23fx+qksT4/A8Ls3k8EWzh6Emq563m mho5vS0LlKtJWe/C4LryHlvvm9zoMkLSCyoliAVXF3LocODw83BtKrVNzc+Pf17DvirL kw5bsCgD0vMyC37UnydNciu4n0YcjIz1ldlD2SuAY5arr7iDRAJvWQ00hjBF7sTAyZqS M5D8MhLNBj3fq4/jPg/o8Astp2NHfX+j/IPw+CYWeDT2LRP2tetfnZylZ7izkVYN9SAi ba+A== X-Gm-Message-State: AGi0PuakKSzLeVdZkqE6IN2CU2BcPn2/pQfhJMln8DSCUidS9fIf0NZp spod6mSbRHZWg8T9+YHaQ4IWxGhLjSCm7KRc4b0= X-Google-Smtp-Source: APiQypKc+r4fbbNBv3pm8HvCIO+3hpE2pUtonCR6lIIoN4hks7h/NUmD5EKuzH8aQ7Ot4qYbzBM7POOsSukDeYFcyEs= X-Received: by 2002:a92:d912:: with SMTP id s18mr22679922iln.30.1588063520989; Tue, 28 Apr 2020 01:45:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Tue, 28 Apr 2020 09:45:10 +0100 Message-ID: Subject: Re: segment fault To: luo alvin Cc: gcc-help Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Apr 2020 08:45:26 -0000 On Tue, 28 Apr 2020 at 07:07, luo alvin wrote: > > Thank you very much for replying me. I also think it not bug,because I te= st this code in the lower version(lower than 8.3.1-3) of gcc,all cause segm= ent fault. The funny thing is that if you run this code higher than gcc ver= sion(8.3.1-4)(actually I only test code in the version 8.3.1-4),the result = is fine(doesn=E2=80=99t lead to segment fault). Your program has undefined behaviour. That means anything can happen. >furthermore, I found that the value of sizeof(std::string) is different be= tween gcc versions. Value in version 8.3.1-3 is 8 ,and 32 in version 8.3.1-= 4. That is not caused by the GCC version, it's caused by a different default for the _GLIBCXX_USE_CXX11_ABI macro. When the default is 0 sizeof(std::string) =3D=3D sizeof(char*) but when the default is 1 sizeof(string) is larger. See https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html for more information about the macro.