basic.odr, definition of "used" for templates
On 7 Okt., 19:52, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
Daniel Kr??gler wrote:
On 5 Okt., 10:57, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
Does the following program "use" the function "f"?
void f();
template<typename T>
void g() {
f();
}
int main() { }
3.2[basic.def.ord]p2:
"An expression is potentially evaluated unless it is an unevaluated
operand (Clause 5) or a subexpression thereof. A variable or
non-overloaded function whose name appears as a potentially-evaluated
expression is used unless it is an object that satis???es the requirements
for appearing in a constant expression (5.19) and the lvalue-to-rvalue
conversion (4.1) is immediately applied."
Is the above supplied program ill-formed because a definition of "f" is
missing ([basic.def.odr]p3)? If the program is valid, is there wording
that supports it?
I believe the wording does not allow for another interpretation
but that f() in g() is considered an potentially evaluated
expression, thus the program is ill-formed.
Does the same apply to the following?
template<typename T>
struct A {
void g() {
T t;
}
void f() {
g();
}
};
A<void> a;
Does the name of A<void>::g appear in a potentially evaluated expression and
cause instantiation of A<void>::g because it uses it? Or does it not use it, but
just A<T>::g ? When does it use A<void>::g? I'm unsure about this.
In this case the reference to 14.7.1/9 looks like the
most appropriate location to make this valid. This
example is different compared to your original example,
where parsing may deduce a usage from the non-dependent
name. In the new example we can no longer apply the
parsing rules again, because this step has already passed
before. When instantiation has happened, indeed the
argumentation of Jiang applies: There is nothing to
refer to at this point.
It's hard to point directly on the proper wording,
but I believe this situation is clear.
HTH & Greetings from Bremen,
Daniel Kr??gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]