Exemplo n.º 1
0
void CheckExceptionSafety::destructors()
{
    const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();

    // Perform check..
    const std::size_t functions = symbolDatabase->functionScopes.size();
    for (std::size_t i = 0; i < functions; ++i) {
        const Scope * scope = symbolDatabase->functionScopes[i];
        const Function * j = scope->function;
        if (j) {
            // only looking for destructors
            if (j->type == Function::eDestructor) {
                // Inspect this destructor.
                for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
                    // Skip try blocks
                    if (Token::simpleMatch(tok, "try {")) {
                        tok = tok->next()->link();
                    }

                    // Skip uncaught execptions
                    if (Token::simpleMatch(tok, "if ( ! std :: uncaught_exception ( ) ) {")) {
                        tok = tok->next()->link(); // end of if ( ... )
                        tok = tok->next()->link(); // end of { ... }
                    }

                    // throw found within a destructor
                    if (tok->str() == "throw") {
                        destructorsError(tok);
                        break;
                    }
                }
            }
        }
    }
}
Exemplo n.º 2
0
void CheckExceptionSafety::destructors()
{
    const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();

    // Perform check..
    for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
        for (std::list<Function>::const_iterator j = i->functionList.begin(); j != i->functionList.end(); ++j) {
            // only looking for destructors
            if (j->type == Function::eDestructor && j->functionScope) {
                // Inspect this destructor..
                for (const Token *tok = j->functionScope->classStart->next(); tok != j->functionScope->classEnd; tok = tok->next()) {
                    // Skip try blocks
                    if (Token::simpleMatch(tok, "try {")) {
                        tok = tok->next()->link();
                    }

                    // throw found within a destructor
                    if (tok->str() == "throw") {
                        destructorsError(tok);
                        break;
                    }
                }
            }
        }
    }
}
Exemplo n.º 3
0
void CheckExceptionSafety::destructors()
{
    // This is a style error..
    if (!_settings->_checkCodingStyle)
        return;

    // Perform check..
    for (const Token * tok = _tokenizer->tokens(); tok; tok = tok->next())
    {
        if (Token::simpleMatch(tok, ") {"))
            tok = tok->next()->link();

        if (!Token::Match(tok, "~ %var% ( ) {"))
            continue;

        // Inspect this destructor..
        unsigned int indentlevel = 0;
        for (const Token *tok2 = tok->tokAt(5); tok2; tok2 = tok2->next())
        {
            if (tok2->str() == "{")
            {
                ++indentlevel;
            }

            else if (tok2->str() == "}")
            {
                if (indentlevel <= 1)
                    break;
                --indentlevel;
            }

            else if (tok2->str() == "throw")
            {
                destructorsError(tok2);
                break;
            }
        }
    }
}