Skip to content

Commit 6c8bd5b

Browse files
committed
Move is_template_scope to parent as it holds the id_class member
1 parent 611888c commit 6c8bd5b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-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
@@ -85,11 +85,6 @@ class cpp_scopet:public cpp_idt
8585
id_class==id_classt::NAMESPACE;
8686
}
8787

88-
bool is_template_scope() const
89-
{
90-
return id_class==id_classt::TEMPLATE_SCOPE;
91-
}
92-
9388
cpp_scopet &get_parent() const
9489
{
9590
return static_cast<cpp_scopet &>(cpp_idt::get_parent());

src/cpp/cpp_typecheck_template.cpp

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

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

@@ -197,8 +199,10 @@ void cpp_typecheckt::typecheck_class_template(
197199

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

204208
/// typecheck function templates
@@ -300,8 +304,9 @@ void cpp_typecheckt::typecheck_function_template(
300304
id2string(new_symbol->base_name);
301305

302306
// link the template symbol with the template scope
303-
assert(template_scope.id_class==cpp_idt::id_classt::TEMPLATE_SCOPE);
304307
cpp_scopes.id_map[symbol_name] = &template_scope;
308+
INVARIANT(
309+
template_scope.is_template_scope(), "symbol should be in template scope");
305310
}
306311

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

0 commit comments

Comments
 (0)