cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[stmt.dcl] Distinguish objects associated with static block variable #208

Open xmh0511 opened 1 year ago

xmh0511 commented 1 year ago

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

As an augment of https://github.com/cplusplus/draft/issues/5349, the issue does not only exist in the thread but also exists within the instantiation of template entities.

[temp.fct.spec.general] p2 says

Each function template specialization instantiated from a template has its own copy of any static variable.

So, how about the specialization of member functions of the class template? We do not mention the case in the relevant subclause.

template<class T>
struct A{
    void fun(){
        static int value = 0;  // #1
        std::cout<<&value<<std::endl;
    }
};
int main() {
    A<int>{}.fun();
    A<char>{}.fun();
}

There lacks a wording that can distinguish the identity of the objects(entities) associated with the variable at #1.

opensdh commented 7 months ago

That paragraph should just be a note, or perhaps just the example, or even removed altogether. Of course A<int>::fun::value is not the same variable as A<char>::fun::value: they are local variables in different functions.

xmh0511 commented 7 months ago

Of course A::fun::value is not the same variable as A::fun::value: they are local variables in different functions.

IMO, we lack the wording to specify that such two entities cannot denote the same object.