From 2ec99953415c8d17a20b72f92b0d268478d1bfde Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 9 Jul 2014 22:44:42 +0000 Subject: [PATCH] =?utf8?q?re=20PR=20c++/60686=20(message=20"=20only=20decl?= =?utf8?q?arations=20of=20constructors=20can=20be=20=E2=80=98explicit?= =?utf8?q?=E2=80=99=20"=20now=20conflicting=20with=20C++11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit /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 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/decl.c | 13 ++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/explicit8.C | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/explicit8.C 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" } +}; -- 2.30.2