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

[module.context] instantiation context of the enclosing specialization #4949

Open
xmh0511 opened this issue Sep 29, 2021 · 3 comments
Open

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 29, 2021

//Translation unit #1:

export module stuff;
export template<typename T, typename U> void foo(T, U u) { auto v = u; }
export template<typename T, typename U> void bar(T, U u) { auto v = *u; }  

//Translation unit #2:

export module M1;
import "defn.h";        // provides struct X {};
import stuff;
export template<typename T> void f(T t) {
  X x;
  foo(t, x);
}

// Translation unit #3:

export module M2;
import "decl.h";        // provides struct X; (not a definition)
import stuff;
export template<typename T> void g(T t) {
  X *x;
  bar(t, x);
}

// Translation unit #4:

import M1;
import M2;
void test() {
  f(0);
  g(0);
}

For f(0), the comment says that

the instantiation context of foo<int, X> comprises

  • the point at the end of translation unit #1,
  • the point at the end of translation unit #2, and
  • the point of the call to f(0),

For g(0), the comment says that

the instantiation context of bar<int, X> comprises

  • the point at the end of translation unit #1,
  • the point at the end of translation unit #3, and
  • the point of the call to g(0),

For every first bullet, the point is specified by [module.context#3]

During the implicit instantiation of a template whose point of instantiation is specified as that of an enclosing specialization ([temp.point]), the instantiation context is the union of the instantiation context of the enclosing specialization and, if the template is defined in a module interface unit of a module M and the point of instantiation is not in a module interface unit of M, the point at the end of the declaration-seq of the primary module interface unit of M (prior to the private-module-fragment, if any).

However, it is confusing about the second bullet for either f(0) or g(0). Which rule specifies that the end of TU2 is comprised by foo<int, X>, the end of TU3 is comprised by bar<int, X>? Specifically, is comprised by the enclosing specialization?

I think the emphasized wording just work for the template whose point of instantiation is specified as that of an enclosing specialization. In other words, [module.context] p3 should be parsed as that

During the implicit instantiation of a template T whose point of instantiation is specified as that of an enclosing specialization ([temp.point]), the instantiation context is the union of the instantiation context of the enclosing specialization and, if the template T is defined in a module interface unit of a module M and the point of instantiation is not in a module interface unit of M, the point at the end of the declaration-seq of the primary module interface unit of M (prior to the private-module-fragment, if any).

Except that the emphasized wording intends to work for the arbitrary template it is saying, it does not make sense the end of TU2 or TU3 is comprised.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 30, 2021

@languagelawyer Is any thought here. I'm confused by this example.

@languagelawyer
Copy link
Contributor

I know nothing about templates and modules

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 30, 2021

@jensmaurer Could you please take a look at this? It seems to make no sense the TU2 or TU3 is a point in an instantiation context as per the current wording.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants