Skip to content

Commit 63a4fe6

Browse files
committed
[RFC][libc++] Testing feature test macro script.
This is a proof-of-concept how we can test the script. Instead of storing the data in the script it's stored in a JSON file so a different file can be used for testing. This is related to the RFC #89499
1 parent 42b193c commit 63a4fe6

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/utils/data/feature_test_macros/test_data.json
2+
3+
import sys
4+
import json
5+
6+
sys.path.append(sys.argv[1])
7+
from generate_feature_test_macro_components import get_table
8+
9+
10+
data = json.load(open(f"{sys.argv[2]}"))
11+
table = get_table(data)
12+
13+
expected = {
14+
"__cpp_lib_any": {
15+
"c++17": "201606L",
16+
"c++20": "201606L",
17+
"c++23": "201606L",
18+
"c++26": "201606L",
19+
},
20+
"__cpp_lib_barrier": {"c++20": "201907L", "c++23": "201907L", "c++26": "201907L"},
21+
"__cpp_lib_format": {
22+
"c++20": "",
23+
"c++23": "",
24+
"c++26": "",
25+
},
26+
"__cpp_lib_variant": {
27+
"c++17": "202102L",
28+
"c++20": "202102L",
29+
"c++23": "202102L",
30+
"c++26": "202102L",
31+
},
32+
}
33+
34+
35+
assert table == expected, f"expected\n{expected}\n\nresult\n{table}"
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
[
2+
{
3+
"name": "__cpp_lib_any",
4+
"values": {
5+
"c++17": {
6+
"201606": [
7+
{
8+
"implemented": true
9+
}
10+
]
11+
}
12+
},
13+
"headers": [
14+
"any"
15+
]
16+
},
17+
{
18+
"name": "__cpp_lib_barrier",
19+
"values": {
20+
"c++20": {
21+
"201907": [
22+
{
23+
"implemented": true
24+
}
25+
]
26+
}
27+
},
28+
"headers": [
29+
"barrier"
30+
],
31+
"test_suite_guard":
32+
"!defined(_LIBCPP_HAS_NO_THREADS) && (!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_SYNC)",
33+
"libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC"
34+
},
35+
{
36+
"name": "__cpp_lib_format",
37+
"values": {
38+
"c++20": {
39+
"201907": [
40+
{
41+
"number": "P0645R10",
42+
"title": "Text Formatting",
43+
"implemented": true
44+
},
45+
{
46+
"number": "P1361R2",
47+
"title": "Integration of chrono with text formatting",
48+
"implemented": false
49+
}
50+
],
51+
"202106": [
52+
{
53+
"number": "P2216R3",
54+
"title": "std::format improvements",
55+
"implemented": true
56+
}
57+
],
58+
"202110": [
59+
{
60+
"number": "P2372R3",
61+
"title": "Fixing locale handling in chrono formatters",
62+
"implemented": false
63+
},
64+
{
65+
"number": "P2418R2",
66+
"title": "FAdd support for std::generator-like types to std::format",
67+
"implemented": true
68+
}
69+
]
70+
},
71+
"c++23": {
72+
"202207": [
73+
{
74+
"number": "P2419R2",
75+
"title": "Clarify handling of encodings in localized formatting of chrono types",
76+
"implemented": false
77+
}
78+
]
79+
},
80+
"c++26": {
81+
"202306": [
82+
{
83+
"number": "P2637R3",
84+
"title": "Member Visit",
85+
"implemented": true
86+
}
87+
],
88+
"202311": [
89+
{
90+
"number": "P2918R2",
91+
"title": "Runtime format strings II",
92+
"implemented": true
93+
}
94+
]
95+
}
96+
},
97+
"headers": [
98+
"format"
99+
]
100+
},
101+
{
102+
"name": "__cpp_lib_variant",
103+
"values": {
104+
"c++17": {
105+
"202102": [
106+
{
107+
"number": "",
108+
"title": "``std::visit`` for classes derived from ``std::variant``",
109+
"implemented": true
110+
}
111+
]
112+
},
113+
"c++20": {
114+
"202106": [
115+
{
116+
"number": "",
117+
"title": "Fully constexpr ``std::variant``",
118+
"implemented": false
119+
}
120+
]
121+
},
122+
"c++26": {
123+
"202306": [
124+
{
125+
"number": "",
126+
"title": "Member visit",
127+
"implemented": true
128+
}
129+
]
130+
}
131+
},
132+
"headers": [
133+
"variant"
134+
]
135+
}
136+
]

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from builtins import range
55
from functools import reduce
6+
import json
67

78

89
def get_libcxx_paths():
@@ -1867,6 +1868,38 @@ def produce_docs():
18671868
f.write(doc_str)
18681869

18691870

1871+
def get_table(data):
1872+
result = dict()
1873+
for feature in data:
1874+
last = None
1875+
entry = dict()
1876+
implemented = True
1877+
for std in get_std_dialects():
1878+
if std not in feature["values"].keys():
1879+
if last == None:
1880+
continue
1881+
else:
1882+
entry[std] = last
1883+
else:
1884+
if last == None:
1885+
last = ""
1886+
if implemented:
1887+
for value in feature["values"][std]:
1888+
for paper in list(feature["values"][std][value]):
1889+
if not paper["implemented"]:
1890+
implemented = False
1891+
break
1892+
if implemented:
1893+
last = f"{value}L"
1894+
else:
1895+
break
1896+
1897+
entry[std] = last
1898+
result[feature["name"]] = entry
1899+
1900+
return result
1901+
1902+
18701903
def main():
18711904
produce_version_header()
18721905
produce_tests()

0 commit comments

Comments
 (0)