Skip to content

Commit 081c1db

Browse files
committed
[libc++] Implement format_error.
This is the first step at implementing <format>. It adds the <format> header and implements the `format_error`. class. Implemnts parts of: -P0645 Text Formatting Reviewed By: ldionne, #libc, miscco, curdeius Differential Revision: https://reviews.llvm.org/D92214
1 parent 207d4be commit 081c1db

18 files changed

+293
-1
lines changed

libcxx/docs/Cxx2aStatusPaperStatus.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"`P0466 <https://wg21.link/P0466>`__","LWG","Layout-compatibility and Pointer-interconvertibility Traits","Cologne","",""
104104
"`P0553 <https://wg21.link/P0553>`__","LWG","Bit operations","Cologne","|Complete|","9.0"
105105
"`P0631 <https://wg21.link/P0631>`__","LWG","Math Constants","Cologne","|Complete|","11.0"
106-
"`P0645 <https://wg21.link/P0645>`__","LWG","Text Formatting","Cologne","",""
106+
"`P0645 <https://wg21.link/P0645>`__","LWG","Text Formatting","Cologne","|In Progress|",""
107107
"`P0660 <https://wg21.link/P0660>`__","LWG","Stop Token and Joining Thread, Rev 10","Cologne","",""
108108
"`P0784 <https://wg21.link/P0784>`__","CWG","More constexpr containers","Cologne","|Complete|","12.0"
109109
"`P0980 <https://wg21.link/P0980>`__","LWG","Making std::string constexpr","Cologne","",""

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ Status
234234
------------------------------------------------- -----------------
235235
``__cpp_lib_execution`` *unimplemented*
236236
------------------------------------------------- -----------------
237+
``__cpp_lib_format`` *unimplemented*
238+
------------------------------------------------- -----------------
237239
``__cpp_lib_generic_unordered_lookup`` ``201811L``
238240
------------------------------------------------- -----------------
239241
``__cpp_lib_int_pow2`` ``202002L``

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ set(files
9999
fenv.h
100100
filesystem
101101
float.h
102+
format
102103
forward_list
103104
fstream
104105
functional

libcxx/include/format

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// -*- C++ -*-
2+
//===--------------------------- format -----------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP_FORMAT
11+
#define _LIBCPP_FORMAT
12+
13+
/*
14+
15+
namespace std {
16+
// [format.error], class format_error
17+
class format_error : public runtime_error {
18+
public:
19+
explicit format_error(const string& what_arg);
20+
explicit format_error(const char* what_arg);
21+
};
22+
}
23+
24+
*/
25+
26+
#include <__config>
27+
#include <stdexcept>
28+
#include <version>
29+
30+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31+
# pragma GCC system_header
32+
#endif
33+
34+
_LIBCPP_PUSH_MACROS
35+
#include <__undef_macros>
36+
37+
_LIBCPP_BEGIN_NAMESPACE_STD
38+
39+
#if _LIBCPP_STD_VER > 17
40+
41+
class _LIBCPP_EXCEPTION_ABI format_error : public runtime_error {
42+
public:
43+
_LIBCPP_INLINE_VISIBILITY explicit format_error(const string& __s)
44+
: runtime_error(__s) {}
45+
_LIBCPP_INLINE_VISIBILITY explicit format_error(const char* __s)
46+
: runtime_error(__s) {}
47+
virtual ~format_error() noexcept;
48+
};
49+
50+
#endif //_LIBCPP_STD_VER > 17
51+
52+
_LIBCPP_END_NAMESPACE_STD
53+
54+
_LIBCPP_POP_MACROS
55+
56+
#endif // _LIBCPP_FORMAT

libcxx/include/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ module std [system] {
292292
header "filesystem"
293293
export *
294294
}
295+
module format {
296+
header "format"
297+
export *
298+
}
295299
module forward_list {
296300
header "forward_list"
297301
export initializer_list

libcxx/include/version

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ __cpp_lib_exchange_function 201304L <utility>
7272
__cpp_lib_execution 201902L <execution>
7373
201603L // C++17
7474
__cpp_lib_filesystem 201703L <filesystem>
75+
__cpp_lib_format 201907L <format>
7576
__cpp_lib_gcd_lcm 201606L <numeric>
7677
__cpp_lib_generic_associative_lookup 201304L <map> <set>
7778
__cpp_lib_generic_unordered_lookup 201811L <unordered_map> <unordered_set>
@@ -313,6 +314,7 @@ __cpp_lib_void_t 201411L <type_traits>
313314
# define __cpp_lib_erase_if 202002L
314315
# undef __cpp_lib_execution
315316
// # define __cpp_lib_execution 201902L
317+
// # define __cpp_lib_format 201907L
316318
# define __cpp_lib_generic_unordered_lookup 201811L
317319
# define __cpp_lib_int_pow2 202002L
318320
// # define __cpp_lib_integer_comparison_functions 202002L

libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,9 @@
10391039
{'is_defined': True, 'name': '__ZNSt3__112ctype_bynameIwED0Ev', 'type': 'FUNC'}
10401040
{'is_defined': True, 'name': '__ZNSt3__112ctype_bynameIwED1Ev', 'type': 'FUNC'}
10411041
{'is_defined': True, 'name': '__ZNSt3__112ctype_bynameIwED2Ev', 'type': 'FUNC'}
1042+
{'is_defined': True, 'name': '__ZNSt3__112format_errorD0Ev', 'type': 'FUNC'}
1043+
{'is_defined': True, 'name': '__ZNSt3__112format_errorD1Ev', 'type': 'FUNC'}
1044+
{'is_defined': True, 'name': '__ZNSt3__112format_errorD2Ev', 'type': 'FUNC'}
10421045
{'is_defined': True, 'name': '__ZNSt3__112future_errorC1ENS_10error_codeE', 'type': 'FUNC'}
10431046
{'is_defined': True, 'name': '__ZNSt3__112future_errorC2ENS_10error_codeE', 'type': 'FUNC'}
10441047
{'is_defined': True, 'name': '__ZNSt3__112future_errorD0Ev', 'type': 'FUNC'}
@@ -1985,6 +1988,7 @@
19851988
{'is_defined': True, 'name': '__ZTINSt3__112codecvt_baseE', 'size': 0, 'type': 'OBJECT'}
19861989
{'is_defined': True, 'name': '__ZTINSt3__112ctype_bynameIcEE', 'size': 0, 'type': 'OBJECT'}
19871990
{'is_defined': True, 'name': '__ZTINSt3__112ctype_bynameIwEE', 'size': 0, 'type': 'OBJECT'}
1991+
{'is_defined': True, 'name': '__ZTINSt3__112format_errorE', 'size': 0, 'type': 'OBJECT'}
19881992
{'is_defined': True, 'name': '__ZTINSt3__112future_errorE', 'size': 0, 'type': 'OBJECT'}
19891993
{'is_defined': True, 'name': '__ZTINSt3__112strstreambufE', 'size': 0, 'type': 'OBJECT'}
19901994
{'is_defined': True, 'name': '__ZTINSt3__112system_errorE', 'size': 0, 'type': 'OBJECT'}
@@ -2193,6 +2197,7 @@
21932197
{'is_defined': True, 'name': '__ZTSNSt3__112codecvt_baseE', 'size': 0, 'type': 'OBJECT'}
21942198
{'is_defined': True, 'name': '__ZTSNSt3__112ctype_bynameIcEE', 'size': 0, 'type': 'OBJECT'}
21952199
{'is_defined': True, 'name': '__ZTSNSt3__112ctype_bynameIwEE', 'size': 0, 'type': 'OBJECT'}
2200+
{'is_defined': True, 'name': '__ZTSNSt3__112format_errorE', 'size': 0, 'type': 'OBJECT'}
21962201
{'is_defined': True, 'name': '__ZTSNSt3__112future_errorE', 'size': 0, 'type': 'OBJECT'}
21972202
{'is_defined': True, 'name': '__ZTSNSt3__112strstreambufE', 'size': 0, 'type': 'OBJECT'}
21982203
{'is_defined': True, 'name': '__ZTSNSt3__112system_errorE', 'size': 0, 'type': 'OBJECT'}
@@ -2377,6 +2382,7 @@
23772382
{'is_defined': True, 'name': '__ZTVNSt3__112bad_weak_ptrE', 'size': 0, 'type': 'OBJECT'}
23782383
{'is_defined': True, 'name': '__ZTVNSt3__112ctype_bynameIcEE', 'size': 0, 'type': 'OBJECT'}
23792384
{'is_defined': True, 'name': '__ZTVNSt3__112ctype_bynameIwEE', 'size': 0, 'type': 'OBJECT'}
2385+
{'is_defined': True, 'name': '__ZTVNSt3__112format_errorE', 'size': 0, 'type': 'OBJECT'}
23802386
{'is_defined': True, 'name': '__ZTVNSt3__112future_errorE', 'size': 0, 'type': 'OBJECT'}
23812387
{'is_defined': True, 'name': '__ZTVNSt3__112strstreambufE', 'size': 0, 'type': 'OBJECT'}
23822388
{'is_defined': True, 'name': '__ZTVNSt3__112system_errorE', 'size': 0, 'type': 'OBJECT'}

libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,9 @@
726726
{'is_defined': True, 'name': '_ZNSt3__112ctype_bynameIwED0Ev', 'type': 'FUNC'}
727727
{'is_defined': True, 'name': '_ZNSt3__112ctype_bynameIwED1Ev', 'type': 'FUNC'}
728728
{'is_defined': True, 'name': '_ZNSt3__112ctype_bynameIwED2Ev', 'type': 'FUNC'}
729+
{'is_defined': True, 'name': '_ZNSt3__112format_errorD0Ev', 'type': 'FUNC'}
730+
{'is_defined': True, 'name': '_ZNSt3__112format_errorD1Ev', 'type': 'FUNC'}
731+
{'is_defined': True, 'name': '_ZNSt3__112format_errorD2Ev', 'type': 'FUNC'}
729732
{'is_defined': True, 'name': '_ZNSt3__112future_errorC1ENS_10error_codeE', 'type': 'FUNC'}
730733
{'is_defined': True, 'name': '_ZNSt3__112future_errorC2ENS_10error_codeE', 'type': 'FUNC'}
731734
{'is_defined': True, 'name': '_ZNSt3__112future_errorD0Ev', 'type': 'FUNC'}
@@ -1648,6 +1651,7 @@
16481651
{'is_defined': True, 'name': '_ZTINSt3__112codecvt_baseE', 'size': 16, 'type': 'OBJECT'}
16491652
{'is_defined': True, 'name': '_ZTINSt3__112ctype_bynameIcEE', 'size': 24, 'type': 'OBJECT'}
16501653
{'is_defined': True, 'name': '_ZTINSt3__112ctype_bynameIwEE', 'size': 24, 'type': 'OBJECT'}
1654+
{'is_defined': True, 'name': '_ZTINSt3__112format_errorE', 'size': 24, 'type': 'OBJECT'}
16511655
{'is_defined': True, 'name': '_ZTINSt3__112future_errorE', 'size': 24, 'type': 'OBJECT'}
16521656
{'is_defined': True, 'name': '_ZTINSt3__112strstreambufE', 'size': 24, 'type': 'OBJECT'}
16531657
{'is_defined': True, 'name': '_ZTINSt3__112system_errorE', 'size': 24, 'type': 'OBJECT'}
@@ -1776,6 +1780,7 @@
17761780
{'is_defined': True, 'name': '_ZTSNSt3__112codecvt_baseE', 'size': 23, 'type': 'OBJECT'}
17771781
{'is_defined': True, 'name': '_ZTSNSt3__112ctype_bynameIcEE', 'size': 26, 'type': 'OBJECT'}
17781782
{'is_defined': True, 'name': '_ZTSNSt3__112ctype_bynameIwEE', 'size': 26, 'type': 'OBJECT'}
1783+
{'is_defined': True, 'name': '_ZTSNSt3__112format_errorE', 'size': 23, 'type': 'OBJECT'}
17791784
{'is_defined': True, 'name': '_ZTSNSt3__112future_errorE', 'size': 23, 'type': 'OBJECT'}
17801785
{'is_defined': True, 'name': '_ZTSNSt3__112strstreambufE', 'size': 23, 'type': 'OBJECT'}
17811786
{'is_defined': True, 'name': '_ZTSNSt3__112system_errorE', 'size': 23, 'type': 'OBJECT'}
@@ -1908,6 +1913,7 @@
19081913
{'is_defined': True, 'name': '_ZTVNSt3__112bad_weak_ptrE', 'size': 40, 'type': 'OBJECT'}
19091914
{'is_defined': True, 'name': '_ZTVNSt3__112ctype_bynameIcEE', 'size': 104, 'type': 'OBJECT'}
19101915
{'is_defined': True, 'name': '_ZTVNSt3__112ctype_bynameIwEE', 'size': 136, 'type': 'OBJECT'}
1916+
{'is_defined': True, 'name': '_ZTVNSt3__112format_errorE', 'size': 40, 'type': 'OBJECT'}
19111917
{'is_defined': True, 'name': '_ZTVNSt3__112future_errorE', 'size': 40, 'type': 'OBJECT'}
19121918
{'is_defined': True, 'name': '_ZTVNSt3__112strstreambufE', 'size': 128, 'type': 'OBJECT'}
19131919
{'is_defined': True, 'name': '_ZTVNSt3__112system_errorE', 'size': 40, 'type': 'OBJECT'}

libcxx/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(LIBCXX_SOURCES
1212
condition_variable.cpp
1313
condition_variable_destructor.cpp
1414
exception.cpp
15+
format.cpp
1516
functional.cpp
1617
future.cpp
1718
hash.cpp

libcxx/src/format.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===------------------------- format.cpp ---------------------------------===//
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+
#include "format"
10+
11+
_LIBCPP_BEGIN_NAMESPACE_STD
12+
13+
format_error::~format_error() noexcept = default;
14+
15+
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)