On 7/5/21 10:18 AM, Matthias Kretz wrote:
On Thursday, 1 July 2021 17:18:26 CEST Jason Merrill wrote:
You probably want to adjust is_late_template_attribute to change that.

Right, I hacked is_late_template_attribute but now I only see a TYPE_DECL
passed to my attribute handler (!DECL_ALIAS_TEMPLATE_P). > I.e. I don't know how
your previous comment is supposed to help me:

On Tuesday, 22 June 2021 22:12:42 CEST Jason Merrill wrote:
Yes.  You can check that with get_underlying_template.

FWIW, I don't feel qualified to implement the diagnose_as attribute on alias
templates. The trees I've seen while testing the following test case don't
make sense to me. :(


// { dg-do compile { target c++11 } }
// { dg-options "-fdiagnostics-use-aliases -fpretty-templates" }

template <typename T> class A0 {};
template <typename T> using B0 [[gnu::diagnose_as]] = A0<T>; // #1
template <typename T> using C0 [[gnu::diagnose_as]] = A0<T*>; // #2

template <typename T> class A1 {};
template <typename T> class A1<T*> {};
template <typename T> using B1 [[gnu::diagnose_as]] = A1<T*>; // #3

void fn_1(int);

int main ()
{
   fn_1 (A0<float> ()); // { dg-error "cannot convert 'B0<float>' to 'int'" }
   fn_1 (A1<float> ()); // { dg-error "cannot convert 'A1<float>' to 'int'" }
   fn_1 (A1<float*> ()); // { dg-error "cannot convert 'B1<float>' to 'int'" }
}

On #1 I see !COMPLETE_TYPE_P (TREE_TYPE (*node))

Yes; a use that matches the primary template but is not the primary template gets a separate dependent type.

while on #3 TREE_TYPE (*node) is a complete type.

Indeed, we don't do the same thing for partial specializations.

Like I said, I don't get to see the TEMPLATE_DECL of
either #1, #2, or #3, only a TYPE_DECL whose TREE_TYPE is A0. I thus have no
idea how to reject #2.

The difference between #1 and #2 is that same_type_p (#1, CLASSTYPE_PRIMARY_TEMPLATE_TYPE (TREE_TYPE (#1)) is true; see the use of that in resolve_typename_type.

Jason

Reply via email to