Skip to content

Commit 27a13a8

Browse files
committed
Correct get_declaration_of not to skip first symbol
When lookig backward there for loop will never check symbols.cbegin() as it is excluded by `i != symbols.cbegin()` condition. Change normal iterators to `std::reverse_iterator`.
1 parent df15969 commit 27a13a8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

source/sema.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ class sema
244244

245245
// Then look backward to find the first declaration of
246246
// this name that is not deeper (in a nested scope)
247-
for ( ; i != symbols.cbegin(); --i )
247+
for (auto ri = std::make_reverse_iterator(i+1); ri != symbols.crend(); ++ri )
248248
{
249-
if (i->sym.index() == symbol::active::declaration && i->depth <= depth)
249+
if (ri->sym.index() == symbol::active::declaration && ri->depth <= depth)
250250
{
251-
auto const& decl = std::get<symbol::active::declaration>(i->sym);
251+
auto const& decl = std::get<symbol::active::declaration>(ri->sym);
252252

253253
assert(decl.declaration);
254254
if (
@@ -261,7 +261,7 @@ class sema
261261
if (decl.identifier && *decl.identifier == t) {
262262
return &decl;
263263
}
264-
depth = i->depth;
264+
depth = ri->depth;
265265
}
266266
}
267267

0 commit comments

Comments
 (0)