From: Paolo Carlini Date: Wed, 9 Jul 2014 22:44:42 +0000 (+0000) Subject: re PR c++/60686 (message " only declarations of constructors can be ‘explicit’ "... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2ec99953415c8d17a20b72f92b0d268478d1bfde;p=gcc.git re PR c++/60686 (message " only declarations of constructors can be ‘explicit’ " now conflicting with C++11) /cp 2014-07-09 Paolo Carlini PR c++/60686 * decl.c (grokdeclarator): Adjust error messages about 'explicit' outside class declaration, in friend declaration, and neither on constructor nor conversion operator. /testsuite 2014-07-09 Paolo Carlini PR c++/60686 * g++.dg/cpp0x/explicit8.C: New. From-SVN: r212415 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6174193cb89..5827bbdf3de 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2014-07-09 Paolo Carlini + + PR c++/60686 + * decl.c (grokdeclarator): Adjust error messages about 'explicit' + outside class declaration, in friend declaration, and neither on + constructor nor conversion operator. + 2014-07-09 Paolo Carlini DR 1584 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5ab8ccd2588..1ade5861d58 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10117,9 +10117,16 @@ 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 %"); + /* [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. */ + if (!current_class_type) + error ("% outside class declaration"); + else if (friendp) + error ("% in friend declaration"); + else + error ("only declarations of constructors and conversion operators " + "can be %"); explicitp = 0; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 675e3431b10..f4ccc1fda68 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-07-09 Paolo Carlini + + PR c++/60686 + * g++.dg/cpp0x/explicit8.C: New. + 2014-07-09 Paolo Carlini DR 1584 diff --git a/gcc/testsuite/g++.dg/cpp0x/explicit8.C b/gcc/testsuite/g++.dg/cpp0x/explicit8.C new file mode 100644 index 00000000000..acacf97451a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/explicit8.C @@ -0,0 +1,22 @@ +// 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 "'explicit' outside class declaration" } + +struct B { + explicit void f(); // { dg-error "only declarations of constructors and conversion operators can be 'explicit'" } +}; + +explicit void B::f() { } // { dg-error "'explicit' outside class declaration" } + +struct C { + explicit C(int); +}; + +struct D { + explicit friend C::C(int); // { dg-error "'explicit' in friend declaration" } +};