From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by sourceware.org (Postfix) with ESMTPS id 921C63858D32 for ; Tue, 19 Sep 2023 08:52:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 921C63858D32 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-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-d8020510203so5166951276.2 for ; Tue, 19 Sep 2023 01:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695113561; x=1695718361; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=nJSi6E+zKk0mfz1zXHvRbyFBjr4JzYBdL/fvZqVhHRQ=; b=ZwZElpEKXe5vlyCRtKnAd66tZJXiH4TBigCS0+Wf4Tr6kTPRxDIdYNjR7YwIWeiS36 NKZqcrcXcK8MNgC+VPWm4y5Fe1OSBAyclF6K8Aq1Dfe+5khxJog5ihUBuppn1Z1cnuf5 G+PbMsShSk8bbyp6RgQNz8fwlexpZAzs3Gtge7xJ7HcHL3lLbiMJDNAxj5QHLBuJJL7i H7145slFYhuPZenchs4oORv2sAPQK17XyNogAFylUHJ/LENMbFK72l43SgtibOjrq3/A BC7XgZf2T92UxkoumKY3NblCGdDat7pV3giuSFuFen1olVf+Be2GDmZVIKGxA/XpbUMq JIMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695113561; x=1695718361; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nJSi6E+zKk0mfz1zXHvRbyFBjr4JzYBdL/fvZqVhHRQ=; b=imakwcxamoc5Gs6bHB+/l4QtOhwNTJxIGHIQowVZXat27T+r45i/DFQFExLZHjI9z8 RkxhidoGj5fY4UmhkWf5nHFXQMHy2LwRpzxvfpCasQWKqwjHHFPjxQT0lQnrrDnQHTRD gNBRRjhEIhAcdUDIdxirp67ea8u/E4IPxRfNRWeVNNNYKhYnT8KqJj2eNPdcgSBZ9ach iBuckp647F81oRNJguRyIpi7tkqy5VfzXwFrSlddZiEWwkPD6whBv+eLU9y5agLwQvWa evnyTSumhevNng58r1z18JcS6nxYjkLngwAX6GfiNhcdh75JZy/6iSzHjPHnIkwe6ySN 3NKw== X-Gm-Message-State: AOJu0YwOQSxD1ADqVvjwBw6cCbEVbTk0e06YpL+8eP7fV5AZ6om4SWZQ 3YJwCVWosPprwTTdF3oZJhsaPas8OJRMhAENCrq8DtCDGX9EGA== X-Google-Smtp-Source: AGHT+IEUqeDWmBDW9q8pP4A7jhfIVKJBiHlkgVqGVVr0K72hS5YjC5lUmfR5Bvw+uGtUt7UqkpWBAG76BiFXlLMqiUk= X-Received: by 2002:a25:2614:0:b0:d3b:e659:5329 with SMTP id m20-20020a252614000000b00d3be6595329mr10442507ybm.9.1695113560585; Tue, 19 Sep 2023 01:52:40 -0700 (PDT) MIME-Version: 1.0 From: Fabian H Date: Tue, 19 Sep 2023 10:52:29 +0200 Message-ID: Subject: usage of __PRETTY_FUNCTION__ in constexpr To: gcc-help@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,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: Hi, I hope this is the correct place to ask such questions. I'm using a library that uses __PRETTY_FUNCTION__ in a constexpr to determine the name of a type at compile time. Which pretty much looks like this: template [[nodiscard]] constexpr auto stripped_type_name() noexcept { std::string_view pretty_function{ __PRETTY_FUNCTION__ }; // Results in "constexpr auto stripped_type_name() [with Type = std::vector]" auto first = pretty_function.find_first_not_of(' ', pretty_function.find_first_of('=') + 1); auto value = pretty_function.substr(first, pretty_function.find_last_of(']') - first); return value; } template().find_first_of('.')> [[nodiscard]] static constexpr std::string_view type_name(int) noexcept { constexpr auto value = stripped_type_name(); return value; } For me that results in flaky behaviour depending on the compilation unit, optimization level and various unrelated code changes. It either returns "std::vector >" or "std::vector" when calling stripped_type_name>() I was wondering if this is a proper use of __PRETTY_FUNCTION__ and/or what could explain such behaviour.