Topic: Defect report: Is an extern thread_local a legal non-type reference template argument?
Author: Jeffrey Yasskin <jyasskin@gmail.com>
Date: Wed, 27 Jan 2010 22:28:01 CST Raw View
Is it legal to write:
extern thread_local int var;
template<int& r> void Tpl() { ... }
void Foo() {
Tpl<var>();
}
? N3000 has, in [temp.arg.nontype] p1:
"A template-argument for a non-type, non-template template-parameter
shall be one of:
...
the address of an ob ject or function with external linkage,
including function templates and function
template-id s but excluding non-static class members, expressed as &
id-expression where the & is
optional if the name refers to a function or array, or if the
corresponding template-parameter is a
reference; or"
thread_local objects have thread storage duration but can also have
external linkage, so it appears this is legal. It's surprising because
it means that uses of &r in Tpl() may or may not be
constant-expressions depending on the template argument and because
non-template uses of a thread_local name immediately bind to the
current thread's instance, rather than delaying the binding to the use
of the reference.
I believe the current standard is implementable, but undesirable. I'd
propose to change "with external linkage" to "with external linkage
and static storage duration".
Jeffrey Yasskin
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]