cplusplus / CWG

Core Working Group
24 stars 7 forks source link

P2449 Whether two explicit specializations declare the same entity or not? #72

Open xmh0511 opened 2 years ago

xmh0511 commented 2 years ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

In general, two declarations that correspond and satisfy [basic.link] p8 can declare the same entity. However, [temp.expl.spec] p4 explicitly says

An explicit specialization does not introduce a name ([basic.scope.scope]).

So, the rule regarding whether two declarations correspond([basic.scope.scope] p4) cannot apply to explicit specializations.

Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unless

template<class T>
struct S{};

template<>
struct S<int>{};  // #1

template<>
struct S<int>{  // #2
   int a;
};

So, how to determine whether #1 and #2 declare the same entity and therefore violate [basic.def.odr]? We cannot find any proof in the standard. Unlike [temp.spec.partial] explicitly regulates that

Two partial specialization declarations declare the same entity if they are partial specializations of the same template and have equivalent template-heads and template argument lists ([temp.over.link]).

Which overwrites the common rule about whether two declarations declare the same entity(although whether template argument lists are equivalent is not clear, which is CWG2584). Explicit instantiation also has the same issue as an explicit specialization for whether two declarations declare the same entity or not.

opensdh commented 2 years ago

D2449R0 (the sequel to P1787, not yet published anywhere) already addresses this.

xmh0511 commented 2 years ago

D2449R0 (the sequel to P1787, not yet published anywhere) already addresses this.

Does D2449R0 consider CWG2584?

jensmaurer commented 2 years ago

CWG2548 talks about "Array prvalues and additive operators". That seems unrelated.

xmh0511 commented 2 years ago

CWG2548 talks about "Array prvalues and additive operators". That seems unrelated.

Thanks. I gave the wrong CWG number. It is CWG2584.

opensdh commented 2 years ago

No, since the inadequate definition of equivalence predates P1787 and isn't fundamentally a lookup concern. However, see also CWG2603.

xmh0511 commented 2 years ago

No, since the inadequate definition of equivalence predates P1787 and isn't fundamentally a lookup concern. However, see also CWG2603.

Since "correspond" is introduced by P1787 and the definition depends on the equivalence in [temp.over.link], so [temp.over.link] should be revamped.