Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
frederick-vs-ja opened this issue Dec 27, 2024 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@frederick-vs-ja
Copy link
Contributor

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.

@frederick-vs-ja frederick-vs-ja added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Dec 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 27, 2024

@llvm/issue-subscribers-clang-frontend

Author: A. Jiang (frederick-vs-ja)

Currently, Clang doesn't accept the following code snippet, while other implementations do ([demo](https://godbolt.org/z/Yccjc95Eb)).
template &lt;template &lt;typename&gt; class&gt;
struct B;

struct C {
  template &lt;typename&gt;
  struct Nested;
};

template &lt;typename T&gt;
void f(T*, B&lt;T::template Nested&gt;*);

void g(C *cp, B&lt;C::template Nested&gt;* 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&lt;T::template Nested&gt;* (and thus B&lt;T::template Nested&gt;* forms non-deduced context for T). Although the current standard wording is possibly defective on this (see cplusplus/CWG#660).

template &lt;template &lt;typename&gt; class&gt;
struct B;

struct C {
  template &lt;typename&gt;
  struct Nested;
};

template &lt;typename T&gt;
void f(T*, B&lt;T::template Nested&gt;*);

void g(C *cp, B&lt;C::template Nested&gt;* bcnp) {
  f({}, bcnp);
}

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

@frederick-vs-ja frederick-vs-ja changed the title [clang] Incomplete treatement for non-deduced context with nested template [clang] Incomplete treatment for non-deduced context with nested template Dec 27, 2024
@hubert-reinterpretcast
Copy link
Collaborator

hubert-reinterpretcast commented Dec 27, 2024

Although the current standard wording is possibly defective on this (see cplusplus/CWG#660).

The following case does not rely (in the wording: https://wg21.link/temp.spec.partial.match#3) on the definition of non-deduced context.

template <template <typename> class>
struct B;

template <typename T>
struct B<T::template Nested>;

It seems both Clang and GCC have a bug here: https://godbolt.org/z/qvfGYhWT4

@shafik
Copy link
Collaborator

shafik commented Dec 28, 2024

CC @erichkeane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

4 participants