This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: preprocessor warn of duplicate include guard macros?
- From: Hogren <hogren at iiiha dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 25 Jan 2017 22:58:36 +0100
- Subject: Re: preprocessor warn of duplicate include guard macros?
- Authentication-results: sourceware.org; auth=none
- References: <bcf034da-6815-24bc-5da2-ed573367f4c6@suddenlink.net>
On 25/01/2017 06:40, Larry Evans wrote:
> 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
>
Hello,
I think that you may be misunderstand the paragraph. The name of the
file is not remembered. It says just that the block "#ifndef FOO …
#endif" is keeped and this is with this that gcc can take the
"Multiple-Include Optimization".
I think that what you want would be make a good new functionality, but
it's not possible yet.
If you find a error like this in a library, it's very nice to inform
authors, or may be to propose a patch to them.
Regards,
Hogren