[PATCH, RFC] plugin to warn about surplus includes

Bernhard Reutner-Fischer rep.dot.nop@gmail.com
Tue May 18 20:56:00 GMT 2010


Hi,

A couple of days ago i was asking:
does any frontend support some sort of noting that a user-header was
included but no decl of it was ever referenced (i.e. superfluous
#include) ?

I could not find an appropriate tool to diagnose them, so i was thinking
about a gcc plugin to do that.

Would some plugin like the attached be suitable to put into svn if
cleaned up a bit?
If so, where would they live?

Observations while thinking about all this:
- libcpp does not record LC_PSEUDO_ENTER (or something like that),
  so pristine libcpp cannot detect duplicate includes, like iostream
  in attached sample input.cc
- should figure out how to print a help-text for the plugin
  Hints?
- should handle structs.

Thanks in advance for hints on the help-text printing or comments about
the overall idea of such a facility.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: warn_include.c
Type: text/x-csrc
Size: 11762 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20100518/7b6e9287/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: input.cc
Type: text/x-c++src
Size: 132 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20100518/7b6e9287/attachment-0001.bin>
-------------- next part --------------
GCC_SRC_DIR ?= /scratch/src/gcc-4.6.orig
GCC_OBJ_DIR ?= /scratch/obj.$(shell uname -m)/gcc-4.6.orig
CC = gcc-4.6.orig-HEAD

SRC_INCS := gcc libcpp/include include
OBJ_INCS := gcc
CPPFLAGS += $(patsubst %,-I$(GCC_SRC_DIR)/%,$(SRC_INCS)) \
		$(patsubst %,-I$(GCC_OBJ_DIR)/%,$(OBJ_INCS))
CFLAGS += -fPIC

warn_include.so: warn_include.c
	$(LINK.c) -shared -o $@ $^

.PHONY: clean
clean:
	rm -f *.o *.so

help:
	@echo gcc-4.6.orig-HEAD -fplugin=./warn_include.so -fplugin-arg-warn_include-missing -fplugin-arg-warn_include-surplus=0 -c -o /dev/null input.cc


More information about the Gcc mailing list