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]

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


Dirk Mueller wrote:

> 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;
> +	      }

Minor nit-pick: I tend to check !processing_template_decl first because
it's often a cheaper check, and because it ensures that you can use
arbitrary functions after that point without worrying about all the
weird things you see in templates.  So, I'd prefer if you reversed the
order of the tests.

Also, what does this do with:

  typedef const int I;
  I f();

?  Also, what does this do with templates:

  template <typename T>
  void f() {
    T (*p)();
  }

  f<const int>()

?

The declarators won't be re-processed in the template case, so your
patch won't work there, IIUC.  I think we need an approach that works in
that situation.  Perhaps, a new cp_build_function_type, which does the
check there?  And a check in build_method_type_directly as well?

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


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