Skip to content

Incorrect name qualification in AST / diagnostics for alias CTAD #136624

@mizvekov

Description

@mizvekov

Consider this example: https://compiler-explorer.com/z/bGqdsa3qc

template<typename U> struct A {
  U t;
};

template<typename V> A(V) -> A<V>;

namespace foo {
  template<class Y> using Alias = A<Y>;
}

foo::Alias t = 0;

Produces:

error: no viable conversion from 'int' to 'foo::A<int>' (aka 'A<int>')

Note that the foo:: qualification is applied to Alias in the source code, which is in that namespace, but
on the AST (and consequently in the diagnostic) it gets applied to A , where it cannot be found.

The problem here is many fold:

  1. We have an elaborated type including foo:: over the deduced template specialization (DTST), which names foo::Alias.
  2. However, when printing a DTST which has already been deduced, we choose to print it as the deduced type instead, probably for diagnostics reasons (although this is wrong for -ast-print, and we don't control this with a policy).
  3. For alias CTAD, we don't build a guide which actually contains the alias template specialization Alias<int>, instead the guide contains A<int>.

I see a couple of solutions:

  • If we fix 3, then this would print as intended: 'foo::Alias<int>' (aka 'A<int>')
  • We could stop doing 2, then this would print as 'foo::Alias' (aka 'A<int>').
    The first type does not include much information, as 2) probably intended to avoid, but it is correctly qualified, and then the 'aka' gives the missing information.

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions