enum auto_deduction_context adc = adc_variable_type;
if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl))
adc = adc_decomp_type;
+ tree outer_targs = NULL_TREE;
+ if (flag_concepts
+ && PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
+ && VAR_P (decl)
+ && DECL_LANG_SPECIFIC (decl)
+ && DECL_TEMPLATE_INFO (decl)
+ && !DECL_FUNCTION_SCOPE_P (decl))
+ /* The outer template arguments might be needed for satisfaction.
+ (For function scope variables, do_auto_deduction will obtain the
+ outer template arguments from current_function_decl.) */
+ outer_targs = DECL_TI_ARGS (decl);
type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
tf_warning_or_error, adc,
- NULL_TREE, flags);
+ outer_targs, flags);
if (type == error_mark_node)
return;
if (TREE_CODE (type) == FUNCTION_TYPE)
--- /dev/null
+// PR c++/103341
+// { dg-do compile { target c++20 } }
+
+template<class T, class U> concept same_as = __is_same(T, U);
+template<class T>
+struct A {
+ static inline same_as<T> auto value = 0; // { dg-error "constraint" }
+};
+
+template struct A<int>; // { dg-bogus "" }
+template struct A<bool>; // { dg-message "required from here" }
--- /dev/null
+// PR c++/103341
+// { dg-do compile { target c++20 } }
+
+template<class T, class U> concept same_as = __is_same(T, U);
+template<class T> same_as<T> auto v1a = 1;
+template<class T> same_as<T> auto v1b = T();
+template<class T> same_as<T*> auto v2a = 1; // { dg-error "constraints" }
+template<class T> same_as<T*> auto v2b = T(); // { dg-error "constraints" }
+
+template int v1a<int>;
+template int v1b<int>;
+template int v2a<int>; // { dg-message "required from here" }
+template int v2b<int>; // { dg-message "required from here" }