Spurious warning gcc -Wuninitialized

OS: Debian 9

compiler: gcc 8.2.0 (installed from buster (testing) repository)

I know that using things from debian testing branch is dangerous, but debian testing is usually stable, and gcc 8.2 has been released as stable, so it shouldn't have many bugs.

in this function:

int user_tui        (const char *title, const char *subtitle)
{
    int action;
//  action  = USER_IFACE_ACT_FOO;

    show_help();
    user_tui_show_log(title, subtitle);
    action  = usr_input();

    return  action;
}

It is reporting the following error (-Wall -Werror and also -O3 -march=native):

/.../modules//user//src//user_tui.c: In function ‘user_tui’:
/.../modules//user//src//user_tui.c:91:9: error: ‘action’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  return action;
         ^~~~~~
cc1: all warnings being treated as errors

When I uncomment the initialization, the error is still there. I think it shouldn't even be needed, as there is no conditional or anything that would ever block the assignment action = usr_input();.

Is it a spurious warning, or is it legit?

I would say it is a bug in gcc; it can't even be considered spurious.

Upvotes: 1

Views: 147

Answers (1)

Thanks to @MaximEgorushkin for noting that I should look inside usr_input().

The error is in usr_input() and not in user_tui().

It has a very long switch with many switches inside, and in one of them I forgot the default: entry.

So lesson: look recursively inside functions to see if they are really initialized.

I think gcc should let us know that!

Upvotes: 1

Related Questions