Spurious warning gcc -Wuninitialized












0















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.










share|improve this question




















  • 1





    Show the definition of usr_input function.

    – Maxim Egorushkin
    Nov 22 '18 at 13:46











  • Really no conditions, also not in usr_input() itself, maybe by using exceptions which running out of the initializing scope? BTW "gcc 8.2 has been released as stable, so it shouldn't have many bugs." is definitly wrong if you look in the bugtracker. There are "some" open bugs, some are open and unfixed for multiple major versions... But you are right, such an easy to see bug I also would not expect.

    – Klaus
    Nov 22 '18 at 13:49








  • 1





    @Maxim You were right, I had to look inside usr_input(). But I would say that the variable returned by usr_input() is the one that is being used uninitialized, and not action itself. action is really being initialized, although with garbage in the case of an uninitialized return of usr_input(). I would call that a bug in gcc.

    – Cacahuete Frito
    Nov 22 '18 at 14:32













  • Please don't change the topic. Instead use the Accept button at the answer that solved your problem. That's the way how StackOverflow works. It's also okay to accept the own answer.

    – harper
    Nov 22 '18 at 15:04













  • Ok. However, as the answer is mine, I can't until 2 days from now.

    – Cacahuete Frito
    Nov 22 '18 at 15:05
















0















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.










share|improve this question




















  • 1





    Show the definition of usr_input function.

    – Maxim Egorushkin
    Nov 22 '18 at 13:46











  • Really no conditions, also not in usr_input() itself, maybe by using exceptions which running out of the initializing scope? BTW "gcc 8.2 has been released as stable, so it shouldn't have many bugs." is definitly wrong if you look in the bugtracker. There are "some" open bugs, some are open and unfixed for multiple major versions... But you are right, such an easy to see bug I also would not expect.

    – Klaus
    Nov 22 '18 at 13:49








  • 1





    @Maxim You were right, I had to look inside usr_input(). But I would say that the variable returned by usr_input() is the one that is being used uninitialized, and not action itself. action is really being initialized, although with garbage in the case of an uninitialized return of usr_input(). I would call that a bug in gcc.

    – Cacahuete Frito
    Nov 22 '18 at 14:32













  • Please don't change the topic. Instead use the Accept button at the answer that solved your problem. That's the way how StackOverflow works. It's also okay to accept the own answer.

    – harper
    Nov 22 '18 at 15:04













  • Ok. However, as the answer is mine, I can't until 2 days from now.

    – Cacahuete Frito
    Nov 22 '18 at 15:05














0












0








0








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.










share|improve this question
















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.







gcc gcc-warning






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 15:02









harper

10.3k44285




10.3k44285










asked Nov 22 '18 at 13:36









Cacahuete FritoCacahuete Frito

349317




349317








  • 1





    Show the definition of usr_input function.

    – Maxim Egorushkin
    Nov 22 '18 at 13:46











  • Really no conditions, also not in usr_input() itself, maybe by using exceptions which running out of the initializing scope? BTW "gcc 8.2 has been released as stable, so it shouldn't have many bugs." is definitly wrong if you look in the bugtracker. There are "some" open bugs, some are open and unfixed for multiple major versions... But you are right, such an easy to see bug I also would not expect.

    – Klaus
    Nov 22 '18 at 13:49








  • 1





    @Maxim You were right, I had to look inside usr_input(). But I would say that the variable returned by usr_input() is the one that is being used uninitialized, and not action itself. action is really being initialized, although with garbage in the case of an uninitialized return of usr_input(). I would call that a bug in gcc.

    – Cacahuete Frito
    Nov 22 '18 at 14:32













  • Please don't change the topic. Instead use the Accept button at the answer that solved your problem. That's the way how StackOverflow works. It's also okay to accept the own answer.

    – harper
    Nov 22 '18 at 15:04













  • Ok. However, as the answer is mine, I can't until 2 days from now.

    – Cacahuete Frito
    Nov 22 '18 at 15:05














  • 1





    Show the definition of usr_input function.

    – Maxim Egorushkin
    Nov 22 '18 at 13:46











  • Really no conditions, also not in usr_input() itself, maybe by using exceptions which running out of the initializing scope? BTW "gcc 8.2 has been released as stable, so it shouldn't have many bugs." is definitly wrong if you look in the bugtracker. There are "some" open bugs, some are open and unfixed for multiple major versions... But you are right, such an easy to see bug I also would not expect.

    – Klaus
    Nov 22 '18 at 13:49








  • 1





    @Maxim You were right, I had to look inside usr_input(). But I would say that the variable returned by usr_input() is the one that is being used uninitialized, and not action itself. action is really being initialized, although with garbage in the case of an uninitialized return of usr_input(). I would call that a bug in gcc.

    – Cacahuete Frito
    Nov 22 '18 at 14:32













  • Please don't change the topic. Instead use the Accept button at the answer that solved your problem. That's the way how StackOverflow works. It's also okay to accept the own answer.

    – harper
    Nov 22 '18 at 15:04













  • Ok. However, as the answer is mine, I can't until 2 days from now.

    – Cacahuete Frito
    Nov 22 '18 at 15:05








1




1





Show the definition of usr_input function.

– Maxim Egorushkin
Nov 22 '18 at 13:46





Show the definition of usr_input function.

– Maxim Egorushkin
Nov 22 '18 at 13:46













Really no conditions, also not in usr_input() itself, maybe by using exceptions which running out of the initializing scope? BTW "gcc 8.2 has been released as stable, so it shouldn't have many bugs." is definitly wrong if you look in the bugtracker. There are "some" open bugs, some are open and unfixed for multiple major versions... But you are right, such an easy to see bug I also would not expect.

– Klaus
Nov 22 '18 at 13:49







Really no conditions, also not in usr_input() itself, maybe by using exceptions which running out of the initializing scope? BTW "gcc 8.2 has been released as stable, so it shouldn't have many bugs." is definitly wrong if you look in the bugtracker. There are "some" open bugs, some are open and unfixed for multiple major versions... But you are right, such an easy to see bug I also would not expect.

– Klaus
Nov 22 '18 at 13:49






1




1





@Maxim You were right, I had to look inside usr_input(). But I would say that the variable returned by usr_input() is the one that is being used uninitialized, and not action itself. action is really being initialized, although with garbage in the case of an uninitialized return of usr_input(). I would call that a bug in gcc.

– Cacahuete Frito
Nov 22 '18 at 14:32







@Maxim You were right, I had to look inside usr_input(). But I would say that the variable returned by usr_input() is the one that is being used uninitialized, and not action itself. action is really being initialized, although with garbage in the case of an uninitialized return of usr_input(). I would call that a bug in gcc.

– Cacahuete Frito
Nov 22 '18 at 14:32















Please don't change the topic. Instead use the Accept button at the answer that solved your problem. That's the way how StackOverflow works. It's also okay to accept the own answer.

– harper
Nov 22 '18 at 15:04







Please don't change the topic. Instead use the Accept button at the answer that solved your problem. That's the way how StackOverflow works. It's also okay to accept the own answer.

– harper
Nov 22 '18 at 15:04















Ok. However, as the answer is mine, I can't until 2 days from now.

– Cacahuete Frito
Nov 22 '18 at 15:05





Ok. However, as the answer is mine, I can't until 2 days from now.

– Cacahuete Frito
Nov 22 '18 at 15:05












1 Answer
1






active

oldest

votes


















0














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!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432203%2fspurious-warning-gcc-wuninitialized%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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!






    share|improve this answer




























      0














      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!






      share|improve this answer


























        0












        0








        0







        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!






        share|improve this answer













        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!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 14:01









        Cacahuete FritoCacahuete Frito

        349317




        349317
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432203%2fspurious-warning-gcc-wuninitialized%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]