Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Or do you prefer something different? 2020-03-17 Jakub Jelinek <ja...@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. --- gcc/cp/decl.c.jj 2020-03-12 08:26:23.000000000 +0100 +++ gcc/cp/decl.c 2020-03-16 16:25:02.142867924 +0100 @@ -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); --- gcc/testsuite/g++.dg/cpp1z/class-deduction72.C.jj 2020-03-16 16:27:03.997068510 +0100 +++ gcc/testsuite/g++.dg/cpp1z/class-deduction72.C 2020-03-16 16:28:21.241927835 +0100 @@ -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" } Jakub