Search code examples
c++gccgcc-warning

Disable "unused function" for specific function name


I'm compiling project with "Treat warnings as errors".

The problem is, I need incremental type list from here:

https://stackoverflow.com/a/24092000/508023

And GCC rightfully complains that a set of declared static functions is neither defined nor used. I don't want to disable this diagnostic completely. Instead, I'd like to disable it only for functions with specific name. Is there such possibility? Maybe some attribute? Or compilation option?

Clarification: I don't need to disable warning for a specified piece of file. I need to disable it for a specific function.

EDIT: I was able to solve my issue by using ADL-based trick. So question isn't actual anymore.


Solution

  • This is best done with the __attribute__((unused)) GCC extension, as in the code below:

    namespace {
        void f() __attribute__((unused));
        void g();
    
        void f() {}
        void g() {}
    }
    
    int main() {/*f(); g();*/ return 0;}