Topic: Defect? Initialisation order of class template static data members
Author: dmh0xq001@sneakemail.com (Alan Stokes)
Date: Sat, 10 Aug 2002 11:37:40 GMT Raw View
Consider a program containing the following two translation units.
What order are S<int>::I1 and S<int>::I2 initialised in? 3.6.2/1
requires them to be initialised in the order their definitions appear
in each translation unit, but that order is different in the two
translation units.
(Multiple definitions of static data members of class templates are
explicitly allowed by the ODR - 3.2/5.)
=== Translation unit 1 ===
int f();
template <typename T> struct S { static int I1, I2; };
template <typename T> int S<T>::I1 = f();
template <typename T> int S<T>::I2 = f();
int g1() { return S<int>::I1 + S<int>::I2; }
=== Translation unit 2 ===
int f();
template <typename T> struct S { static int I1, I2; };
template <typename T> int S<T>::I2 = f();
template <typename T> int S<T>::I1 = f();
int g2() { return S<int>::I1 + S<int>::I2; }
=== End ===
- Alan
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: loewis@informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=)
Date: Sat, 10 Aug 2002 19:47:05 GMT Raw View
dmh0xq001@sneakemail.com (Alan Stokes) writes:
> Consider a program containing the following two translation units.
> What order are S<int>::I1 and S<int>::I2 initialised in? 3.6.2/1
> requires them to be initialised in the order their definitions appear
> in each translation unit, but that order is different in the two
> translation units.
It appears that this is issue 269, which has been closed as NAD, with
referral to 2.1/8.
Regards,
Martin
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Anthony Williams" <anthwil@nortelnetworks.com>
Date: Mon, 12 Aug 2002 21:14:33 GMT Raw View
dmh0xq001@sneakemail.com (Alan Stokes) writes:
> Consider a program containing the following two translation units.
> What order are S<int>::I1 and S<int>::I2 initialised in? 3.6.2/1
> requires them to be initialised in the order their definitions appear
> in each translation unit, but that order is different in the two
> translation units.
This is issue 270
(http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#270) --- the
committee decided that the order for initialization of static data members of
class templates is unspecified.
Anthony
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]