Skip to content

[clang] Incomplete treatment for non-deduced context with nested template #121208

@frederick-vs-ja

Description

@frederick-vs-ja

Currently, Clang doesn't accept the following code snippet, while other implementations do (demo).

template <template <typename> class>
struct B;

struct C {
  template <typename>
  struct Nested;
};

template <typename T>
void f(T*, B<T::template Nested>*);

void g(C *cp, B<C::template Nested>* bcnp) {
  f(cp, 0);
}

When 0 is replaced with {} (but not nullptr or any real null pointer constant), Clang also accept it (demo).

The following similar example is rejected by all implemenations (demo), and shows that Clang also considers that T is not deducible from B<T::template Nested>* (and thus B<T::template Nested>* forms non-deduced context for T). Although the current standard wording is possibly defective on this (see cplusplus/CWG#660).

template <template <typename> class>
struct B;

struct C {
  template <typename>
  struct Nested;
};

template <typename T>
void f(T*, B<T::template Nested>*);

void g(C *cp, B<C::template Nested>* bcnp) {
  f({}, bcnp);
}

Given that T is (or should be considered) in the non-deduced context in B<T::template Nested>*, Clang should not try to match B<T::template Nested>* against int (or std::nullptr_t), and should just take 0 (or nullptr) as null pointer constant instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions