From patchwork Fri Dec 4 09:55:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sadineni, Harish" X-Patchwork-Id: 107289 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.4945.1796378179899362049 for ; Fri, 04 Dec 2026 01:56:20 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@windriver.com header.s=PPS06212021 header.b=ltPFNaij; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: windriver.com, ip: 205.220.178.238, mailfrom: prvs=679879a703=harish.sadineni@windriver.com) Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B45LF3K1015424 for ; Fri, 4 Dec 2026 09:56:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=cc:content-transfer-encoding:content-type:date:from :message-id:mime-version:subject:to; s=PPS06212021; bh=8GAO+SqJS IOz6Nik4h92xcWo0eQAfk8wkeD8Q0uDasw=; b=ltPFNaijOQt3qVefdkaB5e+kI fHKYKrY9CGgEVev042OkjhBLl93Z/BjlxBdNcZJmL6/ULGNAOisZCJe8YaasrU0V ppedMfIrA9RVRz9PCo7cIFr+oZvOAccvlIsyBe44284WpO7E+qP89WF1vof7Bohr /ObMDbHNDLmyd/cgGXVRTn1IaN+s8d60TegMRXBT9XTfZRuKSZFzwN0lVWPUJ8mv 77EIlsXWXBGGwVQAV0uX4/z4kPe2DsaT7PXa8TjQBr6AIVM7Ff+zPx4AVc5FRMdt b/rM8xcDCMwXmGbhMRm52EhCqniA2r0+lUzvel85gEBlepQzEDOheQKNnymnA== Received: from sn4pr2101cu001.outbound.protection.outlook.com (mail-southcentralusazon11022138.outbound.protection.outlook.com [40.93.195.138]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 4jbq7w0bpd-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Fri, 04 Dec 2026 09:56:18 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XM05oe1OLp2xVIBs6N1UGIqa5vQkXihTp2KeEQ6cwc0z82T204A2zNFpL2fe8Ssoaoz2c1ZOvya816rf/lv25ISabkyIgcjiCe4eIs2JyuZwyIGYRsNtZWbLkt42rk5N+ujUu5/idL6HAgmOa7DQId+bEpGsUkU4S4q7uqtFIhWvhoGpJV3jj20LB2J1mhxYlyK/khIEGD6BetmGzoEtcQs0qj5OZn1B/y6ud+xXDRo3yc9xn7zZMp8T28GdgJxsDe9I+wOzF8LBNsnlmbm2DEYwiJmQluks9hiykUirC0FoePSSLI209+TJ7E3Zm7NY12/hFoZZfDDLsHV9Y33JOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8GAO+SqJSIOz6Nik4h92xcWo0eQAfk8wkeD8Q0uDasw=; b=KX/HAcPXLwIDOet1qnTz/fLoCmJljKd9QouSNRXAo04/+sJIMPi/bdRLEnpcTv0ep05PggMgUh9Zs1YjBEfgxM4rkZupRbawj6M0JPnCYuC/E761AfjUfVhHJzsoXbVoeZEx5uEfpKUqfACxYiq5PL8/dh0cRKDruc8vczN109XYzlXmGzRStN8sljqjTOZo9gPENRGhuoS/vfiyquQL+TEbSCZnNSyHP9MdF6TuDlWpRHNEhxeVxAJOp7tYG/Cd5EGqvJlRGfEDGWosvqUiMQfqVnjFC+QXVk7CkVn6eW8N+8oW/bcRZWS6McW0MrmeXNt6hgxHxJWGOsYoUsZJSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=windriver.com; Received: from SA3PR11MB346485.namprd11.prod.outlook.com (2603:10b6:806:5a4::14) by CYXPR11MB8755.namprd11.prod.outlook.com (2603:10b6:930:e3::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.12; Fri, 4 Dec 2026 09:56:11 +0000 Received: from SA3PR11MB346485.namprd11.prod.outlook.com ([fe80::7e79:2dbb:6903:6080]) by SA3PR11MB346485.namprd11.prod.outlook.com ([fe80::7e79:2dbb:6903:6080%5]) with mapi id 15.21.0688.011; Fri, 4 Dec 2026 09:56:11 +0000 From: Harish.Sadineni@windriver.com To: openembedded-core@lists.openembedded.org Cc: Sundeep.kokkonda@Windriver.com Subject: [wrynose][PATCH 1/2] gcc: Fix for CVE-2026-114691 Date: Fri, 4 Dec 2026 01:55:23 -0800 Message-Id: <20261204095524.1907176-1-Harish.Sadineni@windriver.com> X-Mailer: git-send-email 2.39.4 X-ClientProxiedBy: SJ0PR03CA0072.namprd03.prod.outlook.com (2603:10b6:a03:331::17) To SA3PR11MB346485.namprd11.prod.outlook.com (2603:10b6:806:5a4::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA3PR11MB346485:EE_|CYXPR11MB8755:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d610aee-f974-4b39-8553-08df51ecd344 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|52116014|11063799006|6133799003|261009223027099003|13003099007|18002099003|260925021911599003|260925021311599003|261026140227099003|260925022911599003|56012099006|261021123027099003|261022105027099003|261102123227099003|261028144727099003|261021121427099003|261022075727099003|261026121527099003|10067099003|38350700014; X-Microsoft-Antispam-Message-Info: M3wTUaW+EjzsvA6805JNinYK0TKYPb/P5WJ35YTv1JAwjDEta9/R7VOLgw9VfI4uTyGyptQhTsM3j/Kt3In+ppxabL0GeABInnOBWm/c6r/pXCka3PLotxm03+MSR8N8cr+be/+iwXwLfXz8V+uXA0NtCJLGQMdQ9pazj+5XckPkne2S4yJ27Hah79Q+n8DMwGaKfUh0zKeE7q8JY1TrX1fEwrcYcKtkExUVRk1i6MmFchvxP92zp3P78oyUj9/un1XqC7waVwOM+TnMKIba/O+815JcSmOjL+zYuagdZWVuOWU7paoFNAZU5gQGzdj96z4Mlej1lojsUHMhLzYxRGs6W6Wesd1lnI3f1LzNn0sFmto2TKuXLZmehEfOokZP4+8wdfJMJVVlLGR6q0XaL5GqxkTTygcVPwNbY4HQu3SU2N3sY14m5hdsgAo748uqge32k7XPFcPFxiRwQ0u74siE3TxanlBF45KxyFPwytU42pPsguKRbYn/NzxxoBxcL95YO9iQyCgP1dGQi7dwHJJGia7F5vpnpN95tbxZ1qJhMGlo4YQkqxFKuTjaXDb+nP1GYBFf+Onb90ZzIcXk6q43kOV18ldWFwyBzYLOFCqTo1UQnd8Dn5kKo/nyJ2sHam7xIWgSClqfnXqYk3q4DMh82Mjx3J21DJtiWV0qvkpY9LTi6aVLW+7uu4ANE4yri280uPDVwk9JgdtHgxGDedqsTPoABnF/FMBZKCSQ9g4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA3PR11MB346485.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(52116014)(11063799006)(6133799003)(261009223027099003)(13003099007)(18002099003)(260925021911599003)(260925021311599003)(261026140227099003)(260925022911599003)(56012099006)(261021123027099003)(261022105027099003)(261102123227099003)(261028144727099003)(261021121427099003)(261022075727099003)(261026121527099003)(10067099003)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Z9BkdWQ5MvdqO3CViQrAWhgX9LI7kkgWsv1dJlL3OdJDCz51YLyu+xa2hGazCe5fyVSoSgQ== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d610aee-f974-4b39-8553-08df51ecd344 X-MS-Exchange-CrossTenant-AuthSource: SA3PR11MB346485.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 09:56:10.9589 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lwkgfy3B5rwnvnhjOseOcIn6vnl7yEsgV/QvwfwBSyxr5Tr9bfzjSIm4C+0NmY8+piZ30mOtajIq0rcnCi1OvbJcM/ch0t8wAxecL4LEiL0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR11MB8755 X-Proofpoint-ORIG-GUID: jUlJbFs1mkqYX20PbDwFS_FyEdAd8gWc X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA0MDAzOSBTYWx0ZWRfX1Oc70XRmMBTl 9eB4JC+74vLrJ2KY3ASr0jaZEoq5OKZ31ni83zNPU+UGWfXkyYxM/r5SLrpbfHOaNw5QTPucBQH VdNbeLlIyZ1KMqhQgb7ktsuFLmZP66AIDpYC+i0PuKCM6MoPWtj/Ge6kDk2gZF8DAWzp4L8RXbQ PBlABI6LW8LOwY5AwQtDwqbkRrpXb4fdzKbRL3ZBwd2BsMQf+muCbvEs3asTXon9lvRU3uREJ+/ B1EGqMLfEYAiZa9Z9wPV5/R9hG8dUNx3B13j/M4Ws3QzrLhFQFWFuY9HxMKjPTkEpdJ00P1gXVP Zh3Q2aGAZUYiLADmcDVb3MEy+RUnVArZLrE3h+cUUHCHycIQFKBu1OrIjdN+5G5X9+wLtKPl1cb 5SejW2OKySZF0Q3ZDNTkWPBL2HNIPAIGAzu0dXGEVz8guJPXpJyMJCi4UA1OeQqpqzhS5ES8Ik8 3QmA+/+Hi0PYkVQsOpw== X-Authority-Analysis: v=2.4 cv=C618WgP+ c=1 sm=1 tr=0 ts=6b128e42 cx=c_pps a=ZVJWEtTsqHd5Y1/ROadkLg==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=bi6dqmuHe4P4UrxVR6um:22 a=klDOsUkWDRETUCZYPvoE:22 a=PYnjg3YJAAAA:8 a=mDV3o1hIAAAA:8 a=t7CeM3EgAAAA:8 a=20KFwNOVAAAA:8 a=Ts-6AtMENj6w9u1THSIA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDAzOSBTYWx0ZWRfXxtP43aB8hJp5 DoVkqqLSFp49Kq0GexSWAkFKx8lZvTKx/P60eD6VXkSUVKm45BK00GI7V67yWDHyXQaGCbl949I TqzC1S1TuK3dFIc4QJetjQDbjRcHXNZI7CUKg9WGcD8E80WVRYhy X-Proofpoint-GUID: jUlJbFs1mkqYX20PbDwFS_FyEdAd8gWc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-04_01,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 adultscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612040039 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Fri, 04 Dec 2026 09:56:21 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251948 From: Harish Sadineni libstdc++: Fix overflow in std::vector constructors (CVE-2026-114691) Some std::vector constructors pass a user-provided size (or a distance derived from user-provided range) to the _S_nword function which does addition to find the number of words (of type unsigned long) that are needed for that number of bits. If the size is close to SIZE_MAX the addition wraps to zero and the number of words needed is incorrect. This adds a new function for initializing from user-provided sizes which checks against max_size() so that out-of-range values are rejected before any call to _S_nword. The new function rejects negative values as well as large ones. For an invalid range the result of ranges::distance or std::distance could be a very large negative value that would become smaller than max_size() when converted to size_t. This detects some invalid inputs (last before first) at minimal cost. References: https://nvd.nist.gov/vuln/detail/cve-2026-114691 https://gcc.gnu.org/cgit/gcc/patch/?id=2ab9ded76e8714b1654260ac68a815c20567cc09 Signed-off-by: Harish Sadineni --- meta/recipes-devtools/gcc/gcc-15.3.inc | 1 + .../gcc/gcc/0030-CVE-2026-114691.patch | 292 ++++++++++++++++++ 2 files changed, 293 insertions(+) create mode 100644 meta/recipes-devtools/gcc/gcc/0030-CVE-2026-114691.patch diff --git a/meta/recipes-devtools/gcc/gcc-15.3.inc b/meta/recipes-devtools/gcc/gcc-15.3.inc index ed719197bc..b87b4ce9f4 100644 --- a/meta/recipes-devtools/gcc/gcc-15.3.inc +++ b/meta/recipes-devtools/gcc/gcc-15.3.inc @@ -76,6 +76,7 @@ SRC_URI = "${BASEURI} \ file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \ file://0001-mapper-localhost-might-not-be-known.patch \ file://0029-CVE-2026-102010.patch \ + file://0030-CVE-2026-114691.patch \ " UNPACKDIR = "${TMPDIR}/work-shared/gcc-${PV}-${PR}/sources" diff --git a/meta/recipes-devtools/gcc/gcc/0030-CVE-2026-114691.patch b/meta/recipes-devtools/gcc/gcc/0030-CVE-2026-114691.patch new file mode 100644 index 0000000000..86538eb362 --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc/0030-CVE-2026-114691.patch @@ -0,0 +1,292 @@ +From 2ab9ded76e8714b1654260ac68a815c20567cc09 Mon Sep 17 00:00:00 2001 +From: Jonathan Wakely +Date: Mon, 26 Oct 2026 17:21:01 +0000 +Subject: libstdc++: Fix overflow in std::vector constructors + (CVE-2026-114691) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Some std::vector constructors pass a user-provided size (or a +distance derived from user-provided range) to the _S_nword function +which does addition to find the number of words (of type unsigned long) +that are needed for that number of bits. If the size is close to +SIZE_MAX the addition wraps to zero and the number of words needed is +incorrect. + +This adds a new function for initializing from user-provided sizes which +checks against max_size() so that out-of-range values are rejected +before any call to _S_nword. + +The new function rejects negative values as well as large ones. For an +invalid range the result of ranges::distance or std::distance could be a +very large negative value that would become smaller than max_size() when +converted to size_t. This detects some invalid inputs (last before +first) at minimal cost. + +libstdc++-v3/ChangeLog: + + * include/bits/stl_bvector.h (_M_check_and_initialize): New + function. + (vector(size_type, const bool&, const allocator_type&)) + (vector(from_range_t, R&&, const Alloc&)) + (_M_initialize_dispatch, _M_initialize_range): Use new function + instead of _M_initialize. + (_M_initialize): Add debug assertion. + * testsuite/23_containers/vector/bool/prX.cc: New test. +CVE: CVE-2026-114691 +Upstream-Status: Backport [https://gcc.gnu.org/cgit/gcc/patch/?id=2ab9ded76e8714b1654260ac68a815c20567cc09] + +Signed-off-by: Harish Sadineni +(cherry picked from commit 2fd8866591b5aea7098835f80ab7e176382175ae) +--- + libstdc++-v3/include/bits/stl_bvector.h | 24 +++- + .../testsuite/23_containers/vector/bool/prX.cc | 160 +++++++++++++++++++++ + 2 files changed, 179 insertions(+), 5 deletions(-) + create mode 100644 libstdc++-v3/testsuite/23_containers/vector/bool/prX.cc + +diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h +index f190d1be5cec..24e5e7bf0420 100644 +--- a/libstdc++-v3/include/bits/stl_bvector.h ++++ b/libstdc++-v3/include/bits/stl_bvector.h +@@ -715,6 +715,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + { _M_impl._M_move_data(std::move(__x._M_impl)); } + #endif + ++ // Caller must ensure the addition won't overflow. + _GLIBCXX_CONSTEXPR + static size_t + _S_nword(size_t __n) +@@ -811,7 +812,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + #endif + : _Base(__a) + { +- _M_initialize(__n); ++ _M_check_and_initialize(__n); + _M_initialize_value(__value); + } + +@@ -909,7 +910,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + { + if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) + { +- _M_initialize(size_type(ranges::distance(__rg))); ++ _M_check_and_initialize(ranges::distance(__rg)); + ranges::copy(__rg, begin()); + } + else +@@ -1553,6 +1554,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + void + _M_initialize(size_type __n) + { ++ // Caller must ensure this, to avoid overflow in _S_nword. ++ _GLIBCXX_DEBUG_ASSERT(__n <= (size_t)-_S_word_bit); ++ + if (__n) + { + _Bit_pointer __q = this->_M_allocate(__n); +@@ -1563,6 +1567,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + } + } + ++ template ++ _GLIBCXX20_CONSTEXPR ++ void ++ _M_check_and_initialize(_SizeT __n) ++ { ++ if (__n > max_size() || __n < 0) ++ __throw_length_error( ++ __N("Cannot create std::vector larger than max_size()")); ++ _M_initialize(static_cast(__n)); ++ } ++ + _GLIBCXX20_CONSTEXPR + void + _M_initialize_value(bool __x) _GLIBCXX_NOEXCEPT +@@ -1588,7 +1603,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + void + _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) + { +- _M_initialize(static_cast(__n)); ++ _M_check_and_initialize(static_cast(__n)); + _M_initialize_value(__x); + } + +@@ -1616,8 +1631,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last, + std::forward_iterator_tag) + { +- const size_type __n = std::distance(__first, __last); +- _M_initialize(__n); ++ _M_check_and_initialize(std::distance(__first, __last)); + std::copy(__first, __last, begin()); + } + +diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/prX.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/prX.cc +new file mode 100644 +index 000000000000..bc97b9bfde5f +--- /dev/null ++++ b/libstdc++-v3/testsuite/23_containers/vector/bool/prX.cc +@@ -0,0 +1,160 @@ ++// { dg-do run } ++ ++#include ++#include ++#include ++#include ++ ++static void ++test_n_element_ctor() ++{ ++ try { ++ std::vector v(-15, true); ++ VERIFY(false); ++ } catch (const std::length_error&) { ++ } ++} ++ ++static void ++test_n_element_ctor_dispatch() ++{ ++ try { ++ std::vector v(-15, 1); // in C++98 this calls vector(Iter, Iter) ctor ++ VERIFY(false); ++ } catch (const std::length_error&) { ++ } ++} ++ ++// A Cpp17RandomAccessIterator for which std::distance always returns an ++// impossibly large distance. This implements the Cpp17RandomAccessIterator ++// API but doesn't meet the semantic requirements. ++// For the test below, all that matters is that the huge value from ++// std::distance(first, last) causes std::length_error to be thrown. ++struct FakeIterator ++{ ++ typedef std::random_access_iterator_tag iterator_category; ++ typedef bool value_type; ++ typedef std::size_t difference_type; // should be a signed type ++ typedef const bool* pointer; ++ typedef const bool& reference; ++ ++ FakeIterator() : val(true) { } ++ ++ reference operator*() const { return val; } ++ pointer operator->() const { return &val; } ++ reference operator[](difference_type) const { return val; } ++ ++ FakeIterator& operator++() { return *this; } ++ FakeIterator operator++(int) { return *this; } ++ FakeIterator& operator--() { return *this; } ++ FakeIterator operator--(int) { return *this; } ++ ++ FakeIterator& operator+=(difference_type) { return *this; } ++ FakeIterator& operator-=(difference_type) { return *this; } ++ ++ FakeIterator operator+(difference_type) const { return *this; } ++ FakeIterator operator-(difference_type) const { return *this; } ++ ++ friend FakeIterator operator+(difference_type, FakeIterator i) { return i; } ++ ++ // Return an impossibly large distance ++ difference_type operator-(FakeIterator) const { return (std::size_t)-8; } ++ ++ // These are meaningless results but not actually used by this test. ++ bool operator==(const FakeIterator&) const { return false; } ++ bool operator!=(const FakeIterator&) const { return true; } ++ bool operator<(const FakeIterator&) const { return true; } ++ bool operator>(const FakeIterator&) const { return false; } ++ bool operator<=(const FakeIterator&) const { return true; } ++ bool operator>=(const FakeIterator&) const { return false; } ++ ++private: ++ bool val; ++}; ++ ++#ifdef __cpp_lib_ranges ++// Wraps a std::random_access_iterator as a Cpp17RandomAccessIterator ++// except for having an integer-like class type as difference_type. ++// This one is _almost_ a real Cpp17RandomAccessIterator, except for the ++// difference_type. Again, we only care that the huge distance is ++// detected and std::length_error is thrown. ++class Iterator ++{ ++ using View = std::ranges::iota_view; ++ using ViewIter = std::ranges::iterator_t; ++ ++public: ++ using iterator_category = std::random_access_iterator_tag; ++ using value_type = bool; ++ using difference_type = std::iter_difference_t; ++ ++ Iterator() = default; ++ ++ explicit Iterator(ViewIter iter) : iter(iter) { } ++ ++ const bool& operator*() const { return val; } ++ const bool* operator->() const { return &val; } ++ const bool& operator[](difference_type n) const { return *(*this + n); } ++ ++ Iterator& operator++() { ++iter; return *this; } ++ Iterator operator++(int) { return Iterator(iter++); } ++ Iterator& operator--() { --iter; return *this; } ++ Iterator operator--(int) { return Iterator(iter--); } ++ ++ Iterator& operator+=(difference_type n) { iter += n; return *this; } ++ Iterator& operator-=(difference_type n) { iter -= n; return *this; } ++ ++ Iterator operator+(difference_type n) const { return Iterator(iter + n); } ++ Iterator operator-(difference_type n) const { return Iterator(iter - n); } ++ ++ friend Iterator operator+(difference_type n, Iterator i) { return i + n; } ++ difference_type operator-(Iterator i) const { return iter - i.iter; } ++ ++ bool operator==(const Iterator& i) const { return iter == i.iter; } ++ auto operator<=>(const Iterator& i) const { return iter <=> i.iter; } ++ ++private: ++ ViewIter iter = ViewIter(); ++ bool val = true; ++}; ++ ++static_assert( std::random_access_iterator ); ++#endif ++ ++static void ++test_range_ctors() ++{ ++ try { ++ FakeIterator x; ++ std::vector v(x, x); ++ VERIFY(false); ++ } catch (const std::length_error&) { ++ } ++ ++#ifdef __cpp_lib_ranges ++ const std::size_t min = 0, max = -8; ++ auto i = std::views::iota(min, max); ++ try { ++ Iterator first(std::ranges::begin(i)); ++ Iterator last(std::ranges::end(i)); ++ std::vector v(first, last); ++ VERIFY(false); ++ } catch (const std::length_error&) { ++ } ++ ++#ifdef __cpp_lib_containers_ranges ++ try { ++ std::vector v(std::from_range, i); ++ VERIFY(false); ++ } catch (const std::length_error&) { ++ } ++#endif ++#endif ++} ++ ++int main() ++{ ++ test_n_element_ctor(); ++ test_n_element_ctor_dispatch(); ++ test_range_ctors(); ++} +-- +cgit