Skip to content

Commit 72954e1

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 3736fdd commit 72954e1

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
@@ -2012,7 +2012,8 @@ def get_ftms(
20122012
else:
20132013
break
20142014

2015-
entry[std] = last
2015+
if last:
2016+
entry[std] = last
20162017
result[feature["name"]] = entry
20172018

20182019
return result
@@ -2208,6 +2209,20 @@ def implemented_ftms(self) -> Dict[Ftm, Dict[Std, Optional[Value]]]:
22082209

22092210
return get_ftms(self.__data, self.std_dialects, True)
22102211

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

2244-
implemented = self.implemented_ftms[ftm][std] == self.standard_ftms[ftm][std]
2259+
implemented = self.is_implemented(ftm, std)
22452260
entry = VersionHeader(
22462261
value,
22472262
implemented,

0 commit comments

Comments
 (0)