Date: Tue, 12 Nov 2024 01:33:02 +0100
On 11/11/2024 23.56, mauro russo wrote:
>>> "if two function definitions containing the expressions..." -> should it mean in the declarative part only of the definition or even in the body ?
>
>> In the body. We want to apply the one-definition rule on the result.
>
> Is it problematic to specify this detail on the 'body' ? A single word that would faster lead the reader mind on the correct way.
> Moreover, I didn't get what "on the result" exactly means. The best guessing is on the two definitions.
> Anyway, I still believe that more information should be provided, for example what else is in these two definitions (likely, nothing else), and maybe even the fact that we mean two definitions of the same function (despite, of course, a disussion about ODR is meaningless if not so).
So, you seem to agree that's clear enough.
> Well, being in the same context is a good candidate for the additional information to be explicit in §13.7.6.1-5.
> On the other hand, if the two expressions start from the same context, why we should care of specifying "except for the different naming" ? I don't believe the intent was just about aliases (e.g., see Note 1 in §13.6-4). Am I missing something here ?
Yes, different names of template parameters.
> Anyway, I still see a bit cryptic that §13.6-(16.3) would apply to such a hypotetical context (currently never mentioned) so that, as a consequence, it applies to the two functions.
For example, there might be references to global variables or
global typedefs. Those must name the same things for both
hypothetical definitions.
> And... did I miss the fact that ODR reads somewhere about "same meaning" instead of "same tokens" ?
Yes.
[basic.def.odr] p15.4 is "same tokens".
p15.5 is "same meaning" (of those tokens).
>> [temp.type] is for declaration matching and similar situations
>> where types need to be compared before instantiation.
>> In your example, the function template "f" is instantiated when
>> that's needed (because you call it from "main"), and the instantiation
>> produces a non-dependent function body by substituting "int" for "T"
>> everywhere. Since nothing is dependent anymore after this, the special
>> rule for decltype(e) in [temp.type] doesn't apply at this stage.
>
> Ok, thank you to clarify, here for sure I miss knowledge about the definition of 'dependent types'.
> Might you be so kind to present a scenario we may need to compare two decltype(dependent_expr) before instantiations ?
There are examples in [temp.over.link] p5 (example 3) that
might clarify.
Another example:
template<class T>
void f(decltype(T() + T()));
template<class U>
void f(decltype(U() + U{}));
Are these two declarations declaring the same function template?
The difference in template parameter names is ok, but there
are different tokens involved for the first parameter type,
so those declarations declare different overloads.
The standard is not a tutorial.
Jens
>>> "if two function definitions containing the expressions..." -> should it mean in the declarative part only of the definition or even in the body ?
>
>> In the body. We want to apply the one-definition rule on the result.
>
> Is it problematic to specify this detail on the 'body' ? A single word that would faster lead the reader mind on the correct way.
> Moreover, I didn't get what "on the result" exactly means. The best guessing is on the two definitions.
> Anyway, I still believe that more information should be provided, for example what else is in these two definitions (likely, nothing else), and maybe even the fact that we mean two definitions of the same function (despite, of course, a disussion about ODR is meaningless if not so).
So, you seem to agree that's clear enough.
> Well, being in the same context is a good candidate for the additional information to be explicit in §13.7.6.1-5.
> On the other hand, if the two expressions start from the same context, why we should care of specifying "except for the different naming" ? I don't believe the intent was just about aliases (e.g., see Note 1 in §13.6-4). Am I missing something here ?
Yes, different names of template parameters.
> Anyway, I still see a bit cryptic that §13.6-(16.3) would apply to such a hypotetical context (currently never mentioned) so that, as a consequence, it applies to the two functions.
For example, there might be references to global variables or
global typedefs. Those must name the same things for both
hypothetical definitions.
> And... did I miss the fact that ODR reads somewhere about "same meaning" instead of "same tokens" ?
Yes.
[basic.def.odr] p15.4 is "same tokens".
p15.5 is "same meaning" (of those tokens).
>> [temp.type] is for declaration matching and similar situations
>> where types need to be compared before instantiation.
>> In your example, the function template "f" is instantiated when
>> that's needed (because you call it from "main"), and the instantiation
>> produces a non-dependent function body by substituting "int" for "T"
>> everywhere. Since nothing is dependent anymore after this, the special
>> rule for decltype(e) in [temp.type] doesn't apply at this stage.
>
> Ok, thank you to clarify, here for sure I miss knowledge about the definition of 'dependent types'.
> Might you be so kind to present a scenario we may need to compare two decltype(dependent_expr) before instantiations ?
There are examples in [temp.over.link] p5 (example 3) that
might clarify.
Another example:
template<class T>
void f(decltype(T() + T()));
template<class U>
void f(decltype(U() + U{}));
Are these two declarations declaring the same function template?
The difference in template parameter names is ok, but there
are different tokens involved for the first parameter type,
so those declarations declare different overloads.
The standard is not a tutorial.
Jens
Received on 2024-11-12 00:33:05