<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Oct 8, 2010, at 9:14 AM, James Noble wrote:</div><blockquote type="cite"><div>On Oct 8, 2010, at 11:47 AM, Argyrios Kyrtzidis wrote:<br><blockquote type="cite">Why are we requiring a definition for Test::value, isn't this supposed to be used as a constant ? John ?<br></blockquote><font class="Apple-style-span" color="#006312"><br></font>I think the C++ standard mandates that even a static const variable must have a<br>definition. I think some compilers allow integral types to skirt around that but<br>I think this is why there is the "enum hack" for C++ ...<br></div></blockquote></div><br><div>This is not quite correct. The standard says that a definition must given for a static const literal-typed data member if it is used in the program. "Used" is actually a term of art from [basic.def.odr]p2:</div><div> <span class="Apple-style-span" style="font-size: 10px; ">A variable or non-overloaded function whose name appears as a potentially-evaluated expression is used unless it is an object that satisfies the requirements for appearing in a constant expression </span><span class="Apple-style-span" style="font-size: 10px; ">and the lvalue-to-rvalue conversion </span><span class="Apple-style-span" style="font-size: 10px; ">is immediately applied.</span></div><div>So this is actually a point of non-compliance for us with C++0x, which is okay because we don't actually claim to support C++0x. Nonetheless, we should implement this.</div><div><br></div><div>The enum hack is useful mostly because it's easy to accidentally bind a reference to a const static data member and thus "use" it according to the standard — usually because some template function takes a 'const T &' (to avoid unnecessary copies of aggregate arguments) and then 'T' gets instantiated with 'int' and suddenly you're binding to the variable instead of a temporary. Never let it be said that C++ is not an awful language.</div><div><br></div><div>John.</div></body></html>