aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-06-21 20:43:47 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2019-06-21 20:43:47 +0000
commit32833537fcfcc320c8a149641b12d49d23e94609 (patch)
treee89d6f1de38914ef1fd534195a78dfb0efb868a3 /gcc
parentfc39d4e18b473b923571614bfd6aed0707f8ac56 (diff)
downloadgcc-32833537fcfcc320c8a149641b12d49d23e94609.zip
gcc-32833537fcfcc320c8a149641b12d49d23e94609.tar.gz
gcc-32833537fcfcc320c8a149641b12d49d23e94609.tar.bz2
PR c++/61490 - qualified-id in friend function definition.
* decl.c (grokdeclarator): Diagnose qualified-id in friend function definition. Improve location for diagnostics of friend functions. * g++.dg/diagnostic/friend2.C: New test. * g++.dg/diagnostic/friend3.C: New test. From-SVN: r272572
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/decl.c22
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/diagnostic/friend2.C10
-rw-r--r--gcc/testsuite/g++.dg/diagnostic/friend3.C9
5 files changed, 46 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 12da65e..9b75295 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2019-06-21 Marek Polacek <polacek@redhat.com>
+ PR c++/61490 - qualified-id in friend function definition.
+ * decl.c (grokdeclarator): Diagnose qualified-id in friend function
+ definition. Improve location for diagnostics of friend functions.
+
PR c++/60223 - ICE with T{} in non-deduced context.
* pt.c (unify): Allow COMPOUND_LITERAL_P in a non-deduced context.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 85f96f7..98b54d5 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -11624,13 +11624,29 @@ grokdeclarator (const cp_declarator *declarator,
friendp = 0;
}
if (decl_context == NORMAL)
- error ("friend declaration not in class definition");
+ error_at (declarator->id_loc,
+ "friend declaration not in class definition");
if (current_function_decl && funcdef_flag)
{
- error ("cannot define friend function %qs in a local "
- "class definition", name);
+ error_at (declarator->id_loc,
+ "cannot define friend function %qs in a local "
+ "class definition", name);
friendp = 0;
}
+ /* [class.friend]/6: A function can be defined in a friend
+ declaration if the function name is unqualified. */
+ if (funcdef_flag && in_namespace)
+ {
+ if (in_namespace == global_namespace)
+ error_at (declarator->id_loc,
+ "friend function definition %qs cannot have "
+ "a name qualified with %<::%>", name);
+ else
+ error_at (declarator->id_loc,
+ "friend function definition %qs cannot have "
+ "a name qualified with %<%D::%>", name,
+ in_namespace);
+ }
}
else if (ctype && sfk == sfk_conversion)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e80c422..d5367b2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2019-06-21 Marek Polacek <polacek@redhat.com>
+ PR c++/61490 - qualified-id in friend function definition.
+ * g++.dg/diagnostic/friend2.C: New test.
+ * g++.dg/diagnostic/friend3.C: New test.
+
PR c++/60223 - ICE with T{} in non-deduced context.
* g++.dg/cpp0x/nondeduced1.C: New test.
* g++.dg/cpp0x/nondeduced2.C: New test.
diff --git a/gcc/testsuite/g++.dg/diagnostic/friend2.C b/gcc/testsuite/g++.dg/diagnostic/friend2.C
new file mode 100644
index 0000000..4f4ada8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/friend2.C
@@ -0,0 +1,10 @@
+// PR c++/61490
+// { dg-do compile }
+
+namespace N { void f (); }
+void f2 ();
+
+struct A {
+ friend void N::f () { } // { dg-error "15:friend function definition 'f' cannot have a name qualified with 'N::'" }
+ friend void ::f2 () { } // { dg-error "15:friend function definition 'f2' cannot have a name qualified with '::'" }
+};
diff --git a/gcc/testsuite/g++.dg/diagnostic/friend3.C b/gcc/testsuite/g++.dg/diagnostic/friend3.C
new file mode 100644
index 0000000..574d7ca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/friend3.C
@@ -0,0 +1,9 @@
+// { dg-do compile }
+
+void
+fn ()
+{
+ struct S {
+ friend void bar () { } // { dg-error "17:cannot define friend function 'bar' in a local class definition" }
+ };
+}