The fix for PR c++/69733 caused a regression for conversion operators
with redundant cv-qualifiers, changing an incorrect location to an
unknown location. This restores it to the incorrect location (as was
already done on trunk by the fix for PR c++/65775).

Tested x86_64-linux, OK for gcc-7-branch?
commit fc16f7b06d38c34be068b9ae3a4fd8d6095070e5
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Apr 19 12:01:53 2018 +0100

    PR c++/85464 - missing location for -Wignored-qualifiers diagnostic
    
    The fix for PR c++/69733 caused a regression for conversion operators
    with redundant cv-qualifiers, changing an incorrect location to an
    unknown location. This restores it to the incorrect location (as was
    already done on trunk by the fix for PR c++/65775).
    
    gcc/cp:
    
            PR c++/85464 - missing location for -Wignored-qualifiers diagnostic
            * decl.c (grokdeclarator): If declspecs->locations[ds_type_spec]
            is UNKNOWN_LOCATION fall back to input_location.
    
    gcc/testsuite:
    
            PR c++/85464 - missing location for -Wignored-qualifiers diagnostic
            * g++.dg/diagnostic/pr85464.C: New.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5c519146043..9809d06eed8 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10105,6 +10105,8 @@ grokdeclarator (const cp_declarator *declarator,
                                                      declspecs->locations);
   if (typespec_loc == UNKNOWN_LOCATION)
     typespec_loc = declspecs->locations[ds_type_spec];
+  if (typespec_loc == UNKNOWN_LOCATION)
+    typespec_loc = input_location;
 
   /* Look inside a declarator for the name being declared
      and get it as a string, for an error message.  */
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr85464.C 
b/gcc/testsuite/g++.dg/diagnostic/pr85464.C
new file mode 100644
index 00000000000..ee8b65185e5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/pr85464.C
@@ -0,0 +1,5 @@
+// { dg-options "-Wignored-qualifiers" }
+struct Test {
+   operator int const(); // { dg-warning "type qualifiers ignored" }
+   operator int const() const; // { dg-warning "type qualifiers ignored" }
+};

Reply via email to