[cfe-dev] GSoC 2012: Static Function Blacklisting

James K. Lowden jklowden at schemamania.org
Sat Mar 31 11:01:27 PDT 2012


On Thu, 29 Mar 2012 16:51:16 +0000
Michael Han <Michael.Han at autodesk.com> wrote:

> > Can the annotations/attributes in clang be extended in this manner 
> > (ignoring example syntax)?

> You can add any attributes you like but to get them up stream would
> be hard as adding attributes is adding language extension and Clang
> definitely doesn't want to include arbitrary domain specific
> attributes. ...  One idea of extending attribute system is to take a
> look at the Clang "annotate" attribute which you can embedded
> arbitrary literals so technically you can get your own annotation DSL
> inside the "annotate" attribute. 

There is a better way. 

"Decorating" the code to carry meta-information complicates the
compiler and the code unnecessarily. Information that is not input to
the compiler (or direct commentary) is better held elsewhere. Otherwise
the code itself is obscured.  

I know, Doxygen and the rest have long held the opposite, and the
argument has merit in the absence of better tools.  That argues for
better tools, precisely what Clang aims to facilitate.  (Imagine, for
instance, a "compiler" that could match code with its documentation.)  

Like documentation -- because, really, they *are* documentation --
assertions about what the code does or may do are fundamentally
unbounded.  The assertions we might make about re-entrancy (just to
pick one example) certainly need more than one [key]word.  It is not
reduceable to a binary condition like "const". Is it re-entrant,
thread-safe, signal-safe?  More:  Does it rely on or modify global
state?  Does it have side effects or I/O?  Other linkage dependencies?
Has it been reviewed and approved for questionable but legal syntax,
such as rendundant parenthesis?  Who made these assertions, and when?
Who approved them?  Why?  

(Please don't claim any of these are the responsibility of the
version-control system.  A VCS does not parse.  It cannot track
assertions at that level of granularity.)

This "assertion meta-language" is neither C++ nor specific to C++.
It would be much better to address it as such, and not attempt to
shoehorn it into the compiler at the expense of the code's most
perishable and evanescent quality: clarity.  

--jkl



More information about the cfe-dev mailing list