gcc warning" 'will be initialized after'

前端 未结 7 798
走了就别回头了
走了就别回头了 2020-12-22 16:38

I am getting a lot of these warnings from 3rd party code that I cannot modify. Is there a way to disable this warning or at least disable it for certain areas (like #pragma

相关标签:
7条回答
  • 2020-12-22 17:16

    You can disable it with -Wno-reorder.

    0 讨论(0)
  • 2020-12-22 17:18

    The order of initialization doesn’t matter. All fields are initialized in the order of their definition in their class/struct. But if the order in initialization list is different gcc/g++ generate this warning. Only change the initialization order to avoid this warning. But you can't define field using in initialization before its construct. It will be a runtime error. So you change the order of definition. Be careful and keep attention!

    0 讨论(0)
  • 2020-12-22 17:20

    use -Wno-reorder (man gcc is your friend :) )

    0 讨论(0)
  • 2020-12-22 17:22

    If you're seeing errors from library headers and you're using GCC, then you can disable warnings by including the headers using -isystem instead of -I.

    Similar features exist in clang.

    If you're using CMake, you can specify SYSTEM for include_directories.

    0 讨论(0)
  • 2020-12-22 17:28

    Make sure the members appear in the initializer list in the same order as they appear in the class

    Class C {
       int a;
       int b;
       C():b(1),a(2){} //warning, should be C():a(2),b(1)
    }
    

    or you can turn -Wno-reorder

    0 讨论(0)
  • 2020-12-22 17:32

    For those using QT having this error, add this to .pro file

    QMAKE_CXXFLAGS_WARN_ON += -Wno-reorder
    
    0 讨论(0)
提交回复
热议问题