if (deduction_guide_p (decl))
{
- if (!DECL_NAMESPACE_SCOPE_P (decl))
- {
- error_at (location, "deduction guide %qD must be declared at "
- "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))
inform (location_of (type), " declared here");
return NULL_TREE;
}
+ if (DECL_CLASS_SCOPE_P (decl)
+ && current_access_specifier != declared_access (TYPE_NAME (type)))
+ {
+ error_at (location, "deduction guide %qD must have the same access "
+ "as %qT", decl, type);
+ inform (location_of (type), " declared here");
+ }
if (funcdef_flag)
error_at (location,
"deduction guide %qD must not have a function body", decl);
storage_class = declspecs->storage_class;
if (storage_class == sc_static)
staticp = 1 + (decl_context == FIELD);
+ else if (decl_context == FIELD && sfk == sfk_deduction_guide)
+ /* Treat class-scope deduction guides as static member functions
+ so that they get a FUNCTION_TYPE instead of a METHOD_TYPE. */
+ staticp = 2;
if (virtualp)
{
rval = error_mark_node;
}
- if (rval && is_overloaded_fn (rval))
+ if (rval && is_overloaded_fn (rval)
+ /* Don't use a BASELINK for class-scope deduction guides since
+ they're not actually member functions. */
+ && !dguide_name_p (name))
rval = build_baselink (rval_binfo, basetype_path, rval,
(IDENTIFIER_CONV_OP_P (name)
? TREE_TYPE (name): NULL_TREE));
--- /dev/null
+// PR c++/79501
+// { dg-do compile { target c++17 } }
+
+template<auto V>
+struct X {
+ template<class T, auto>
+ struct B { T t; };
+
+ template<class T> B(T, decltype(V)=V) -> B<const T, V>;
+
+ auto foo() { return B{V}; }
+};
+
+X<42> x;
+using type = decltype(x.foo());
+using type = decltype(decltype(x)::B{42});
+using type = X<42>::B<const int, 42>;
--- /dev/null
+// PR c++/79501
+// { dg-do compile { target c++17 } }
+// A variant of class-deduction78.C where List and its deduction guides are
+// defined at class scope.
+
+using size_t = decltype(sizeof(42));
+
+struct A {
+ template<typename T, size_t N = 0>
+ struct List {
+ T head;
+ List<T, N-1> tail;
+ };
+
+ template<typename T>
+ struct List<T, 0> {};
+
+ template<typename T> List(T) -> List<T, 1>;
+ template<typename T, size_t N> List(T, List<T, N>) -> List<T, N+1>;
+};
+
+int main() {
+ using type = decltype(A::List{0, A::List{1, A::List{2}}});
+ using type = A::List<int, 3>;
+}
--- /dev/null
+// PR c++/79501
+// { dg-do compile { target c++17 } }
+
+struct X {
+protected:
+ template<class T>
+ struct B { T t; };
+
+ template<class T> B(T) -> B<T>;
+};
+
+struct Y {
+protected:
+ template<class T>
+ struct B { T t; };
+
+private:
+ template<class T> B(T) -> B<T>; // { dg-error "access" }
+};
--- /dev/null
+// PR c++/100983
+// { dg-do compile { target c++17 } }
+
+struct X {
+ template<int N>
+ struct Y { template<class... Ts> Y(Ts...); };
+
+ template<class... Ts> Y(Ts...) -> Y<sizeof...(Ts)>;
+};
+
+X::Y y{1,2,3};