1

As you can see below, clang is giving me the same warning twice - once in the implementation file and one in the main file where I do run the program. Is there anyway to stop this happening? I have the standard header guard in device.h and I'm not sure how to get rid of this.

    In file included from device.cpp:1:
    ./device.h:35:4: warning: field 'm_new_depth_frame' will be initialized after
          field 'depthMat' [-Wreorder]
                            m_new_depth_frame(false), depthMat(Size(640,480)...
                            ^
    1 warning generated.
    In file included from kinect_test.cpp:3:
    ./device.h:35:4: warning: field 'm_new_depth_frame' will be initialized after
          field 'depthMat' [-Wreorder]
                            m_new_depth_frame(false), depthMat(Size(640,480)...
                            ^
    1 warning generated.

To clarify, this warning is fine by me (its from a third party library) - I just feel like there is no need to be warned twice.

chris
  • 4,840
  • 5
  • 35
  • 66
  • Fix the order of the member variable definitions to be the same order as used initialisation. – πάντα ῥεῖ Oct 12 '14 at 09:17
  • this is not about fixing the warning, rather stopping clang repeat itself. potentially its because I've done something dumb in including that I'm not aware of – chris Oct 12 '14 at 09:19
  • Have a look [here](http://stackoverflow.com/questions/1564937/gcc-warning-will-be-initialized-after). – blackbird Oct 12 '14 at 09:19
  • 2
    Header guards only prevent you from having an included header appearing accidentially multiple times in each single translation unit, not to appear once for all TUs. – πάντα ῥεῖ Oct 12 '14 at 09:21

1 Answers1

3

You will get the warning for each translation unit where the header is included, this is normal and expected, translation units are parsed independently.

To fix the warning, swap order of m_new_depth_frame and depthMat in the member initializer list.

sp2danny
  • 7,488
  • 3
  • 31
  • 53