preprocessor warn of duplicate include guard macros?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What if:

./lib1/foo.hpp:
  #ifndef FOO_HPP
  #define FOO_HPP
  ...
  #endif

./lib2/foo.hpp:
  #ifndef FOO_HPP
  #define FOO_HPP
  ...
  #endif
,/main.cpp
  #include "lib1/foo.hpp"
  #include "lib2/foo.hpp"

Is there any cpp option which can warn that
./lib1/foo.hpp and ./lib2/foo.hpp have
the same include guards?

Based on:

https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html#Guard-Macros

I would guess it would be simple to detect this since, according to
that cppinternals link:

  _cpp_pop_file_buffer remembers the controlling macro
  associated with the file. Subsequent calls to
  stack_include_file result in no buffer being pushed if the
  controlling macro is defined, effecting the optimization.

I recently had a need for this because boost/spirit has this
problem and correcting it has been tedious :(

-regards,
Larry





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux