From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 177A73858D1E for ; Tue, 18 Apr 2023 23:12:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 177A73858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62c.google.com with SMTP id kt6so39049785ejb.0 for ; Tue, 18 Apr 2023 16:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681859561; x=1684451561; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KZ2sDXALoOi1b13yv7LoiR3z2lUgX08eFbIu7XobcFw=; b=DLjuDhp0ypiTSsRowBZjdICb+mt5d7AR7YEMAWtVAySjxeBmrmJUo/opyzl2QoQ1f1 QOGsMZ+MCkA72OwLWCVNDbSoa5fnKcJHMqV82hT28uAfD6KVyyuVhnsP45bjGPx4XsEo U0ECgwmco60icdkeh6TWcg2RxUwbygsJ9nDi0Ohs9KgcFxZ7BcbaD3tT6AGJbL0KhL6+ ZsyOIAMl8EIoZY/Mn/wVHRJg1s3QLIqlKVYoVn20H4K7QK9JDU1EqjqaOxAcLt5H9FaF fLvdOq39i/DQr0i9BOyw6i1kseAXxNkzHCZRwg0IPE1s6UtmscsFQHym3eE46FYXi7/w N1XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681859561; x=1684451561; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KZ2sDXALoOi1b13yv7LoiR3z2lUgX08eFbIu7XobcFw=; b=eLDglT+Zk6WUdaCGc8q+Raqxbxrnn1wKE5Qw4HIUIJNRqHNoQfYVqFaAJhi0ymkOEd ndRQxjZusPj8tHP3/D0Muqfl2lMTS2F/zULPLR9P/Ivt/ge1Tq03jxbB9LzFdKpDLuib qp8/N6LBLwPwWwF1j5HGK9K51pXSqmH5bF9O5dQNQjfHpcm58dPZfPOkCvdP85oCne9c VKosf6gkggd0lEd4+BenfL/5M2a3vVf2xOTgryNhxLhnNK/so6n5mX4JLz+JQ1PLI26v s+IicDXGR/4BZLB4Vd1m5iOW9FK158Q7F6InUGknPIGUFUAfrG4zIaHmSb9sIYr6/V9y W+7g== X-Gm-Message-State: AAQBX9drLKLCVSjXqx/O7MpMrJK3Canw1ve33GHO/IDgtkpjEJmPAcM/ LFY7UD/k2GRlD0eWvwzoD5wy1VcuzRtP+0fl/DDI7ija X-Google-Smtp-Source: AKy350YdVms64qpXh6VLVl569MSmr5r0h/gMpiuykDQILqVt1GPupoTS5Ygbp52sAhB8m2QEO7fwc9+7XxITargucB0= X-Received: by 2002:a17:907:838d:b0:947:4828:4399 with SMTP id mv13-20020a170907838d00b0094748284399mr9398196ejc.12.1681859560594; Tue, 18 Apr 2023 16:12:40 -0700 (PDT) MIME-Version: 1.0 References: <03e9c7d6-95a0-bd2e-fa31-91919ad76f3f@jguk.org> <66cc512c-f341-eda5-4e9a-8066f59e829f@jguk.org> <1b8d08b9-cef0-e828-7bf3-77f71167b66d@jguk.org> <11a260c8-a3e5-38e2-38fa-871f4edf2f67@jguk.org> In-Reply-To: From: Jonathan Wakely Date: Wed, 19 Apr 2023 00:12:29 +0100 Message-ID: Subject: Re: libstdc++ Chapter 28. Demangling example To: Jonny Grant Cc: Jonathan Wakely , libstdc++@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 18 Apr 2023 at 23:50, Jonny Grant wrote: > > > > On 18/04/2023 15:49, Jonathan Wakely wrote: > > On Tue, 18 Apr 2023 at 14:00, Jonny Grant wrote: > >> > >> > >> > >> On 12/04/2023 17:07, Jonny Grant wrote: > >>> > >>> > >>> On 12/04/2023 16:36, Jonathan Wakely wrote: > >>>> On Wed, 12 Apr 2023 at 16:10, Jonny Grant wrote: > >>>>> > >>>>> > >>>>> > >>>>> On 04/04/2023 12:26, Jonathan Wakely wrote: > >>>>>> On Fri, 31 Mar 2023 at 21:38, Jonny Grant wrote: > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> On 31/03/2023 17:18, Jonathan Wakely wrote: > >>>>>>>> On Fri, 31 Mar 2023 at 16:24, Jonny Grant wrote: > >>>>>>>>> > >>>>>>>>> Hello > >>>>>>>>> > >>>>>>>>> I tried out this code. Maybe I'm doing something wrong? > >>>>>>>>> > >>>>>>>>> https://godbolt.org/z/Y78h4f1W6 > >>>>>>>>> > >>>>>>>>> https://gcc.gnu.org/onlinedocs/gcc-12.2.0/libstdc++/manual/manual/ext_demangling.html > >>>>>>>>> > >>>>>>>>> However only get reduced output after status -2 is returned: > >>>>>>>>> > >>>>>>>>> std::bad_exception => > >>>>>>>>> > >>>>>>>>> Looks like std::cout gets broken by the nullptr realname (that's a frustration). So I put an if(realname) in the godbolt link above. > >>>>>>>> > >>>>>>>> N.B. passing a null pointer to printf("%s", ptr) is undefined. > >>>>>>>> Printing "(null)" is not required by the standards. > >>>>>>>> > >>>>>>>> Anyway, the exception classes haven't printed their mangled name for > >>>>>>>> many many years, if they ever did. Only the second part of the > >>>>>>>> example, using typeid, is valid. > >>>>>>> > >>>>>>> Ok I see. Is it better that the std::bad_exception part of the example is removed? > >>>>>> > >>>>>> Yes, done for GCC 13. > >>>>> > >>>>> Great! > >>>>> > >>>>>>> > >>>>>>> c++filt doesn't demangle St13bad_exception either. > >>>>>> > >>>>>> c++filt needs the _Z prefix that identifies a mangled C++ name. The > >>>>>> __cxa_demangle function doesn't need that. > >>>>>> > >>>>>> $ c++filt St13bad_exception > >>>>>> St13bad_exception > >>>>>> $ c++filt _ZSt13bad_exception > >>>>>> std::bad_exception > >>>>> > >>>>> Ok that makes sense. > >>>>> > >>>>>>>>> Maybe it's also a good time to update the example abi::__cxa_demangle call from those 0 parameters to be NULL? > >>>>>>>> > >>>>>>>> Maybe nullptr. > >>>>>>> > >>>>>>> ok > >>>>>> > >>>>>> I didn't change them, using 0 as a null pointer constant seems OK. > >>>>> > >>>>> Isn't nullptr, or at least NULL better? NULL has always been used in C++ code, I've seldom seen 0 used professionally. > >>>> > >>>> NULL is a macro, that requires inclusion of a header. nullptr is > >>>> superior, but not available in C++98. 0 works OK here. > >>> > >>> Fair enough. One of those headers must have included - I recall it did compile with NULL. > >>> > >> > >> https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es47-use-nullptr-rather-than-0-or-null > >> ES.47: Use nullptr rather than 0 or NULL > >> > >> Where there's a 0 in an example, it gets copy-pasted. If the example use nullptr, that's what is copy-pasted. > > > > Yes, exactly, and then it doesn't compile with -std=c++98 > > Isn't it reasonable for GCC13 examples to be based on c++11 these days? c++98 is already 25 years old. > > Alas, the example doesn't compile with -std=c++98 due to missing > #include > > https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html > > https://godbolt.org/z/KjKfboqxG > > This documentation for abi::__cxa_demangle says both these can be NULL, it doesn't say 0. Feels better to follow the manual and change them to NULL. > > char * output_buffer, > size_t * length, > > https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01696.html Fine, I'll change them. Can I focus on more important things now?