Skip to content

Commit b96612d

Browse files
committed
2 parents 60a215c + 2c31da2 commit b96612d

File tree

7 files changed

+63
-2
lines changed

7 files changed

+63
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
arithmetic: <T> concept = std::integral<T> || std::floating_point<T>;
2+
main: () = {
3+
[[assert Testing: arithmetic<i32>]]
4+
[[assert Testing: arithmetic<float>]]
5+
}

regression-tests/test-results/clang-18/pure2-concept-definition.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-concept-definition.cpp.output

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
10+
11+
//=== Cpp2 type definitions and function declarations ===========================
12+
13+
#line 1 "pure2-concept-definition.cpp2"
14+
template<typename T> concept arithmetic = std::integral<T> || std::floating_point<T>;
15+
auto main() -> int;
16+
17+
18+
//=== Cpp2 function definitions =================================================
19+
20+
21+
#line 2 "pure2-concept-definition.cpp2"
22+
auto main() -> int {
23+
cpp2::Testing.expects(arithmetic<cpp2::i32>, "");
24+
cpp2::Testing.expects(arithmetic<float>, "");
25+
}
26+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-concept-definition.cpp2... ok (all Cpp2, passes safety checks)
2+

source/cppfront.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5133,6 +5133,10 @@ class cppfront
51335133
&& printer.get_phase() == printer.phase2_func_defs
51345134
)
51355135
)
5136+
&& (
5137+
!n.is_concept()
5138+
|| printer.get_phase() == printer.phase1_type_defs_func_decls
5139+
)
51365140
)
51375141
{
51385142
printer.print_cpp2("template", n.position());
@@ -5804,10 +5808,18 @@ class cppfront
58045808
)
58055809
{
58065810
auto& type = std::get<declaration_node::an_object>(n.type);
5811+
if (
5812+
printer.get_phase() == printer.phase2_func_defs
5813+
&& type->is_concept()
5814+
)
5815+
{
5816+
return;
5817+
}
58075818

58085819
if (
58095820
printer.get_phase() != printer.phase2_func_defs
58105821
&& n.parent_is_namespace()
5822+
&& !type->is_concept()
58115823
)
58125824
{
58135825
printer.print_cpp2( "extern ", n.position() );
@@ -5871,6 +5883,7 @@ class cppfront
58715883
if (
58725884
n.parent_is_namespace()
58735885
&& printer.get_phase() != printer.phase2_func_defs
5886+
&& !type->is_concept()
58745887
)
58755888
{
58765889
printer.print_cpp2( ";", n.position());
@@ -5882,14 +5895,20 @@ class cppfront
58825895
{
58835896
in_non_rvalue_context.push_back(true);
58845897
printer.add_pad_in_this_line(-100);
5885-
printer.print_cpp2( " {", n.position() );
5898+
if (type->is_concept()) {
5899+
printer.print_cpp2( " = ", n.position() );
5900+
} else {
5901+
printer.print_cpp2( " {", n.position() );
5902+
}
58865903

58875904
push_need_expression_list_parens(false);
58885905
assert( n.initializer );
58895906
emit( *n.initializer, false );
58905907
pop_need_expression_list_parens();
58915908

5892-
printer.print_cpp2( "}", n.position() );
5909+
if (!type->is_concept()) {
5910+
printer.print_cpp2( "}", n.position() );
5911+
}
58935912
in_non_rvalue_context.pop_back();
58945913
}
58955914

source/parse.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,13 @@ struct type_id_node
10461046
return false;
10471047
}
10481048

1049+
auto is_concept() const
1050+
-> bool
1051+
{
1052+
auto tok = get_token();
1053+
return tok && *tok == "concept";
1054+
}
1055+
10491056
auto template_args_count() const
10501057
-> int
10511058
{
@@ -2488,6 +2495,8 @@ struct declaration_node
24882495
{ return type.index() == a_function; }
24892496
auto is_object () const -> bool
24902497
{ return type.index() == an_object; }
2498+
auto is_concept () const -> bool
2499+
{ return type.index() == an_object && get<an_object>(type)->is_concept(); }
24912500
auto is_type () const -> bool
24922501
{ return type.index() == a_type; }
24932502
auto is_namespace() const -> bool

0 commit comments

Comments
 (0)