diff mbox

Warning location fix, PR c++/69733

Message ID 56BB8EF2.1020500@redhat.com
State New
Headers show

Commit Message

Bernd Schmidt Feb. 10, 2016, 7:26 p.m. UTC
This PR notes that in this warning:
const.ii:5:25: warning: type qualifiers ignored on function return type 
[-Wignored-qualifiers]
     const double value() const {return val;}
                          ^~~~~

we are pointing at the wrong qualifier. Below I'm attaching a patch that 
makes it point at the first qualifier of the return type (or the return 
type in case it's a typedef with qualifiers) instead. However, it turns 
out this is not consistent with the C frontend, which points at the 
function name for this warning.

I'm guessing we want to be consistent between frontends, and I also have 
a similar patch for C. Before I finalize it all with testcases and 
everything - which behaviour is desired?


Bernd

Comments

Jakub Jelinek Feb. 10, 2016, 7:33 p.m. UTC | #1
On Wed, Feb 10, 2016 at 08:26:42PM +0100, Bernd Schmidt wrote:
> This PR notes that in this warning:
> const.ii:5:25: warning: type qualifiers ignored on function return type
> [-Wignored-qualifiers]
>     const double value() const {return val;}
>                          ^~~~~
> 
> we are pointing at the wrong qualifier. Below I'm attaching a patch that
> makes it point at the first qualifier of the return type (or the return type
> in case it's a typedef with qualifiers) instead. However, it turns out this
> is not consistent with the C frontend, which points at the function name for
> this warning.
> 
> I'm guessing we want to be consistent between frontends, and I also have a
> similar patch for C. Before I finalize it all with testcases and everything
> - which behaviour is desired?

Just a nit from compile time POV, wouldn't it be better to compute loc only
inside of the if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)) block, so that
it is not computed when it is not needed?

> --- gcc/cp/decl.c	(revision 233217)
> +++ gcc/cp/decl.c	(working copy)
> @@ -10009,8 +10009,14 @@ grokdeclarator (const cp_declarator *dec
>  
>  	    if (type_quals != TYPE_UNQUALIFIED)
>  	      {
> +		location_t loc;
> +		loc = smallest_type_quals_location (type_quals,
> +						    declspecs->locations);
> +		if (loc == UNKNOWN_LOCATION)
> +		  loc = declspecs->locations[ds_type_spec];
>  		if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type))
> -		  warning (OPT_Wignored_qualifiers,
> +		  warning_at (loc,
> +			      OPT_Wignored_qualifiers,
>  			   "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.  */

	Jakub
diff mbox

Patch

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 233217)
+++ gcc/cp/decl.c	(working copy)
@@ -10009,8 +10009,14 @@  grokdeclarator (const cp_declarator *dec
 
 	    if (type_quals != TYPE_UNQUALIFIED)
 	      {
+		location_t loc;
+		loc = smallest_type_quals_location (type_quals,
+						    declspecs->locations);
+		if (loc == UNKNOWN_LOCATION)
+		  loc = declspecs->locations[ds_type_spec];
 		if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type))
-		  warning (OPT_Wignored_qualifiers,
+		  warning_at (loc,
+			      OPT_Wignored_qualifiers,
 			   "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.  */