Hello All (I am playing with C++11, but I am not a C++ expert, and I don't know the C++ front-end part of GCC, so this is a feature wish only).
Perhaps it could be useful for some later (4.8?) release of GCC to produce an inferred type annotation file. For those knowing Ocaml, I was thinking of something similar to the -annot (or -dtypes) option of the ocaml or ocamlopt compiler. http://caml.inria.fr/pub/docs/manual-ocaml/manual022.html For instance with the simplistic (single line) Ocaml file incr.ml: let f x = x + 1;; the incr.annot file obtained with ocamlc -annot incr.ml contains ####### "incr.ml" 1 0 4 "incr.ml" 1 0 5 type( int -> int ) ident( def f "incr.ml" 1 0 15 "_none_" 1 0 -1 ) "incr.ml" 1 0 6 "incr.ml" 1 0 7 type( int ) ident( def x "incr.ml" 1 0 10 "incr.ml" 1 0 15 ) "incr.ml" 1 0 10 "incr.ml" 1 0 11 type( int ) ident( int_ref x "incr.ml" 1 0 6 "incr.ml" 1 0 7 ) "incr.ml" 1 0 12 "incr.ml" 1 0 13 type( int -> int -> int ) ident( ext_ref Pervasives.( + ) ) "incr.ml" 1 0 14 "incr.ml" 1 0 15 type( int ) "incr.ml" 1 0 10 "incr.ml" 1 0 15 type( int ) ############ and external editors (in particular the ocaml or tuareg modes of Emacs) are able to parse such annotation file, and interactively to show the type (with Ctrl-C Ctrl-T under emacs) at the cursor's position. The main motivation would be to help C++ newbies, not C++ experts (those know well enough the C++ language, and don't need help). With the type inference abilities given by the auto keyword, it is sometimes hard for a beginner to understand what type is some particular expression in his code (or what exactly function is called in an overloaded context). The type annotation file can be generated by C++ front-end, and would contain type and position information for every expression inside a source file. That type annotation produced by g++ would be usable by external editors, etc. Of course, such a thing could be done by some GCC plugin, but I believe providing the feature inside GCC itself, and documenting the format of the textual type annotation file, would give this feature more visibility, and it would help people a lot. And I am pretty certain that the C++ frontend does compute the type of each expression, so it is mostly the point of defining a textual type annotation format and output it. The point is that inside languages with type inferences, like C++ is becoming in its 2011 standard, newbies are helped a lot with type annotations (and the editor's support of them) - but experts rarely need this. So I would dream of a -fannotate-type option to g++ 4.8 with a section in the documentation describing the format of the type annotation file. We already have -M (etc..) options to help about include dependencies. We could have some other option to help about type inferences. Regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mine, sont seulement les miennes} ***