Skip to content

Commit 1764f0c

Browse files
committed
Emit requires clause for variable template, closes #607
And update GCC 10 diagnostic
1 parent ce8f8bc commit 1764f0c

19 files changed

+82
-59
lines changed

include/cpp2util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,10 +1755,10 @@ using cpp2::cpp2_new;
17551755
// See commit 5a0d77f8e297902c0b9712c5aafb6208cfa4c139.
17561756
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ == 10
17571757
#define CPP2_REQUIRES(...) /* empty */
1758-
#define CPP2_REQUIRES_MEMFN(...) static_assert(false, "GCC 11 or higher is required to support type-scope functions that have a 'requires' clause. This includes a '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.")
1758+
#define CPP2_REQUIRES_(...) static_assert(false, "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.")
17591759
#else
17601760
#define CPP2_REQUIRES(...) requires (__VA_ARGS__)
1761-
#define CPP2_REQUIRES_MEMFN(...) requires (__VA_ARGS__)
1761+
#define CPP2_REQUIRES_(...) requires (__VA_ARGS__)
17621762
#endif
17631763

17641764
#endif

regression-tests/pure2-requires-clauses.cpp2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ f: <T: type, U: type>
1515
return a * b;
1616
}
1717

18+
v: <T> const T requires std::same_as<T, i32> = 0;
19+
1820
main: () = {
1921
x: X<int,int> = ();
2022
std::cout << f<int,int>(2,5);

regression-tests/test-results/clang-12/pure2-bugfix-for-non-local-initialization.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-12/pure2-bugfix-for-non-local-initialization.cpp.output

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
true
22
false
3-
./test.exe
3+
"test.exe"

regression-tests/test-results/gcc-10/pure2-bugfix-for-non-local-initialization.cpp.execution

Whitespace-only changes.

regression-tests/test-results/gcc-10/pure2-bugfix-for-non-local-initialization.cpp.output

Whitespace-only changes.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:36: error: expected ‘;’ at end of member declaration
22
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
3-
../../../include/cpp2util.h:1758:52: error: static assertion failed: GCC 11 or higher is required to support type-scope functions that have a 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)' - if you must use GCC 10, use 'forward s: _' instead
4-
1758 | #define CPP2_REQUIRES_MEMFN(...) static_assert(false, "GCC 11 or higher is required to support type-scope functions that have a 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)' - if you must use GCC 10, use 'forward s: _' instead")
5-
| ^~~~~
6-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_MEMFN
3+
../../../include/cpp2util.h:1758: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.
4+
1758 | #define CPP2_REQUIRES_(...) static_assert(false, "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.")
5+
| ^~~~~
6+
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_
77
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:46: error: expected ‘;’ at end of member declaration
88
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
9-
../../../include/cpp2util.h:1758:52: error: static assertion failed: GCC 11 or higher is required to support type-scope functions that have a 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)' - if you must use GCC 10, use 'forward s: _' instead
10-
1758 | #define CPP2_REQUIRES_MEMFN(...) static_assert(false, "GCC 11 or higher is required to support type-scope functions that have a 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)' - if you must use GCC 10, use 'forward s: _' instead")
11-
| ^~~~~
12-
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_MEMFN
9+
../../../include/cpp2util.h:1758: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.
10+
1758 | #define CPP2_REQUIRES_(...) static_assert(false, "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.")
11+
| ^~~~~
12+
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_
1313
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:3: error: no declaration matches ‘element::element(auto:80&&) requires is_same_v<typename std::remove_cv<typename std::remove_reference<decltype(element::__ct ::n)>::type>::type, std::__cxx11::string>’
1414
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:11: note: candidates are: ‘element::element(const element&)’
1515
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:20: note: ‘template<class auto:78> element::element(auto:78&&)’
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
In file included from pure2-requires-clauses.cpp:7:
2+
../../../include/cpp2util.h:1758:33: error: expected unqualified-id before ‘static_assert’
3+
1758 | #define CPP2_REQUIRES_(...) static_assert(false, "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.")
4+
| ^~~~~~~~~~~~~
5+
pure2-requires-clauses.cpp2:19:1: note: in expansion of macro ‘CPP2_REQUIRES_’

regression-tests/test-results/gcc-13/pure2-bugfix-for-non-local-initialization.cpp.execution

Whitespace-only changes.

0 commit comments

Comments
 (0)