Skip to content

Commit c0a4278

Browse files
committed
Move is_template_scope to parent as it holds the id_class member
1 parent 44cb7c9 commit c0a4278

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/cpp/cpp_id.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class cpp_idt
7070
return id_class==id_classt::TYPEDEF;
7171
}
7272

73+
bool is_template_scope() const
74+
{
75+
return id_class==id_classt::TEMPLATE_SCOPE;
76+
}
77+
7378
irep_idt identifier, base_name;
7479

7580
// if it is a member or method, what class is it in?

src/cpp/cpp_scope.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ class cpp_scopet:public cpp_idt
8181
id_class==id_classt::NAMESPACE;
8282
}
8383

84-
bool is_template_scope() const
85-
{
86-
return id_class==id_classt::TEMPLATE_SCOPE;
87-
}
88-
8984
cpp_scopet &get_parent() const
9085
{
9186
return static_cast<cpp_scopet &>(cpp_idt::get_parent());

src/cpp/cpp_typecheck_template.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ void cpp_typecheckt::typecheck_class_template(
159159
previous_declaration.template_type());
160160
}
161161

162-
assert(cpp_scopes.id_map[symbol_name]->id_class ==
163-
cpp_idt::id_classt::TEMPLATE_SCOPE);
162+
INVARIANT(
163+
cpp_scopes.id_map[symbol_name]->is_template_scope(),
164+
"symbol should be in template scope");
165+
164166
return;
165167
}
166168

@@ -198,8 +200,10 @@ void cpp_typecheckt::typecheck_class_template(
198200

199201
// link the template symbol with the template scope
200202
cpp_scopes.id_map[symbol_name]=&template_scope;
201-
assert(cpp_scopes.id_map[symbol_name]->id_class ==
202-
cpp_idt::id_classt::TEMPLATE_SCOPE);
203+
204+
INVARIANT(
205+
cpp_scopes.id_map[symbol_name]->is_template_scope(),
206+
"symbol should be in template scope");
203207
}
204208

205209
/// typecheck function templates
@@ -301,8 +305,10 @@ void cpp_typecheckt::typecheck_function_template(
301305
id2string(new_symbol->base_name);
302306

303307
// link the template symbol with the template scope
304-
assert(template_scope.id_class==cpp_idt::id_classt::TEMPLATE_SCOPE);
305308
cpp_scopes.id_map[symbol_name] = &template_scope;
309+
INVARIANT(
310+
template_scope.is_template_scope(),
311+
"symbol should be in template scope");
306312
}
307313

308314
/// typecheck class template members; these can be methods or static members

0 commit comments

Comments
 (0)