Skip to content

Commit 2acdac5

Browse files
committed
[libc++] Adds is_implemented function for new ftm generator.
At the moment the ftm macro for __cpp_lib_to_chars will have the following values: standard_ftms: { "c++17": "201611L", "c++20": "201611L", "c++23": "201611L", "c++26": "201611L", } implemented_ftms: { "c++17": None, } This is an issue with the test whether the FTM is implemented it does: self.implemented_ftms[ftm][std] == self.standard_ftms[ftm][std] This will fail in C++20 since implemented_ftms[ftm] does not have the key c++20. This adds a new helper function and removes the None entries when a FTM is not implemented.
1 parent 658f848 commit 2acdac5

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ def test_implementation(self):
3838
"c++23": "201907L",
3939
"c++26": "299900L",
4040
},
41-
"__cpp_lib_format": {
42-
"c++20": None,
43-
"c++23": None,
44-
"c++26": None,
45-
},
41+
"__cpp_lib_format": {},
4642
"__cpp_lib_parallel_algorithm": {
4743
"c++17": "201603L",
4844
"c++20": "201603L",
@@ -55,11 +51,7 @@ def test_implementation(self):
5551
"c++23": "202102L",
5652
"c++26": "202102L",
5753
},
58-
"__cpp_lib_missing_FTM_in_older_standard": {
59-
"c++17": None,
60-
"c++20": None,
61-
"c++26": None,
62-
},
54+
"__cpp_lib_missing_FTM_in_older_standard": {},
6355
}
6456

6557
self.assertEqual(self.ftm.implemented_ftms, expected)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
10+
11+
import sys
12+
import unittest
13+
14+
UTILS = sys.argv[1]
15+
TEST_DATA = sys.argv[2]
16+
del sys.argv[1:3]
17+
18+
sys.path.append(UTILS)
19+
from generate_feature_test_macro_components import FeatureTestMacros, Metadata
20+
21+
22+
class Test(unittest.TestCase):
23+
def setUp(self):
24+
self.ftm = FeatureTestMacros(TEST_DATA)
25+
self.maxDiff = None # This causes the diff to be printed when the test fails
26+
27+
def test_implementation(self):
28+
# FTM not available in C++14.
29+
self.assertEqual(self.ftm.is_implemented("__cpp_lib_any", "c++14"), False)
30+
self.assertEqual(self.ftm.is_implemented("__cpp_lib_any", "c++17"), True)
31+
32+
self.assertEqual(self.ftm.is_implemented("__cpp_lib_format", "c++20"), False)
33+
34+
# FTM C++20 202106L, libc++ has 202102L
35+
self.assertEqual(self.ftm.is_implemented("__cpp_lib_variant", "c++20"), False)
36+
37+
38+
if __name__ == "__main__":
39+
unittest.main()

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,8 @@ def get_ftms(
20102010
else:
20112011
break
20122012

2013-
entry[std] = last
2013+
if last:
2014+
entry[std] = last
20142015
result[feature["name"]] = entry
20152016

20162017
return result
@@ -2206,6 +2207,20 @@ def implemented_ftms(self) -> Dict[Ftm, Dict[Std, Optional[Value]]]:
22062207

22072208
return get_ftms(self.__data, self.std_dialects, True)
22082209

2210+
def is_implemented(self, ftm: Ftm, std: Std) -> bool:
2211+
"""Has the FTM `ftm` been implemented in the dialect `std`?"""
2212+
2213+
# When a paper for C++20 has not been implemented in libc++, then there will be no
2214+
# FTM entry in implemented_ftms for C++23 and later.
2215+
#
2216+
# Typically standard_ftms is not used with invalid values in the code, but
2217+
# guard just in case.
2218+
if not std in self.implemented_ftms[ftm].keys() or not std in self.standard_ftms[ftm].keys():
2219+
return False
2220+
2221+
return self.implemented_ftms[ftm][std] == self.standard_ftms[ftm][std]
2222+
2223+
22092224
@functools.cached_property
22102225
def ftm_metadata(self) -> Dict[Ftm, Metadata]:
22112226
"""Returns the metadata of the FTMs defined in the Standard.
@@ -2239,7 +2254,7 @@ def version_header_implementation(self) -> Dict[Std, Dict[Ftm, VersionHeader]]:
22392254
continue
22402255
last_value = value
22412256

2242-
implemented = self.implemented_ftms[ftm][std] == self.standard_ftms[ftm][std]
2257+
implemented = self.is_implemented(ftm, std)
22432258
entry = VersionHeader(
22442259
value,
22452260
implemented,

0 commit comments

Comments
 (0)