diff options
author | Dirk Mueller <dmueller@suse.de> | 2006-11-30 23:08:27 +0000 |
---|---|---|
committer | Dirk Mueller <dmueller@suse.de> | 2006-11-30 23:08:27 +0000 |
commit | c8490dbcf99cd3b1b86ef610f4fd20c8b14a195e (patch) | |
tree | 3dac1ff31be119a1ecd4986d6ad3d0334eeefd1c | |
parent | 3f40513558e4c587e1ec83417e11ad516cde606f (diff) |
2006-12-01 Dirk Mueller <dmueller@suse.de>
PR c++/18313
* decl.c (grokdeclarator): Warn for type qualifiers on return
type for non-dependent types.
* pt.c (tsubst_function_type): Warn for type qualifiers on
return type for dependent types.
* g++.dg/warn/Wreturn-type-4.C: New testcase.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@119382 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/decl.c | 17 | ||||
-rw-r--r-- | gcc/cp/pt.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wreturn-type-4.C | 43 |
5 files changed, 76 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9b78a29fdf7..c9528ca19be 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2006-12-01 Dirk Mueller <dmueller@suse.de> + + PR c++/18313 + * decl.c (grokdeclarator): Warn for type qualifiers on return + type for non-dependent types. + * pt.c (tsubst_function_type): Warn for type qualifiers on + return type for dependent types. + 2006-11-30 Geoffrey Keating <geoffk@apple.com> * rtti.c (get_tinfo_decl): Handle return value from diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f50866832f6..6043596b2fd 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6895,6 +6895,7 @@ grokdeclarator (const cp_declarator *declarator, cp_storage_class storage_class; bool unsigned_p, signed_p, short_p, long_p, thread_p; bool type_was_error_mark_node = false; + bool set_no_warning = false; signed_p = declspecs->specs[(int)ds_signed]; unsigned_p = declspecs->specs[(int)ds_unsigned]; @@ -7541,9 +7542,16 @@ grokdeclarator (const cp_declarator *declarator, /* Declaring a function type. Make sure we have a valid type for the function to return. */ - /* We now know that the TYPE_QUALS don't apply to the - decl, but to its return type. */ - type_quals = TYPE_UNQUALIFIED; + if (type_quals != TYPE_UNQUALIFIED) + { + if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)) + warning (OPT_Wreturn_type, + "type qualifiers ignored on function return type"); + /* We now know that the TYPE_QUALS don't apply to the + decl, but to its return type. */ + type_quals = TYPE_UNQUALIFIED; + set_no_warning = true; + } /* Warn about some types functions can't return. */ @@ -8623,6 +8631,9 @@ grokdeclarator (const cp_declarator *declarator, if (!processing_template_decl) cp_apply_type_quals_to_decl (type_quals, decl); + if (set_no_warning) + TREE_NO_WARNING (decl) = 1; + return decl; } } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bcaae6b3ac0..2f4e8996839 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7133,6 +7133,13 @@ tsubst_function_type (tree t, if (arg_types == error_mark_node) return error_mark_node; + if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED + && in_decl != NULL_TREE + && !TREE_NO_WARNING (in_decl) + && (SCALAR_TYPE_P (return_type) || VOID_TYPE_P (return_type))) + warning (OPT_Wreturn_type, + "type qualifiers ignored on function return type"); + /* Construct a new type node and return it. */ if (TREE_CODE (t) == FUNCTION_TYPE) fntype = build_function_type (return_type, arg_types); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3535260897f..3a9def2e14f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2006-12-01 Dirk Mueller <dmueller@suse.de> + + * g++.dg/warn/Wreturn-type-4.C: New testcase. + 2006-11-30 Janis Johnson <janis187@us.ibm.com> * gcc.dg/dfp/convert-int-max.c: New test. diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C new file mode 100644 index 00000000000..dbb089b1812 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C @@ -0,0 +1,43 @@ +/* PR c++/18313 */ +/* { dg-do compile } */ +/* { dg-options "-Wreturn-type" } */ + +volatile void bar(); /* { dg-warning "type qualifiers ignored" } */ + +struct A +{ + const int bla(); /* { dg-warning "type qualifiers ignored" } */ + static const A getA(); /* { dg-bogus "type qualifiers" } */ +}; + +template<typename T> const T getfoo(const T def) /* { dg-bogus "type qualifiers ignored" } */ +{ return def; } + +template<typename T> class Pair +{ + public: + T getLeft() const { return T(); } /* { dg-warning "type qualifiers ignored" } */ + const T getRight() const { return T(); } /* { dg-bogus "type qualifiers ignored" } */ +}; + +template <typename T> struct S { + const int f(); /* { dg-warning "type qualifiers ignored" } */ + const T g(); /* { dg-bogus "type qualifiers ignored" } */ + T h(); +}; + +int* testtemplate() +{ + int i; + + Pair<const int> a; + + a.getLeft(); + a.getRight(); + + S<bool> b; + b.h(); /* { dg-bogus "type qualifiers ignored" } */ + b.g(); /* { dg-bogus "type qualifiers ignored" } */ + + return getfoo<int*>(&i); +} |