Why does clang seem to inconsistently issue -Wpessimizing-move

Viewed 136

Why does clang issue a -Wpessimizing-move for the first function, but not the second function?

Is it because the template function 'may or may not' be instantiated with a 'true/false'? If that is the case, why is the warning not issued when the template is instantiated with true?

Compiling with -Wall or -Wpessimizing-move.

#include <iostream>
#include <vector>
auto internal_constexpr()  {
    constexpr bool foo = true;
    if constexpr(foo){
        std::vector<int> a{1,3,3,4};
        return std::move(a);
    }else{
        return std::vector<int>{1,2,3,4};
    }
}

template<bool foo>
auto template_param()  {
    if constexpr(foo){
        std::vector<int> a{1,2,3,4};
        return std::move(a);
    }else{
        return std::vector<int>{1,2,3,4};
    }
}

int main(){
  auto a = template_param<true>();
  auto b = internal_constexpr();
  std::cout << a.size() << ", " << b.size();
}
0 Answers
Related