Search code examples
opencveclipse-cdt

Eclipse CDT syntax error parser false error with Mat assignment: It compiles and runs ok


In this line of code, the x is red underlined as error:

cv::Mat x = cv::Mat::eye(2,2,CV_8U);

with this description:

Invalid arguments '
Candidates are:
 Mat()
 Mat(int, int, int)
 Mat(int, int, int, const cv::Scalar_<double> &)
 ... (it goes on, full error description at the bottom)

It compiles and runs ok.

09:12:02 Build Finished. 0 errors, 0 warnings. (took 1s.721ms)

It used to work fine. I can't tell exactly when this started, but in the middle I updated Eclipse to the last stable version Version: 2019-06 (4.12.0) Build id: 20190614-1200.

It's something with the parser. I'm using elf-parser as error parser (the default configuration for Linux). I tried with c++11 and c++17, and without telling which C++ to use.

The generic false error happens when assigning a MatExpr to a Mat declaration. MatExpr is supposed to be automatically cast to Mat (like it always did). It's too specific to opencv, but sometimes error parser fails to recognize std::endl, so I believe the problem with the parser isn't specific to opencv.

Full error description for completeness, I'm pretty sure there is nothing relevant here:

Invalid arguments '
Candidates are:
 Mat()
 Mat(int, int, int)
 Mat(int, int, int, const cv::Scalar_<double> &)
 Mat(cv::Size_<int>, int)
 Mat(cv::Size_<int>, int, const cv::Scalar_<double> &)
 Mat(int, const int *, int)
 Mat(int, const int *, int, const cv::Scalar_<double> &)
 Mat(const std::vector<int,std::allocator<int>> &, int)
 Mat(const std::vector<int,std::allocator<int>> &, int, const cv::Scalar_<double> &)
 Mat(const cv::Mat &)
 Mat(int, int, int, void *, unsigned long int)
 Mat(cv::Size_<int>, int, void *, unsigned long int)
 Mat(const std::vector<#0,std::allocator<#0>> &, bool)
 Mat(std::initializer_list<#0>)
 Mat(std::initializer_list<int>, std::initializer_list<#0>)
 Mat(const std::array<#0,unsigned long int3 #1 0> &, bool)
 Mat(const cv::Vec<#0,int3 #1 0> &, bool)
 Mat(const cv::Matx<#0,int3 #1 0,int3 #2 0> &, bool)
 Mat(const cv::Point_<#0> &, bool)
 Mat(const cv::Point3_<#0> &, bool)
 Mat(const cv::MatCommaInitializer_<#0> &)
 Mat(const cv::Mat &, const cv::Range &, const cv::Range &)
 Mat(const cv::Mat &, const cv::Rect_<int> &)
 Mat(const cv::Mat &, const cv::Range *)
 Mat(const cv::Mat &, const std::vector<cv::Range,std::allocator<cv::Range>> &)
 Mat(cv::Mat &&)
 Mat(int, const int *, int, void *, const unsigned long int *)
 Mat(const std::vector<int,std::allocator<int>> &, int, void *, const unsigned long int *)
 Mat(const cv::cuda::GpuMat &)
'

Solution

  • This is a bug in Eclipse's C++ parser, filed as bug 550397.

    UPDATE: I also have a fix for it.