This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PING: [PATCH: c++/diagnostic/18313] Warn for pointless qualifiers on return type


Hi, 

the patch below implements the warning for pointless qualifiers on the return 
type for the C++ frontend. It seems to work similiar in icc. Compared to the 
patch I posted two weeks ago I removed some annoying positives with templates 
and returning class types. 

Bootstrapped, regtested on i686-suse-linux. Ok for mainline?


2006-11-11  Dirk Mueller  <dmueller@suse.de>

	 PR c++/18313
        * decl.c (grokdeclarator): Add warning for pointless
        qualifiers on return types.

        * g++.dg/warn/Wreturn-type-4.C: New testcase.


Index: decl.c
===================================================================
--- decl.c	(revision 118339)
+++ decl.c	(working copy)
@@ -7528,9 +7528,15 @@ grokdeclarator (const cp_declarator *dec
 	    /* 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 (!CLASS_TYPE_P (type) && !processing_template_decl)
+                  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;
+	      }
 
 	    /* Warn about some types functions can't return.  */
 
Index: g++.dg/warn/Wreturn-type-4.C
===================================================================
--- g++.dg/warn/Wreturn-type-4.C	(revision 0)
+++ g++.dg/warn/Wreturn-type-4.C	(revision 0)
@@ -0,0 +1,20 @@
+/* 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; } 
+
+int* testtemplate()
+{
+    int i;
+    return getfoo<int*>(&i);
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]