From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 401603858D28 for ; Fri, 13 Oct 2023 23:33:11 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 401603858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::729 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697239993; cv=none; b=jUnW+j4ie4lgyeL7EGH0RmxhKxN21BLhKoRqvQGFRfVkFjcYM7NzPLCEXghnZnqd7cuiTMpYnezNrcHm8h2OzLORFXCoJIrgTV3s2mRH98W3d29s13hi1aPJmSuFb3wGsGyG7ko/Eqv9JzeXq4KCWaD/B/nY03fUmunsHm3Zh5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697239993; c=relaxed/simple; bh=DT0WMzN08IxKPj5h3kHcPLMwTNoqJOkreGiTrMT4qmA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=oZazPdniZo4Io+S1ZPf4gLd/Y9UhcNW8SU8dYP42uraoq+Vabf/k+7gD+5DIm3th1QC2NTVL3SrCstBMqgYqkbGOABnpuM6ODsh2DS+LX0AZslYg0xyFJyFOlf+pNCSEiNEIRQJ+CpaBP0GJ9eI1fWDeiZ1FzlMJ96BUbjqchus= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 401603858D28 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=cs.berkeley.edu Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=berkeley.edu Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-775810b032aso168204285a.1 for ; Fri, 13 Oct 2023 16:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.berkeley.edu; s=google; t=1697239990; x=1697844790; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=XyStzg7HivlG9fM5oh1u3XBBPwpTmMSOVRzyT41m8+w=; b=dEEUKMLxkQk+SZrqG97xckXsb4wDqyqNdMcnQJrRVxczcXIUujcbTB0+JdEZ2LjVS1 o2Wib/vbaLnPgpbK1DzEYbsnfexLpk6NHx5+76NIQLNrNTu12y4YP4jh9FqZkS4AEVsT PnGihL7Ut409xezJrxToKYw9RBRJo4tdLV/2eSJbrNPBswDZeEApKWkQSx2UFSTtrVwQ vGCa96OuaDx8HG5OT1x1Yd0nX7tBndEr7YhutI2r6+1H5UC2tmTSAYRN4YeAg1usrATd vwZEj5SPf/pnJt0Chi6sfuGS22JTO7Fxtb1JmidZ/0RPDl3HaqyDe5d8WDz7px2tF8eM O3aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697239990; x=1697844790; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XyStzg7HivlG9fM5oh1u3XBBPwpTmMSOVRzyT41m8+w=; b=PUC7DDoSnxdf3nPCpZhFWDnc2ap41kaZs2F99rkbFxYv73AM4LZIAG/Qp1th/u6xTl sZUJiS9zEEYERC29OS5602DXpnK0R2iiaDYQZRMCyjtip4WNSOUQcAEZII481oCHxEP1 N/PJVlvNGWm4E6nr3c9yURtqek8cC2Rm0NkyO+4RJtBAU1ekpeys5QOyi8qfOJS9DGvT HdZGcfQxcQfuJvCrt2Dv+9wmG27Ix2SYTov2IRdP/ac8Tl2x27VFLadj+AWlsokgPSU1 pjuf0lBOElvBlxgXDza102vmedT2pKwAgZDDctVVsMWYKUGkSz7XW152Rtq0owUpuBwM ujBw== X-Gm-Message-State: AOJu0YzazmrE5Z6D41u1lCAFIMDF4z8yvScDQ7/KkjOSquuvGlrchjBD pVDh0YePIQuRC7V+fZH0iUGjaoI/7zbhu3fNMA+3ITTqcN3/Zjsn1A== X-Google-Smtp-Source: AGHT+IEIOg1WtSAa4k0FAYx1SuRb8offnHBcn1WHr8T/48AONK90/8g7tHivL3i+ThR2AedpeOjdZHXGQHJB34n7F9E= X-Received: by 2002:a05:620a:45a5:b0:774:5ab:d032 with SMTP id bp37-20020a05620a45a500b0077405abd032mr37033683qkb.23.1697239989672; Fri, 13 Oct 2023 16:33:09 -0700 (PDT) MIME-Version: 1.0 From: Benjamin Brock Date: Fri, 13 Oct 2023 16:32:59 -0700 Message-ID: Subject: [PATCH] libstdc++: Workaround for LLVM-61763 in ranges To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,TXREP,T_SPF_PERMERROR 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: This is my first time submitting a patch, so my apologies if I'm submitting incorrectly or missing something. Clang is unable to compile parts of libstdc++'s ranges implementation due to LLVM-61763, a Clang frontend compiler bug in handling the declarations of constrained friends. The problem areas are zip_view, zip_transform_view, and adjacent_transform_view. A simple ranges program like the following fails to compile using Clang trunk and libstdc++. std::vector v = {1, 2, 3, 4}; int sum = 0; for (auto&& [i, j] : std::ranges::views::zip(v, v)) sum += i * j; In file included from :1: /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../include/c++/14.0.0/ranges:4655:14: error: type constraint differs in template redeclaration 4655 | template | ^ . . . . . . Godbolt: https://godbolt.org/z/Ynbs15aGh This patch adds a small workaround that avoids declaring constrained friends when compiling with Clang, instead making some members public. MSVC's standard library has implemented a similar workaround. Scanning through libstdc++, there do appear to be other workarounds for Clang, e.g. in complex and experimental/simd. Hopefully this kind of workaround is acceptable---while the core issue is a Clang compiler bug, it may take a while to fix, and it would be very useful for libstdc++ ranges to work with Clang in the meantime. 2023-10-13 Benjamin Brock libstdc++-v3/ChangeLog: * include/std/ranges: implement workaround for LLVM-61763 in zip_view and adjacency_view --- diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 1d529a886be..7893e3a84c9 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -4632,6 +4632,9 @@ namespace views::__adaptor class zip_view<_Vs...>::_Iterator : public __detail::__zip_view_iter_cat<_Const, _Vs...> { +#ifdef __clang__ // LLVM-61763 workaround + public: +#endif __detail::__tuple_or_pair_t>...> _M_current; constexpr explicit @@ -4652,11 +4655,13 @@ namespace views::__adaptor return input_iterator_tag{}; } +#ifndef __clang__ // LLVM-61763 workaround template requires (view<_Ws> && ...) && (sizeof...(_Ws) > 0) && is_object_v<_Fp> && regular_invocable<_Fp&, range_reference_t<_Ws>...> && std::__detail::__can_reference...>> friend class zip_transform_view; +#endif public: // iterator_category defined in __zip_view_iter_cat @@ -5327,6 +5332,9 @@ namespace views::__adaptor template class adjacent_view<_Vp, _Nm>::_Iterator { +#ifdef __clang__ // LLVM-61763 workaround + public: +#endif using _Base = __detail::__maybe_const_t<_Const, _Vp>; array, _Nm> _M_current = array, _Nm>(); @@ -5367,12 +5375,14 @@ namespace views::__adaptor friend class adjacent_view; +#ifndef __clang__ // LLVM-61763 workaround template requires view<_Wp> && (_Mm > 0) && is_object_v<_Fp> && regular_invocable<__detail::__unarize<_Fp&, _Mm>, range_reference_t<_Wp>> && std::__detail::__can_reference, range_reference_t<_Wp>>> friend class adjacent_transform_view; +#endif public: using iterator_category = input_iterator_tag;