diff --git a/regression-tests/pure2-concept-definition.cpp2 b/regression-tests/pure2-concept-definition.cpp2 index 3ab3679c06..dfed273287 100644 --- a/regression-tests/pure2-concept-definition.cpp2 +++ b/regression-tests/pure2-concept-definition.cpp2 @@ -1,5 +1,7 @@ -arithmetic: concept = std::integral || std::floating_point; -main: () = { +arithmetic: concept = std::integral || std::floating_point; +t: @struct type requires arithmetic = { } +main: () = { [[assert Testing: arithmetic]] [[assert Testing: arithmetic]] + [[assert Testing: !arithmetic>]] } diff --git a/regression-tests/test-results/pure2-concept-definition.cpp b/regression-tests/test-results/pure2-concept-definition.cpp index ed953adea2..ba5404d5d8 100644 --- a/regression-tests/test-results/pure2-concept-definition.cpp +++ b/regression-tests/test-results/pure2-concept-definition.cpp @@ -6,21 +6,26 @@ #include "cpp2util.h" - +#line 1 "pure2-concept-definition.cpp2" +template concept arithmetic = std::integral || std::floating_point; +template requires( arithmetic ) +class t; //=== Cpp2 type definitions and function declarations =========================== -#line 1 "pure2-concept-definition.cpp2" -template concept arithmetic = std::integral || std::floating_point; -auto main() -> int; + +#line 2 "pure2-concept-definition.cpp2" +template requires( arithmetic ) +class t {};auto main() -> int; //=== Cpp2 function definitions ================================================= -#line 2 "pure2-concept-definition.cpp2" - auto main() -> int { +#line 3 "pure2-concept-definition.cpp2" +auto main() -> int { cpp2::Testing.expects(arithmetic, ""); cpp2::Testing.expects(arithmetic, ""); + cpp2::Testing.expects(!(arithmetic>), ""); } diff --git a/regression-tests/test-results/pure2-statement-parse-error.cpp2.output b/regression-tests/test-results/pure2-statement-parse-error.cpp2.output index 1d27c1b4bc..6f7d02b13d 100644 --- a/regression-tests/test-results/pure2-statement-parse-error.cpp2.output +++ b/regression-tests/test-results/pure2-statement-parse-error.cpp2.output @@ -1,3 +1,3 @@ pure2-statement-parse-error.cpp2... -pure2-statement-parse-error.cpp2(3,9): error: Could not parse statement (at 'b') +pure2-statement-parse-error.cpp2(3,9): error: Invalid statement encountered inside a compound-statement (at 'b') diff --git a/source/cppfront.cpp b/source/cppfront.cpp index 02c0658c42..a3995b23d3 100644 --- a/source/cppfront.cpp +++ b/source/cppfront.cpp @@ -4862,12 +4862,13 @@ class cppfront return; } - // In phase 0, only need to consider namespaces and types + // In phase 0, only need to consider namespaces, types, and concepts if ( printer.get_phase() == printer.phase0_type_decls && !n.is_namespace() && !n.is_type() + && !n.is_concept() ) { return; @@ -5135,7 +5136,7 @@ class cppfront ) && ( !n.is_concept() - || printer.get_phase() == printer.phase1_type_defs_func_decls + || printer.get_phase() == printer.phase0_type_decls ) ) { @@ -5790,6 +5791,11 @@ class cppfront else if ( n.is_object() && ( + ( + n.is_concept() + && printer.get_phase() == printer.phase0_type_decls + ) + || ( n.parent_is_namespace() && printer.get_phase() >= printer.phase1_type_defs_func_decls @@ -5809,7 +5815,7 @@ class cppfront { auto& type = std::get(n.type); if ( - printer.get_phase() == printer.phase2_func_defs + printer.get_phase() != printer.phase0_type_decls && type->is_concept() ) {