public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114904] New: Bogus Warning [-Wreturn-type] in function with do-while loop
@ 2024-05-01 12:25 albrecht.guendel at web dot de
  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
  0 siblings, 2 replies; 3+ messages in thread
From: albrecht.guendel at web dot de @ 2024-05-01 12:25 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/114904] Bogus Warning [-Wreturn-type] in function with do-while loop
  2024-05-01 12:25 [Bug c++/114904] New: Bogus Warning [-Wreturn-type] in function with do-while loop albrecht.guendel at web dot de
@ 2024-05-01 14:16 ` albrecht.guendel at web dot de
  2024-05-01 17:20 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: albrecht.guendel at web dot de @ 2024-05-01 14:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Albi <albrecht.guendel at web dot de> ---
This "bug" can be closed and deleted. I am an idiot and i am sorry.
'continue' does not jump to the start of the loop, but to the next
loop-condition-check, so in a do-while loop, it actually jumps to the bottom.

Man, after 20 years of c++ !!!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/114904] Bogus Warning [-Wreturn-type] in function with do-while loop
  2024-05-01 12:25 [Bug c++/114904] New: Bogus Warning [-Wreturn-type] in function with do-while loop albrecht.guendel at web dot de
  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
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-01 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Invalid as mentioned by submitter.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-01 17:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-01 12:25 [Bug c++/114904] New: Bogus Warning [-Wreturn-type] in function with do-while loop albrecht.guendel at web dot de
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

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).