public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105794] New: Spurious "control reaches end of non-void function" warning with a combination of destructor, try/catch and if (true)
@ 2022-05-31 15:42 kamil.sliwak at codepoets dot it
  2022-05-31 20:14 ` [Bug c++/105794] " mpolacek at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: kamil.sliwak at codepoets dot it @ 2022-05-31 15:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105794
           Summary: Spurious "control reaches end of non-void function"
                    warning with a combination of destructor, try/catch
                    and if (true)
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kamil.sliwak at codepoets dot it
  Target Milestone: ---

After switching to GCC 12 I noticed that in several places in the C++ project
I'm working on I'm now getting the `control reaches end of non-void function`
warning. This seems like a regression since it's not happening with earlier GCC
versions or with latest Clang.

I managed to distill the problematic code into a small repro (see below) and
it's reproducible via https://godbolt.org so it does not seem dependent on my
specific environment.

The original code is more complicated but in the end a combination of three
things seems to be causing this:
1. A variable of a custom class type that has an explicitly defined destructor
(which can be empty though).
2. A try/catch block with a return.
3. A `throw` wrapped in a condition that's a compile-time constant.

Removing any of the above makes the warning go away.

### Environment
- GCC version: 12.1.0
- System: Arch Linux

### Repro
#### Command
```
g++ test.cpp
```

#### `test.cpp`
```
#include <exception>

class C {
public:
        ~C() {}
};

int foo()
{
        C c;

        try
        {
                return 1;
        }
        catch (std::exception const&)
        {
        }

        if (true)
                throw std::exception();
}

int main() {
    return 0;
}
```

#### Output
```
test.cpp: In function ‘int foo()’:
test.cpp:22:1: warning: control reaches end of non-void function
[-Wreturn-type]
   22 | }
      | ^
```

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

end of thread, other threads:[~2022-06-01 19:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 15:42 [Bug c++/105794] New: Spurious "control reaches end of non-void function" warning with a combination of destructor, try/catch and if (true) kamil.sliwak at codepoets dot it
2022-05-31 20:14 ` [Bug c++/105794] " mpolacek at gcc dot gnu.org
2022-05-31 20:33 ` mpolacek at gcc dot gnu.org
2022-06-01 19:41 ` [Bug c++/105794] [12/13 Regression] " jason 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).