[cfe-dev] Analyzer question

Erik Verbruggen erikjv at me.com
Fri Feb 11 07:50:49 PST 2011


Hello,

I would like to write static analyses checks for Qt, specifically for the meta-object usage. Qt uses some pre-processor macros which are used by the meta-object compiler (moc) to generate extra code. For example:

class MyObject: public QObject {
	Q_OBJECT // expands to a field declaration and some utility methods

signals: // expands to protected
	void somethingChanged();

public slots: // expands to Q_SLOTS which expands to empty
	void changeSomething();
};

I checked the IBAction/IBOutlet macros, but it looks like they expand to __attribute__((ibaction)) (or iboutlet) when using code completion, and to void/empty when compiling -- meaning: while running the analyzer, they do not end up in the AST.

So, what would be the best way to do it for Qt? If I understand the pre-processing correctly, I would need to do two passes while analysing, or I would need to annotate methods with an additional flag (akin to the ibaction/iboutlet flags) while parsing. I think that annotating while parsing is the most solid way, as one could also use it while doing code-completion or code-navigation.

What do you think? And would such a change/patch be allowed into the clang source tree?

Regards,
Erik Verbruggen.



More information about the cfe-dev mailing list