It would be really useful if gcc/cpp had a -Wrecursive-inclusion option. In
essence, this should print warnings if any file, directly or indirectly,
attempts to include itself. I believe that this in most cases is an error, and
since regular header guards will work around the problem (by skipping already
included files), it can lead to unfortunate silent recursive dependencies which
may be hard to get rid of once they have been introduced.

It is possible to do this manually, e.g. internally in each file, such as:


#ifdef X
#warning already included
#else
#define X

/* ... */

#undef X
#endif


However, this is hard to maintain and easy to get wrong. So I suggest the
introduction of a -Wrecursive-inclusion to let cpp do the job.


-- 
           Summary: Feature request: -Wrecursive-inclusion
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: preprocessor
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vegard dot nossum at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36357

Reply via email to