Bug 59916 - [4.9 Regression] constructors and destructors can cause "control reaches end of non-void function" warnings with -Os
Summary: [4.9 Regression] constructors and destructors can cause "control reaches end ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-23 11:35 UTC by Bernhard Rosenkränzer
Modified: 2014-01-29 17:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-01-29 00:00:00


Attachments
test case (73 bytes, text/x-c++src)
2014-01-23 11:35 UTC, Bernhard Rosenkränzer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Rosenkränzer 2014-01-23 11:35:52 UTC
Created attachment 31929 [details]
test case

The following C++ code:

class A
{
};

class B : virtual public A
{
public:
        B();
        virtual ~B();
};

B::B()
{
}

B::~B()
{
}


causes an incorrect warning with current 4.9 git with -Os:

[bero@localhost gcc-test]$ arm-linux-androideabi-g++ -Werror=return-type -Os -o test.o test.cpp
test.cpp: In constructor 'B::B()':
test.cpp:14:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
test.cpp: In constructor 'B::B()':
test.cpp:14:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
test.cpp: In destructor 'B::~B()':
test.cpp:18:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
test.cpp: In destructor 'virtual B::~B()':
test.cpp:18:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1plus: some warnings being treated as errors
Comment 1 Paolo Carlini 2014-01-27 11:05:10 UTC
Richard, is this a front-end issue?
Comment 2 Richard Biener 2014-01-28 13:04:25 UTC
Surely frontend related - after gimplification I see

B::B() (struct B * const this, const void * * __vtt_parm)
{
  struct B * <retval>;

  <retval> = B::B (this, 0, __vtt_parm);
}

which misses a return.
Comment 3 Jason Merrill 2014-01-28 18:48:49 UTC
(In reply to Richard Biener from comment #2)
>   <retval> = B::B (this, 0, __vtt_parm);

That assigns to the RESULT_DECL, which should count as a return.
Comment 4 Richard Biener 2014-01-29 13:34:02 UTC
Confirmed btw.  No, gimple wants a return stmt, so somewhere it goes wrong - either wrong GENERIC or wrong C++ specific gimplification.
Comment 5 Jason Merrill 2014-01-29 17:13:33 UTC
Author: jason
Date: Wed Jan 29 17:13:01 2014
New Revision: 207271

URL: http://gcc.gnu.org/viewcvs?rev=207271&root=gcc&view=rev
Log:
	PR c++/59916
	* optimize.c (maybe_thunk_body): Build a RETURN_EXPR for
	cdtor_returns_this case.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wreturn-type-10.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/optimize.c
Comment 6 Jason Merrill 2014-01-29 17:13:48 UTC
Fixed.