Hi,

this is also by and large obvious, I think: in order to use the right location for error messages about 'explicit', just use declspecs->locations[ds_explicit]. Tested x86_64-linux.

Thanks,
Paolo.

PS: I'm pretty sure we do have similar issues for other decl-specifiers, which can be likewise fixed very easily. I'll go through them over the next weeks..

////////////////////
/cp
2015-05-22  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/65598
        * decl.c (grokdeclarator): Use the correct location in error
        messages about 'explicit'.

/testsuite
2015-05-22  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/65598
        * g++.dg/cpp0x/explicit9.C: New.
        * g++.dg/cpp0x/explicit8.C: Check the locations too.
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 223520)
+++ cp/decl.c   (working copy)
@@ -10266,12 +10266,15 @@ grokdeclarator (const cp_declarator *declarator,
         in the declaration of a constructor or conversion function within
         a class definition.  */
       if (!current_class_type)
-       error ("%<explicit%> outside class declaration");
+       error_at (declspecs->locations[ds_explicit],
+                 "%<explicit%> outside class declaration");
       else if (friendp)
-       error ("%<explicit%> in friend declaration");
+       error_at (declspecs->locations[ds_explicit],
+                 "%<explicit%> in friend declaration");
       else
-       error ("only declarations of constructors and conversion operators "
-              "can be %<explicit%>");
+       error_at (declspecs->locations[ds_explicit],
+                 "only declarations of constructors and conversion operators "
+                 "can be %<explicit%>");
       explicitp = 0;
     }
 
Index: testsuite/g++.dg/cpp0x/explicit8.C
===================================================================
--- testsuite/g++.dg/cpp0x/explicit8.C  (revision 223520)
+++ testsuite/g++.dg/cpp0x/explicit8.C  (working copy)
@@ -5,13 +5,13 @@ struct A {
   explicit operator int() const;
 };
 
-explicit inline A::operator int() const { return 1; }  // { dg-error 
"'explicit' outside class declaration" }
+explicit inline A::operator int() const { return 1; }  // { dg-error 
"1:'explicit' outside class declaration" }
 
 struct B {
-  explicit void f();  // { dg-error "only declarations of constructors and 
conversion operators can be 'explicit'" }
+  explicit void f();  // { dg-error "3:only declarations of constructors and 
conversion operators can be 'explicit'" }
 };
 
-explicit void B::f() { }  // { dg-error "'explicit' outside class declaration" 
}
+explicit void B::f() { }  // { dg-error "1:'explicit' outside class 
declaration" }
 
 struct C {
   explicit C(int);
@@ -18,5 +18,5 @@ struct C {
 };
 
 struct D {
-  explicit friend C::C(int);  // { dg-error "'explicit' in friend declaration" 
}
+  explicit friend C::C(int);  // { dg-error "3:'explicit' in friend 
declaration" }
 };
Index: testsuite/g++.dg/cpp0x/explicit9.C
===================================================================
--- testsuite/g++.dg/cpp0x/explicit9.C  (revision 0)
+++ testsuite/g++.dg/cpp0x/explicit9.C  (working copy)
@@ -0,0 +1,12 @@
+// PR c++/65598
+// { dg-do compile { target c++11 } }
+
+struct ExplicitTest
+{
+  explicit operator bool() const;
+};
+
+explicit ExplicitTest::operator bool() const  // { dg-error "1:'explicit' 
outside class declaration" }
+{
+  return true;
+}

Reply via email to