Open Bug 564858 Opened 14 years ago Updated 2 years ago

Warn when a macro is not properly parenthesized

Categories

(Developer Infrastructure :: Source Code Analysis, task, P4)

Tracking

(Not tracked)

People

(Reporter: jrmuizel, Unassigned)

References

Details

At the time of filing cairo has the following macro: #if defined (__GNUC__) #define cairo_container_of(ptr, type, member) ({ \ const __typeof__ (((type *) 0)->member) *mptr__ = (ptr); \ (type *) ((char *) mptr__ - offsetof (type, member)); \ }) #else #define cairo_container_of(ptr, type, member) \ (type *)((char *) (ptr) - (char *) &((type *)0)->member) #endif This macro non __GNUC__ version is missing a set of parenthesis which caused a compile error when used like 'cairo_container_of(p, struct a, foo)->pop' because '->' binds more tightly than casts. It would be nice if we had a static analysis pass that checked whether all of the expression members in a macro remain as a unit in the expression tree. i.e. in the previous example, the '->' operator is inserted into the middle of the macro's expression tree (it has both parent and child expressions that are part of the same macro expansion).
Product: Core → Firefox Build System

Is this something that we still confront with?

Flags: needinfo?(jmuizelaar)
Priority: -- → P5
Type: defect → task
Flags: needinfo?(jmuizelaar)
Priority: P5 → P4
Product: Firefox Build System → Developer Infrastructure
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.