2002-02-01 Jason Merrill <jason@redhat.com>
+ PR c++/4872
+ * decl.c (finish_function): Warn about a non-void function with
+ no return statement and no abnormal exit.
+ * cp-tree.h (struct cp_language_function): Add returns_abnormally.
+ (current_function_returns_abnormally): New macro.
+ * call.c (build_call): Set it.
+
* typeck.c (build_component_ref): Always complain about offsetof
constructs on non-PODs. Only make it an error for members of
virtual bases.
nothrow = ((decl && TREE_NOTHROW (decl))
|| TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (function))));
+ if (decl && TREE_THIS_VOLATILE (decl))
+ current_function_returns_abnormally = 1;
+
if (decl && TREE_DEPRECATED (decl))
warn_deprecated_use (decl);
int returns_value;
int returns_null;
+ int returns_abnormally;
int in_function_try_handler;
int x_expanding_p;
#define current_function_returns_null cp_function_chain->returns_null
+/* Set to 0 at beginning of a function definition, set to 1 if
+ a call to a noreturn function is seen. */
+
+#define current_function_returns_abnormally \
+ cp_function_chain->returns_abnormally
+
/* Non-zero if we should generate RTL for functions that we process.
When this is zero, we just accumulate tree structure, without
interacting with the back end. */
if (!processing_template_decl && calls_setjmp_p (fndecl))
DECL_UNINLINABLE (fndecl) = 1;
+ /* Complain if there's just no return statement. */
+ if (!processing_template_decl
+ && TREE_CODE (TREE_TYPE (fntype)) != VOID_TYPE
+ && !current_function_returns_value
+ && !DECL_NAME (DECL_RESULT (fndecl))
+ /* Don't complain if we abort or throw. */
+ && !current_function_returns_abnormally
+ /* If we have -Wreturn-type, let flow complain. Unless we're an
+ inline function, as we might never be compiled separately. */
+ && (!warn_return_type || DECL_INLINE (fndecl))
+ warning ("no return statement in function returning non-void");
+
/* Clear out memory we no longer need. */
free_after_parsing (cfun);
/* Since we never call rest_of_compilation, we never clear
NonPod () {m = 0x12345678;}
NonPod (long m_) {m = m_;}
- NonPod &operator= (NonPod const &src) {now = m; m = src.m;}
+ NonPod &operator= (NonPod const &src) {now = m; m = src.m; return *this;}
NonPod (NonPod const &src) {m = src.m;}
};
static const bar bars[];
- int bad ()
+ void bad ()
{
this->*(bars[0].b) = 42; // { dg-bogus "read-only" "" }
}
INT1a should_not_be_deprecated;
INT1 f1(void) __attribute__ ((deprecated));
-INT1 f2(void) {} /* { dg-warning "`INT1' is deprecated" "" } */
+INT1 f2(void) { return 0; } /* { dg-warning "`INT1' is deprecated" "" } */
INT2 f3(void) __attribute__ ((__deprecated__));
-INT2 f4(void) {} /* { dg-warning "`INT2' is deprecated" "" } */
+INT2 f4(void) { return 0; } /* { dg-warning "`INT2' is deprecated" "" } */
int f5(INT2 x); /* { dg-warning "`INT2' is deprecated" "" } */
int f6(INT2 x) __attribute__ ((__deprecated__));
// Build don't link:
+#include <stdlib.h>
+
class A {
public:
void z();
A(void) {}
private:
A(const A &) { abort(); } // ERROR -
- const A& operator =(const A &) { abort(); } // WARNING - no return stmt XFAIL *-*-*
+ const A& operator =(const A &) { abort(); }
};
class B : public A {
struct struct0 {
int struct0_member_function_0 () {
- } // ERROR - XFAIL
+ } // ERROR -
struct0 struct0_member_function_1 () {
- } // ERROR - XFAIL
+ } // ERROR -
};
struct struct1 {
void operator -= (const Char );
};
-inline Char operator - (const Char a, const Char b) {}
-inline char operator == (const Char a, const char b) {}
+inline Char operator - (const Char a, const Char b) { return Char(0); }
+inline char operator == (const Char a, const char b) { return 0; }
char mystrcmp(Char s[31], Char t[31])
{
// Subject: 4 bugs in g++ 2.3.3
// Message-ID: <9304291053.AA00090@mencon>
- struct A {
- A& operator = (const A& a) {}// ERROR - XFAIL
- };
+struct A {
+ A& operator = (const A& a) {}// WARNING -
+};
throw 42;
}
-template <class T> int foo(T) throw (int) { throw "Hi"; }
+template <class T> void foo(T) throw (int) { throw "Hi"; }
main() {
std::set_unexpected (my_unexpected);
throw 42;
}
-template <class T> int foo(T) throw (T) { throw "Hi"; }
+template <class T> void foo(T) throw (T) { throw "Hi"; }
main() {
std::set_unexpected (my_unexpected);
void (X::* fee ())()
{
lab: goto lab;
+ return 0;
}
#include <stddef.h>
-extern "C" void abort();
+#include <stdlib.h>
class toto {
public:
}
myint(const myint& mi) {
}
- myint& operator=(const myint& mi) {
- }
+ myint& operator=(const myint& mi) { return *this; }
};
extern pair<const myint, myint> a;
class C {
public:
- bool f (S::E()) { }
+ bool f (S::E()) { return true; }
virtual void foo();
};
class Foo {
public:
- int f(){}
+ int f(){ return 0; }
};
void foo() {
if (match_arg != &o)
fail = 1;
match_arg = &o;
+ return *this;
}
};
X::x()
{ // ERROR -
-}
+} // WARNING - no return
X::~x()
{ // ERROR -
int operator()(int)
{
i = 1;
+ return i;
}
typedef int I;
int operator()(int)
{
j = 1;
+ return j;
}
void f() {
struct T
{
- static int f() {}
+ static int f() { return 0; }
};
static const S s = { &T::f };
// Build don't link:
-typedef __SIZE_TYPE__ size_t;
+#include <new>
+
inline void *
operator new(size_t alloc_sz, const char *fname, unsigned lineno)
{
+ return ::operator new (alloc_sz);
}
inline void *
operator new[](size_t alloc_sz, const char *fname, unsigned lineno)
{
+ return ::operator new[] (alloc_sz);
}
inline void
operator delete(void *ptr, const char *fname, unsigned lineno)
virtual int f() {
new S[+f()];
+ return 0;
}
};
public:
int xxi;
float xxf;
- int xxf1 () {};
- int xxf2 (int k) {};
+ int xxf1 () { return 0; };
+ int xxf2 (int k) { return 0; };
};
class YY {
public:
int yyi;
double yyd;
- int yyf1 (float f) {};
+ int yyf1 (float f) { return 0; };
double yyf2 () {return yyd;};
};
};
struct Operation {
- double eval(double) {}
+ double eval(double) { return 0; }
};
int main() {