|| TREE_CODE (T) == TYPENAME_TYPE \
|| TREE_CODE (T) == TYPEOF_TYPE \
|| TREE_CODE (T) == BOUND_TEMPLATE_TEMPLATE_PARM \
+ || TREE_CODE (T) == UNBOUND_CLASS_TEMPLATE \
|| TREE_CODE (T) == DECLTYPE_TYPE \
|| TREE_CODE (T) == TRAIT_TYPE \
|| TREE_CODE (T) == DEPENDENT_OPERATOR_TYPE \
tree t = *tp;
if (TREE_CODE (t) == PTRMEM_CST)
t = PTRMEM_CST_MEMBER (t);
+
+ if (TREE_CODE (t) == TEMPLATE_DECL)
+ {
+ if (DECL_ALIAS_TEMPLATE_P (t) || concept_definition_p (t))
+ /* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
+ alias templates so we can't trust it here (PR107906). Ditto
+ for concepts. */
+ return NULL_TREE;
+ t = DECL_TEMPLATE_RESULT (t);
+ if (!t)
+ return NULL_TREE;
+ }
+
switch (TREE_CODE (t))
{
case CAST_EXPR:
case NEW_EXPR:
case CONSTRUCTOR:
case LAMBDA_EXPR:
+ case TYPE_DECL:
tpvis = type_visibility (TREE_TYPE (t));
break;
- case TEMPLATE_DECL:
- if (DECL_ALIAS_TEMPLATE_P (t) || concept_definition_p (t))
- /* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
- alias templates so we can't trust it here (PR107906). Ditto
- for concepts. */
- break;
- t = DECL_TEMPLATE_RESULT (t);
- /* Fall through. */
case VAR_DECL:
case FUNCTION_DECL:
if (decl_constant_var_p (t))
--- /dev/null
+// PR c++/118846
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi M }
+
+export module M;
+
+template <int N> struct integral_constant { static constexpr int value = N; };
+template <template <class> class> constexpr int cx_count_if() { return 0; }
+template <template <class> class P> struct mp_count_if_impl {
+ using type = integral_constant<cx_count_if<P>()>;
+};
+
+template <template <class> class> struct consume {
+ static constexpr bool value = true;
+};
+template <class P> struct use {
+ using type = consume<P::template fn>;
+};
--- /dev/null
+// PR c++/118846
+// { dg-additional-options "-fmodules" }
+
+module M;
+
+template <typename> struct S {
+ template <typename> struct fn {};
+};
+static_assert(mp_count_if_impl<S>::type::value == 0);
+static_assert(use<S<int>>::type::value);