Skip to content

Build with -Werror=declaration-after-statement

Michael Catanzaro requested to merge mcatanzaro/declaration-after-statement into master

Historically, Epiphany did not permit declarations after the first statement in a block due to its use of AX_COMPILER_FLAGS, which adds -Werror=declaration-after-statement when compiling C files. But I dropped this in switching to meson, thinking we would adopt a more modern code style.

There are two schools of thought here:

(1) It's safest and cleanest to limit variable declarations to the smallest-possible scope. I'm a firm believer in this rule and I almost always follow it when writing C++. (2) It just doesn't look very good in C, especially with GNOME code style.

I'm starting to become sympathetic to (2). Especially now that we are starting to use autofrees and autoptrs all over the place, I find that declaring these at point of first use causes the code to become rather cluttered.

There is not much code in Epiphany that violates the rule because we only recently began to allow it, so not much to clean up.

The only code that really does not benefit from this is the profile migrator code, which probably overuses local variables. I'd call that an exception rather than the rule.

Let's sneak in -Werror=implicit-function-declaration at the same time, since this is always a serious bug.

Merge request reports