Skip to content

Commit f5c3f97

Browse files
committed
Change printing requires clauses in all phases
This change use the same rules for all printer phases and prints `CPP2_REQUIRES_` or `CPP2_REQUIRES`
1 parent 8e38516 commit f5c3f97

11 files changed

+35
-41
lines changed

regression-tests/test-results/gcc-10-c++20/mixed-increment-decrement.cpp.output

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ mixed-increment-decrement.cpp2:4:39: error: expected ‘;’ at end of member de
66
In file included from mixed-increment-decrement.cpp:6:
77
../../../include/cpp2util.h:10005:47: error: static assertion failed: GCC 11 or higher is required to support variables and type-scope functions that have a 'requires' clause. This includes a type-scope 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)', which relies on being able to add a 'requires' clause - in that case, use 'forward s: _' instead if you need the result to compile with GCC 10.
88
mixed-increment-decrement.cpp2:5:1: note: in expansion of macro ‘CPP2_REQUIRES_’
9-
mixed-increment-decrement.cpp2:4:32: error: no declaration matches ‘iterator<T>& iterator<T>::operator++() & requires true’
10-
mixed-increment-decrement.cpp2:4:18: note: candidates are: ‘iterator<T> iterator<T>::operator++(int) &’
11-
mixed-increment-decrement.cpp2:4:18: note: ‘iterator<T>& iterator<T>::operator++() &’
12-
mixed-increment-decrement.cpp2:2:28: note: ‘class iterator<T>’ defined here
13-
mixed-increment-decrement.cpp2:4:32: error: no declaration matches ‘iterator<T> iterator<T>::operator++(int) & requires true’
14-
mixed-increment-decrement.cpp2:4:18: note: candidates are: ‘iterator<T> iterator<T>::operator++(int) &’
15-
mixed-increment-decrement.cpp2:4:18: note: ‘iterator<T>& iterator<T>::operator++() &’
16-
mixed-increment-decrement.cpp2:2:28: note: ‘class iterator<T>’ defined here
9+
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
10+
mixed-increment-decrement.cpp2:5:1: note: in expansion of macro ‘CPP2_REQUIRES_’
11+
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
12+
mixed-increment-decrement.cpp2:5:1: note: in expansion of macro ‘CPP2_REQUIRES_’
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1.1 is int? 0
2+
1 is int? 1
3+
4+
s* is Shape? 1
5+
s* is Circle? true
6+
s* is Square? false

regression-tests/test-results/gcc-10-c++20/pure2-bugfix-for-requires-clause-in-forward-declaration.cpp.output

+5-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:46: error: expect
66
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
77
../../../include/cpp2util.h:10005:47: error: static assertion failed: GCC 11 or higher is required to support variables and type-scope functions that have a 'requires' clause. This includes a type-scope 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)', which relies on being able to add a 'requires' clause - in that case, use 'forward s: _' instead if you need the result to compile with GCC 10.
88
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_’
9-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:3: error: no declaration matches ‘element::element(auto:95&&) requires is_same_v<std::__cxx11::string, typename std::remove_cv<typename std::remove_reference<decltype(element::__ct ::n)>::type>::type>’
10-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:11: note: candidates are: ‘element::element(const element&)’
11-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:20: note: ‘template<class auto:93> element::element(auto:93&&)’
12-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:1:7: note: ‘class element’ defined here
9+
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
10+
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_’
1311
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:78: error: expected unqualified-id before ‘{’ token
14-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:8: error: no declaration matches ‘element& element::operator=(auto:96&&) requires is_same_v<std::__cxx11::string, typename std::remove_cv<typename std::remove_reference<decltype(element::operator=::n)>::type>::type>’
15-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:6:16: note: candidates are: ‘void element::operator=(const element&)’
16-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:16: note: ‘template<class auto:94> element& element::operator=(auto:94&&)’
17-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:1:7: note: ‘class element’ defined here
12+
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
13+
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
14+
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_’

regression-tests/test-results/gcc-10-c++20/pure2-print.cpp.output

+6-8
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ In file included from pure2-print.cpp:7:
77
pure2-print.cpp2:68:1: note: in expansion of macro ‘CPP2_REQUIRES_’
88
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
99
pure2-print.cpp2:97:1: note: in expansion of macro ‘CPP2_REQUIRES_’
10-
pure2-print.cpp2:9:41: error: ‘constexpr const T outer::object_alias’ is not a static data member of ‘class outer’
11-
pure2-print.cpp2:9:48: error: template definition of non-template ‘constexpr const T outer::object_alias’
12-
pure2-print.cpp2:67:14: error: no declaration matches ‘void outer::mytype::variadic(const auto:94& ...) requires (is_convertible_v<typename std::remove_cv<typename std::remove_reference<decltype(outer::mytype::variadic::x)>::type>::type, int> && ...)’
13-
pure2-print.cpp2:67:29: note: candidate is: ‘template<class ... auto:93> static void outer::mytype::variadic(const auto:93& ...)’
14-
pure2-print.cpp2:10:19: note: ‘class outer::mytype’ defined here
15-
pure2-print.cpp2:96:37: error: no declaration matches ‘void outer::print(std::ostream&, const Args& ...) requires cpp2::impl::cmp_greater_eq(sizeof ... (Args ...), 0)’
16-
pure2-print.cpp2:96:37: note: no functions named ‘void outer::print(std::ostream&, const Args& ...) requires cpp2::impl::cmp_greater_eq(sizeof ... (Args ...), 0)’
17-
pure2-print.cpp2:6:7: note: ‘class outer’ defined here
10+
../../../include/cpp2util.h:10005:33: error: expected unqualified-id before ‘static_assert’
11+
pure2-print.cpp2:9:1: note: in expansion of macro ‘CPP2_REQUIRES_’
12+
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
13+
pure2-print.cpp2:68:1: note: in expansion of macro ‘CPP2_REQUIRES_’
14+
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
15+
pure2-print.cpp2:97:1: note: in expansion of macro ‘CPP2_REQUIRES_’
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
In file included from pure2-requires-clauses.cpp:7:
22
../../../include/cpp2util.h:10005:33: error: expected unqualified-id before ‘static_assert’
33
pure2-requires-clauses.cpp2:21:1: note: in expansion of macro ‘CPP2_REQUIRES_’
4+
../../../include/cpp2util.h:10005:33: error: expected unqualified-id before ‘static_assert’
5+
pure2-requires-clauses.cpp2:21:1: note: in expansion of macro ‘CPP2_REQUIRES_’
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-type-constraints.cpp2:6:6: error: redefinition of ‘template<class auto:96> void print(const auto:96&)’
2+
pure2-type-constraints.cpp2:2:6: note: ‘template<class auto:93> void print(const auto:93&)’ previously declared here

regression-tests/test-results/mixed-increment-decrement.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ auto operator--(number_line_pre_decrement<1>& x,int) -> number_line_pre_decremen
132132

133133
#line 4 "mixed-increment-decrement.cpp2"
134134
template <typename T> auto iterator<T>::operator++() & -> iterator<T>&
135-
CPP2_REQUIRES (true) {++x; return (*this); }
135+
CPP2_REQUIRES_ (true) {++x; return (*this); }
136136
#line 4 "mixed-increment-decrement.cpp2"
137137
template <typename T> auto iterator<T>::operator++(int) & -> iterator<T>
138-
CPP2_REQUIRES (true) { auto ret = *this; ++*this; return ret; }
138+
CPP2_REQUIRES_ (true) { auto ret = *this; ++*this; return ret; }
139139

140140

141141
template <typename T> iterator<T>::iterator(iterator const& that)

regression-tests/test-results/pure2-bugfix-for-requires-clause-in-forward-declaration.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ auto main() -> int;
3535

3636
#line 3 "pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2"
3737
element::element(auto&& n)
38-
CPP2_REQUIRES (std::is_same_v<std::string, CPP2_TYPEOF(n)>)
38+
CPP2_REQUIRES_ (std::is_same_v<std::string, CPP2_TYPEOF(n)>)
3939
: name{ CPP2_FORWARD(n) }{}
4040
#line 3 "pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2"
4141
auto element::operator=(auto&& n) -> element&
42-
CPP2_REQUIRES (std::is_same_v<std::string, CPP2_TYPEOF(n)>) {
42+
CPP2_REQUIRES_ (std::is_same_v<std::string, CPP2_TYPEOF(n)>) {
4343
name = CPP2_FORWARD(n);
4444
return *this; }
4545

regression-tests/test-results/pure2-print.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ bool testing_enabled {false};
8989

9090
#line 8 "pure2-print.cpp2"
9191
template<typename T>
92-
CPP2_REQUIRES (true) inline CPP2_CONSTEXPR T outer::object_alias{ 42 };
92+
CPP2_REQUIRES_ (true) inline CPP2_CONSTEXPR T outer::object_alias{ 42 };
9393
#line 9 "pure2-print.cpp2"
9494

9595
#line 12 "pure2-print.cpp2"
@@ -163,7 +163,7 @@ CPP2_REQUIRES (true) inline CPP2_CONSTEXPR T outer::object_alias{ 42 };
163163

164164
#line 67 "pure2-print.cpp2"
165165
auto outer::mytype::variadic(auto const& ...x) -> void
166-
CPP2_REQUIRES ((std::is_convertible_v<CPP2_TYPEOF(x), int> && ...)) {(std::cout << ... << x); }
166+
CPP2_REQUIRES_ ((std::is_convertible_v<CPP2_TYPEOF(x), int> && ...)) {(std::cout << ... << x); }
167167

168168
#line 70 "pure2-print.cpp2"
169169
auto outer::test() -> void{
@@ -190,7 +190,7 @@ CPP2_REQUIRES ((std::is_convertible_v<CPP2_TYPEOF(x), int> && ...)) {(std::cout
190190

191191
#line 96 "pure2-print.cpp2"
192192
template<typename ...Args> auto outer::print(std::ostream& out, Args const& ...args) -> void
193-
CPP2_REQUIRES (cpp2::impl::cmp_greater_eq(sizeof...(Args),0u)) {
193+
CPP2_REQUIRES_ (cpp2::impl::cmp_greater_eq(sizeof...(Args),0u)) {
194194
#line 97 "pure2-print.cpp2"
195195
(out << ... << args);
196196
}

regression-tests/test-results/pure2-requires-clauses.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CPP2_REQUIRES (true) { return x; }
7272

7373
#line 20 "pure2-requires-clauses.cpp2"
7474
template<typename T>
75-
CPP2_REQUIRES (std::same_as<T,cpp2::i32>) T const v {0};
75+
CPP2_REQUIRES_ (std::same_as<T,cpp2::i32>) T const v {0};
7676

7777
#line 22 "pure2-requires-clauses.cpp2"
7878
auto main() -> int{

source/to_cpp1.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -5601,15 +5601,8 @@ class cppfront
56015601
{
56025602
printer.print_extra("\n");
56035603
printer.ignore_alignment( true, n.position().colno + 4 );
5604-
if (printer.get_phase() == printer.phase1_type_defs_func_decls) {
5605-
// Workaround GCC 10 not supporting requires in forward declarations in some cases.
5606-
// See commit 5a0d77f8e297902c0b9712c5aafb6208cfa4c139.
5607-
if (n.is_object() || n.parent_is_type()) {
5608-
printer.print_extra("CPP2_REQUIRES_ (");
5609-
}
5610-
else {
5611-
printer.print_extra("CPP2_REQUIRES (");
5612-
}
5604+
if (n.is_object() || n.parent_is_type()) {
5605+
printer.print_extra("CPP2_REQUIRES_ (");
56135606
}
56145607
else {
56155608
printer.print_extra("CPP2_REQUIRES (");

0 commit comments

Comments
 (0)