Hi,

in this bug submitter noticed that talking only about explicit constructors without mentioning conversion operators is misleading in C++11. Thus Jon suggested simply not mentioning the constructors in the error message, which I find reasonable because after all it's about the fact that the user has 'explicit' on the definition, not about 'explicit' being used on the wrong type of declaration. Certainly anyway, another option would be extending the current error message and mention conversion operators too or even providing different error messages for C++98 and C++11 (maybe overkill considering that we do *accept* explicit operators in C++98 mode, we only emit a pedwarn). Tested x86_64-linux.

Thanks,
Paolo.

///////////////////////
/cp
2014-07-07  Jonathan Wakely  <jwak...@redhat.com>
            Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/60686
        * decl.c (grokdeclarator): Adjust error message about 'explicit'
        outside class definition for C++11.

/testsuite
2014-07-07  Jonathan Wakely  <jwak...@redhat.com>
            Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/60686
        * g++.dg/cpp0x/explicit8.C: New.
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 212332)
+++ cp/decl.c   (working copy)
@@ -10117,9 +10117,10 @@ grokdeclarator (const cp_declarator *declarator,
 
   if (explicitp == 1 || (explicitp && friendp))
     {
-      /* [dcl.fct.spec] The explicit specifier shall only be used in
-        declarations of constructors within a class definition.  */
-      error ("only declarations of constructors can be %<explicit%>");
+      /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
+        in the declaration of a constructor or conversion function within
+        a class definition.  */
+      error ("only declarations can be marked %<explicit%>");
       explicitp = 0;
     }
 
Index: testsuite/g++.dg/cpp0x/explicit8.C
===================================================================
--- testsuite/g++.dg/cpp0x/explicit8.C  (revision 0)
+++ testsuite/g++.dg/cpp0x/explicit8.C  (working copy)
@@ -0,0 +1,8 @@
+// PR c++/60686
+// { dg-do compile { target c++11 } }
+
+struct A {
+  explicit operator int() const;
+};
+
+explicit inline A::operator int() const { return 1; }  // { dg-error "only 
declarations can be marked 'explicit'" }

Reply via email to