Search code examples
cgccpragma

How to ignore "useless storage class" with gcc using -Werror?


I compile my project with -Werror to make sure all of my code is without recognizable warnings. However my current project has a third-party dependency that has an issue in it which causes a warning - and that warning fails my build because of the -Werror flag.

I want to use the -Werror flag and I don't want to correct the third-party package. Is there a way to ignore this warning?

package.h:126:1: error: useless storage class specifier in empty declaration [-Werror]
 };

The line of code that generates the error is a struct definition with a "dangling" typedef.

typedef struct my_data_obj {
  char* data;
  uint32_t data_size;
};

This is obviously a mistake - but I can't find any pragma or any such mechanic to ignore the warning generated from that header file. Any ideas?

EDIT: SOLUTION

Though I'm accepting Florian Weimer's answer because it answers the question most closely it's not the actual fix I settled with. I'll describe that bellow. By including the headers as system headers I did exactly what I wanted to do - suppress the error without having to fix the package.

What I finally did was create a patch file and simply apply that patch each time the project is built.

vim package.h
# fix the file
git add package.h
git diff --cached > package.h.patch

# on build time
git apply package.h.patch

Solution

  • I assume that you want to include package.h from files where you want to enable -Werror.

    GCC does not have a separate flag to control this warning, otherwise the compiler would have printed it. With the separate flag, you could have used #pragma GCC diagnostics ignore, as indicated in the other answers, possibly with a wrapper header file.

    However, you could put the header file into a separate directory, and instead of using -I to add it to the include path, use -isystem. As a result, the header file is treated as a system header, and unless you also compile with -Wsystem-headers, warnings in system headers are suppressed.