Skip to content

bugprone-branch-clone false positive with template functions and constexpr #43574

@pavelkryukov

Description

@pavelkryukov
Bugzilla Link 44229
Resolution FIXED
Resolved on Jan 22, 2020 16:07
Version unspecified
OS All
Blocks #43900
CC @JonasToth,@zmodem,@pavelkryukov
Fixed by commit(s) rGf9c46229e4ac29053747c96e08c574c6c48d544b

Extended Description

Consider following example:

cat tidy-error.cpp

template<int y, typename T> void foo(T&&...);

template
void bar()
{
if constexpr ( x == 2)
foo<6>( 3);
else if constexpr ( x == 3)
foo<8>( 4.5);
else
foo<23>( "hello");
}

template void bar<2>();
template void bar<0>();

The expected output is no error, however:

clang-tidy-9 tidy-error.cpp -checks='bugprone-branch-clone' -extra-arg=-std=c++17

1 warning generated.
tidy-error.cpp:7:9: warning: repeated branch in conditional chain [bugprone-branch-clone]
foo<6>( 3);
^
/mnt/d/Dev/tidy-error.cpp:7:12: note: end of the original
foo<6>( 3);
^
/mnt/d/Dev/tidy-error.cpp:9:9: note: clone 1 starts here
foo<8>( 4.5);
^

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions