Например, должна выводиться ошибка, если в классе создается int test и int Test создается в функции класса.
Это уже работает, но текущий код неправильно обрабатывает следующий случай:
Код: Выделить всё
class testclass
{
private:
int avocado;
void banana()
{
if(avocado == 0)
{
int orange = 1;
}
if(avocado == 2)
{
int Orange = 5;
// A warning is issued here although none should be
}
}
};
Это мой метод проверки на данный момент:
Код: Выделить всё
const DeclContext *Context = nullptr;
const auto *Var = Result.Nodes.getNodeAsgetDeclContext();
}
const auto *Field = Result.Nodes.getNodeAs("field");
//binding all variables from classes here
if(Field)
{
Context = Field->getDeclContext();
}
while (Context)
{
for (const auto *Decl : Context->decls())
{
// check whether current variable is already declared in the same scope
if (const auto *PreviousVar = dyn_cast(Decl))
{
if(PreviousVar == Var)
{
continue;
}
CheckforEquality(Var, PreviousVar);
CheckforEquality(Field, PreviousVar);
}
if (const auto *PreviousField = dyn_cast(Decl))
{
if(PreviousField == Field)
{
continue;
}
CheckforEquality(Var, PreviousField);
CheckforEquality(Field, PreviousField);
}
}
Context = Context->getParent();
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... -variables
Мобильная версия