public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "albrecht.guendel at web dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/114904] New: Bogus Warning [-Wreturn-type] in function with do-while loop
Date: Wed, 01 May 2024 12:25:57 +0000	[thread overview]
Message-ID: <bug-114904-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114904

            Bug ID: 114904
           Summary: Bogus Warning [-Wreturn-type] in function with
                    do-while loop
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: albrecht.guendel at web dot de
  Target Milestone: ---

Hi, 
from GCC 8.1 onwards using >=C++14, i get hit with
> warning: control reaches end of non-void function [-Wreturn-type]
in the following code:

auto test()
{
    do
    {
        volatile int a = 0;
        if (a)
            continue;
        return 1;
    } while(0);
}

or use https://godbolt.org/z/PxE95vqe6

This code uses a do-while construct to conditionally repeat code above the
continue-statement, but always returns within the loop.
The bogus warning occurs as soon as loop-control-flow is added. However the
'continue' would never leave the loop.

The warning can be fixed with __builtin_unreachable(); below the while(0). or
by using goto instead of loop control-flow. However this should not be
necessary.
Clang shows the same behavior.

             reply	other threads:[~2024-05-01 12:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 12:25 albrecht.guendel at web dot de [this message]
2024-05-01 14:16 ` [Bug c++/114904] " albrecht.guendel at web dot de
2024-05-01 17:20 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114904-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).