From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 60AA13858D28 for ; Fri, 31 Mar 2023 16:18:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60AA13858D28 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-ed1-x532.google.com with SMTP id b20so91720310edd.1 for ; Fri, 31 Mar 2023 09:18:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680279507; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2gxkFxHH4Qt8jf/JQhtqocFpc0JXQGCtmBVBmhlQQoM=; b=I7RZAqxrmqjU07EjA1+hPT91CvAcBpdXiLgjff9Bx9hJ7y6Ah8yRqdzUBOsBKC3HYA 9aGlkLD5F0Iqtwzecntn8mZ5rvmQQfKg/l8HArKvegufBXsyyy7ALZ/b7S0lFd6ErhZR Dz5SnbBCJ4rOrNhTzZ2X0AYViqwfiJJFCsg5xONr/xCgsspbRsv1BmMA1toKmIErZzGn UjvG7lc/RTNsbHr5Yx69co+zo/cO05yy7YioeMJNR3ViG+tWPMN3VHy+ZIDDbXTqZPpX Ls8T5mgW463b4X0oAHx4prVIkGPvOd7dLdhAwnJkqg+aA46BL4nXObR8kB2+YAlNbTuk ejqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680279507; 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=2gxkFxHH4Qt8jf/JQhtqocFpc0JXQGCtmBVBmhlQQoM=; b=6YdSWqw4zACq8eUM6Ekgd2rFWoMQBFbX+sXPTyWWlnMdqRxgYs0kGJPz3nv8RT0fm3 ZzHbYanY2p3JZ5gU2VOLPJ2SkkYielmo7M8isEqzY2u2UvPOMPcvSKGCWJDKew5m3wP6 Q2jwMpxgLAUuFvWWxJUeqj98p/5oaBbflZoDRcasRMHJwwObLNwM26K30JRoC7QOHKLD TRaf3JqLhyDpFzGumdYj7qx/IDPyRAu86rHsm7Nlp9ur8GRX0VYydfve4aARXZ6OAJGP cEifD/TiyVtrBtGHwb9BPTHjjyXluybhjQYkIC2SPHfbpHIEIvmNgTTnRF+iF8Uzxn1V 5QkA== X-Gm-Message-State: AAQBX9cSUijhHLeyFWUOUWj8nUiPzGvC4OR4EHACUL0b5//jXqt3/4DR 5gxIoa0uh2e3L3W8eeVuorQtR5AZdTjcUFX4qwl0Thao X-Google-Smtp-Source: AKy350Z5DPpb4ykYSkNaC44GHWQvCFv8Ly1xE4TpyzheI0VB9W1vHZJL44Otv3RNhKNeJd7WsuTC5LedS2oZI+MK57g= X-Received: by 2002:a50:f68b:0:b0:4fb:ebdd:6a03 with SMTP id d11-20020a50f68b000000b004fbebdd6a03mr14071422edn.5.1680279506804; Fri, 31 Mar 2023 09:18:26 -0700 (PDT) MIME-Version: 1.0 References: <03e9c7d6-95a0-bd2e-fa31-91919ad76f3f@jguk.org> In-Reply-To: <03e9c7d6-95a0-bd2e-fa31-91919ad76f3f@jguk.org> From: Jonathan Wakely Date: Fri, 31 Mar 2023 17:18:15 +0100 Message-ID: Subject: Re: libstdc++ Chapter 28. Demangling example To: Jonny Grant Cc: libstdc++@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.7 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. > Maybe it's also a good time to update the example abi::__cxa_demangle call from those 0 parameters to be NULL? Maybe nullptr.