Skip to content

Commit 69fdefe

Browse files
committed
Move check from sema to parse, closes #712
Semantic checks for things the user shouldn't be able to write even as input to a metafunction can be done early, in `parse` Other semantic checks go in `sema` so that metafunctions have more liberty to take otherwise-incomplete definitions and complete them with the metafunction's own defaults (or do things like remove a member and replace it with something else that is complete)
1 parent 3da9ccc commit 69fdefe

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8928:1358
2+
cppfront compiler v0.2.1 Build 8930:0819
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8928:1431"
1+
"8930:0819"

source/parse.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7981,6 +7981,23 @@ class parser
79817981
}
79827982
}
79837983

7984+
// A type initializer must be a compound expression
7985+
if (
7986+
n->is_type()
7987+
&& !is_parameter
7988+
&& (
7989+
!n->initializer
7990+
|| !n->initializer->is_compound()
7991+
)
7992+
)
7993+
{
7994+
errors.emplace_back(
7995+
n->position(),
7996+
"a user-defined type initializer must be a compound-expression consisting of declarations"
7997+
);
7998+
return {};
7999+
}
8000+
79848001
// If this is a type with metafunctions, apply those
79858002
if (n->is_type()) {
79868003
if (!apply_type_metafunctions(*n)) {

source/reflect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ declaration_base::declaration_base(declaration_base const& that)
937937
auto declaration::mark_for_removal_from_enclosing_type() & -> void
938938

939939
{
940-
cpp2::Default.expects(parent_is_type(), "");
940+
cpp2::Type.expects(parent_is_type(), "");
941941
#line 285 "reflect.h2"
942942
auto test {CPP2_UFCS_0(type_member_mark_for_removal, (*cpp2::assert_not_null(n)))};
943943
cpp2::Default.expects(std::move(test), ""); // ... to ensure this assert is true

source/reflect.h2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ declaration: @polymorphic_base @copyable type =
280280
parent_is_polymorphic: (this) -> bool = n*.parent_is_polymorphic();
281281

282282
mark_for_removal_from_enclosing_type: (inout this)
283-
[[pre: parent_is_type()]] // this precondition should be sufficient ...
283+
[[pre Type: parent_is_type()]] // this precondition should be sufficient ...
284284
= {
285285
test := n*.type_member_mark_for_removal();
286286
[[assert: test]] // ... to ensure this assert is true

source/sema.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,20 +1031,6 @@ class sema
10311031
return false;
10321032
}
10331033

1034-
// A type initializer must be a compound expression
1035-
if (
1036-
n.is_type()
1037-
&& n.initializer
1038-
&& !n.initializer->is_compound()
1039-
)
1040-
{
1041-
errors.emplace_back(
1042-
n.position(),
1043-
"a user-defined type initializer must be a compound-expression consisting of declarations"
1044-
);
1045-
return false;
1046-
}
1047-
10481034
// A namespace must be initialized with a compound expression
10491035
if (
10501036
n.is_namespace()

0 commit comments

Comments
 (0)