From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E48D13858D1E for ; Tue, 18 Apr 2023 14:50:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E48D13858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681829418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bjQ/lO8Ln90E2B2sfyGj9bo+h1oFz2SrhPRh1/yvveM=; b=Deo+GeoMRHTjxGVepfbpX+IGZhvSUVFyaekCEPtOQqBWLYYwSnD8QOaXL29gk/Sm69SuIo zQAkrToIiqOSTfkwsMGfBqM2Q80a5vI4DAPNMCNZWxCoNShr0s8WTPRoUONu1Z59Rs/te/ cQyCQI7/V7tPrwGlThrnQF9dznWdzNQ= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-Xt0LHqf6MI29Zh742CoyAg-1; Tue, 18 Apr 2023 10:50:13 -0400 X-MC-Unique: Xt0LHqf6MI29Zh742CoyAg-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2a8c3314d18so7993291fa.0 for ; Tue, 18 Apr 2023 07:50:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681829410; x=1684421410; 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=bjQ/lO8Ln90E2B2sfyGj9bo+h1oFz2SrhPRh1/yvveM=; b=Eck/BOW7oppe4TgBPu38LTboQFiQGCFk97RjvqTPolT+VRC3fECkEOoWPMUJGP8s58 sQjtmt4wU6ZcYaGqhphVnW3B5skRr/djsTfKeTTq/vsG2pGdCqSfId6evqWS+HzYiREy 5knLz1b1obO/GhmyMRr9qfRILn6tw0eWEWu/PLAGyViL8WWyU+gBwfeRzDQ8/zKDn5Tt Dahl6AooT2hjI5oOZPMgqt1FfoKE02RNwr/KmXuUsgfPKJi4YZIj1mdCPBhCxeetOqsD 3ubQdosAQsVfwWiiCJjgGAV2INT7j4jlceKqTu8+ZUKneMcmrFxtc+8GHwA/0C8ywvan LOhg== X-Gm-Message-State: AAQBX9cLrfC0lSxUpMeDwIpsZkFpUzUGK4rxHMI77GS4j5TbvhJbOaWF mY7S12S0aq/UHefP+GjnZJ0ko6QkCp0pIsYOCDqgSg3qkBoAIzvbxkSRB3MI640Wez9eUZogrMj 8Q4zBfJQpE/VcwGEP0lrcDGH6jo0+I0s= X-Received: by 2002:ac2:515b:0:b0:4ed:d216:65f9 with SMTP id q27-20020ac2515b000000b004edd21665f9mr684152lfd.8.1681829410574; Tue, 18 Apr 2023 07:50:10 -0700 (PDT) X-Google-Smtp-Source: AKy350Zu1AxUE8Vm04XEkJHTi6Z2bvu/77XKo0HXWbKn0YKmp4YsnUYCp/97j6X7qh+n6icL+9Nu6B7T94HqdQhPbYk= X-Received: by 2002:ac2:515b:0:b0:4ed:d216:65f9 with SMTP id q27-20020ac2515b000000b004edd21665f9mr684140lfd.8.1681829410184; Tue, 18 Apr 2023 07:50:10 -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: Tue, 18 Apr 2023 15:49:58 +0100 Message-ID: Subject: Re: libstdc++ Chapter 28. Demangling example To: Jonny Grant Cc: Jonathan Wakely , libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 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