About Clang-Tidy inspection

Answered

Point is not a constructor that is callable with a single argument but Clang-Tidy marks it should be modified.

What is the condition that this warning pops up?

0
3 comments

Hi! Please provide a standalone code sample illustrating the issue.

0
Avatar
Permanently deleted user
#include <iostream>

template <typename T>
class Point {
private:
  T xpos, ypos;

public:
  Point(T x = 0, T y = 0) : xpos(x), ypos(y) {}

  void ShowPosition() const {
    std::cout << "[" << xpos << ", " << ypos << "]" << std::endl;
  }
};

int main() {
  Point<int> pos(3, 4);
  pos1.ShowPosition();

  return 0;
}
0

Since

Point(T x = 0, T y = 0) : xpos(x), ypos(y) {}

has default values for both parameters, it can be called with one argument provided and therefore it can be used for implicit conversions. I mean, technically the warning is correct. Don't you agree with it?

0

Please sign in to leave a comment.