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.129.124]) by sourceware.org (Postfix) with ESMTPS id C5B8C3857BB8 for ; Mon, 17 Oct 2022 16:26:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C5B8C3857BB8 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=1666023999; 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: content-transfer-encoding:content-transfer-encoding; bh=x0ALybbp1Ynhj6Aa9iCAeN+BNGCqQldkr5D7wgPVL+A=; b=iqq5PE9fzR9dXCsvMY4hJnoQEe6Li9B6Zb4x42dts2fzg5HePmlRk0n077K78+9kc235UT VAz5GWq35NFG8DiHRLiIgETwtEQc4LtjCsjAagKhFd4ZfrCT2HJo3ape4ailZ73DbZ07Ol 5bV3iAO7J7CyBzmqj8TOKUCYfATbQhg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-483-fNZ3WxDFMtaz94icFKzePw-1; Mon, 17 Oct 2022 12:26:38 -0400 X-MC-Unique: fNZ3WxDFMtaz94icFKzePw-1 Received: by mail-qk1-f198.google.com with SMTP id n13-20020a05620a294d00b006cf933c40feso10104047qkp.20 for ; Mon, 17 Oct 2022 09:26:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x0ALybbp1Ynhj6Aa9iCAeN+BNGCqQldkr5D7wgPVL+A=; b=IHpiZroBJhJcQ2wmjwh1YWSutlAbje7VecOJDDYvBX/b7EhMxzh0HIHc1iv2yrk3U5 /osdg6OFOTYc0BPCuiiKjzUSHErh5e47EVYm72vWuVdRuCp1cvy9e5W64nZCoHnpH+RG qb0+OwvnU13P0JDkMBvuHydazaf13Bmi5dqfhgXH5AlRj7jNBToMLWN4JMxBQrGDoXdV /lhSRuaZ8s02xOc2DP8LN7Q80eKkLGLaIUDeEjC/jy9p8RBTTfjrAP/x2EW8aAgBPQw5 HVZB3dzBffI27UM0s1RgYnkjb3CJI286eM0TWUpTzDrzMDi74rGaHeH6zu+ptKwy9RAB qrXA== X-Gm-Message-State: ACrzQf1hqJOCBRvUmh32Ef9Pyn+YrjTb7hZAq8TY74a1e3Y5ycOEN4qY kssMtUcv+gDmxoLf6UEi4QJqfrummUViReCH3pO+oHjCNXOHA0i81jv5e8cinn/wwAFrN92doGh kn+/UzESYhOF72oc= X-Received: by 2002:a05:6214:c83:b0:4b1:8ea4:f3fb with SMTP id r3-20020a0562140c8300b004b18ea4f3fbmr9234882qvr.73.1666023997498; Mon, 17 Oct 2022 09:26:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ycyMQYmUC8a7hlMz9rPmpnaQDgv30vXI/iXCyoRN35IvFk6jtJCp3I/v/jsNvbg1bQgqC+g== X-Received: by 2002:a05:6214:c83:b0:4b1:8ea4:f3fb with SMTP id r3-20020a0562140c8300b004b18ea4f3fbmr9234863qvr.73.1666023997205; Mon, 17 Oct 2022 09:26:37 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id t1-20020ac86a01000000b00398946670f3sm176194qtr.1.2022.10.17.09.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 09:26:36 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Redefine __from_chars_alnum_to_val's table Date: Mon, 17 Oct 2022 12:26:32 -0400 Message-Id: <20221017162632.1085359-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.68.ge85701b4af MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: It looks like the constexpr commit r13-3313-g378a0f1840e694 caused some modules regressions: FAIL: g++.dg/modules/xtreme-header-4_b.C -std=c++2b (test for excess errors) FAIL: g++.dg/modules/xtreme-header_b.C -std=c++2b (test for excess errors) Like PR105297, the problem seems to be the local class from __from_chars_alnum_to_val ending up as the type of a namespace-scope entity (the variable template __detail::__table in this case). This patch works around this modules issue by using an ordinary class instead of a local class. Also, I suppose we might as well use a static data member to define the table once for all dialects instead of having to define it twice in C++23 mode, once as a static local variable (which isn't usable during constexpr evaluation) and again as a variable template (which is). Tested on x86_64-pc-linux-gnu, does this look OK for trunk? Diff generated with -w to ignore noisy whitespace changes. libstdc++-v3/ChangeLog: * include/std/charconv (__detail::__from_chars_alnum_to_val_table): Redefine as a class template containing type, value and _S_table members. Don't use a local class as the table type. (__detail::__table): Remove. (__detail::__from_chars_alnum_to_val): Adjust after the above. --- libstdc++-v3/include/std/charconv | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 7aefdd3298c..c157d4c74ab 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -413,14 +413,19 @@ namespace __detail return true; } + template + struct __from_chars_alnum_to_val_table + { + struct type { unsigned char __data[1u << __CHAR_BIT__] = {}; }; + // Construct and return a lookup table that maps 0-9, A-Z and a-z to their // corresponding base-36 value and maps all other characters to 127. - constexpr auto - __from_chars_alnum_to_val_table() + static constexpr type + _S_table() { constexpr unsigned char __lower_letters[27] = "abcdefghijklmnopqrstuvwxyz"; constexpr unsigned char __upper_letters[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - struct { unsigned char __data[1u << __CHAR_BIT__] = {}; } __table; + type __table; for (auto& __entry : __table.__data) __entry = 127; for (int __i = 0; __i < 10; ++__i) @@ -433,10 +438,11 @@ namespace __detail return __table; } -#if __cpp_lib_constexpr_charconv - template - inline constexpr auto __table = __from_chars_alnum_to_val_table(); -#endif + // This initializer is made superficially dependent in order + // to prevent the compiler from wastefully constructing the + // table ahead of time when it's not needed. + static constexpr type value = (_DecOnly, _S_table()); + }; // If _DecOnly is true: if the character is a decimal digit, then // return its corresponding base-10 value, otherwise return a value >= 127. @@ -449,16 +455,7 @@ namespace __detail if _GLIBCXX17_CONSTEXPR (_DecOnly) return static_cast(__c - '0'); else - { -#if __cpp_lib_constexpr_charconv - if (std::__is_constant_evaluated()) - return __table<_DecOnly>.__data[__c]; -#endif - // This initializer is deliberately made dependent in order to work - // around modules bug PR105322. - static constexpr auto __table = (_DecOnly, __from_chars_alnum_to_val_table()); - return __table.__data[__c]; - } + return __from_chars_alnum_to_val_table<_DecOnly>::value.__data[__c]; } /// std::from_chars implementation for integers in a power-of-two base. -- 2.38.0.68.ge85701b4af