Skip to content

clang-tidy readability-else-after-return false positive #110694

Open
@LegalizeAdulthood

Description

@LegalizeAdulthood

Suppose you introduce a variable in the scope of the if statement like so:

    size_t index{};
    if( const auto pos{ std::find( geom->materialIds.begin(), geom->materialIds.end(), proxyMaterialId ) };
        pos == geom->materialIds.end() )
    {
        throw std::runtime_error( "Mismatched material id; expected one of " + toString( geom->materialIds ) + ", got "
                                  + std::to_string( proxyMaterialId ) );
    }
    else
    {
        index = std::distance( geom->materialIds.begin(), pos );
    }

readability-else-after-return doesn't recognize the use of the scoped variable in the else and flags the else after return as a violation. This is a false positive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorclang-tidyfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions