public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-coroutines] c++: Diagnose a deduction guide in a wrong scope [PR91759]
@ 2020-03-18 21:16 Iain D Sandoe
0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2020-03-18 21:16 UTC (permalink / raw)
To: gcc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 3403 bytes --]
https://gcc.gnu.org/g:af8656be8df68ac26840f7844430fd595255ebd2
commit af8656be8df68ac26840f7844430fd595255ebd2
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Mar 18 08:53:23 2020 +0100
c++: Diagnose a deduction guide in a wrong scope [PR91759]
The following testcase is accepts-invalid since r7-6608-ga56c0ac08242269b.
Before that change we had this
"deduction guide %qD must be declared in the same scope as %qT"
diagnostics for it, after the change it is expected to be diagnosed
in set_decl_namespace at the not_found: label in there. On this testcase
nothing is diagnosed though, because set_decl_namespace isn't called at all,
as in_namespace is NULL.
The following patch restores the old warning but does it only in case we
don't call set_decl_namespace.
2020-03-18 Jakub Jelinek <jakub@redhat.com>
PR c++/91759
* decl.c (grokfndecl): Restore old diagnostics about deduction
guide declared in different scope if in_namespace is NULL_TREE.
* g++.dg/cpp1z/class-deduction72.C: New test.
Diff:
---
gcc/cp/ChangeLog | 6 ++++++
gcc/cp/decl.c | 9 +++++++++
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/g++.dg/cpp1z/class-deduction72.C | 11 +++++++++++
4 files changed, 31 insertions(+)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1db1e090e51..9aaa81a17bb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-18 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/91759
+ * decl.c (grokfndecl): Restore old diagnostics about deduction
+ guide declared in different scope if in_namespace is NULL_TREE.
+
2020-03-17 Jakub Jelinek <jakub@redhat.com>
PR c++/90995
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d240436d84a..319b7ee5c1c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9644,6 +9644,15 @@ grokfndecl (tree ctype,
"namespace scope", decl);
return NULL_TREE;
}
+ tree type = TREE_TYPE (DECL_NAME (decl));
+ if (in_namespace == NULL_TREE
+ && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
+ {
+ error_at (location, "deduction guide %qD must be declared in the "
+ "same scope as %qT", decl, type);
+ inform (location_of (type), " declared here");
+ return NULL_TREE;
+ }
if (funcdef_flag)
error_at (location,
"deduction guide %qD must not have a function body", decl);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 775837d840f..8efb773437b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-18 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/91759
+ * g++.dg/cpp1z/class-deduction72.C: New test.
+
2020-03-17 Uroš Bizjak <ubizjak@gmail.com>
* g++.dg/debug/dwarf2/const2b.C (dg-do): Fix target selector.
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction72.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction72.C
new file mode 100644
index 00000000000..60c559907a3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction72.C
@@ -0,0 +1,11 @@
+// PR c++/91759
+// { dg-do compile { target c++17 } }
+
+namespace N {
+ template <typename T>
+ struct X{ X(int); }; // { dg-message "declared here" }
+}
+
+using N::X;
+
+X(int) -> X<int>; // { dg-error "must be declared in the same scope as" }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-03-18 21:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18 21:16 [gcc/devel/c++-coroutines] c++: Diagnose a deduction guide in a wrong scope [PR91759] Iain D Sandoe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).