Skip to content

Commit 91163e0

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 b1754db commit 91163e0

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
// Don't look beyond the current function
254254
assert(decl.declaration);
@@ -260,7 +260,7 @@ class sema
260260
if (decl.identifier && *decl.identifier == t) {
261261
return &decl;
262262
}
263-
depth = i->depth;
263+
depth = ri->depth;
264264
}
265265
}
266266

0 commit comments

Comments
 (0)