Re: anonymous enums and templates
On 11 Apr., 19:34, "Roman.Perepeli...@gmail.com"
<Roman.Perepeli...@gmail.com> wrote:
Is this program valid? Why? If yes then what it prints?
#include <iostream>
#include <ostream>
enum { value };
template <class T>
int f(T) { return 1; }
int f(int) { return 2; }
int main()
{
std::cout << f(value) << std::endl;
}
We have two problems here:
1) Does value have linkage?
2) If it does not, should that result in a compile-error
or should it be a (silent) type-deduction failure?
For (1), even with extended definition of "names-for-linkage-
purposes",
as described in
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#389
this case does not belong to the valid cases [It would be valid
according to the newer definition, if you would have written
typedef enum { value } SomeTypedefName;
instead]
Following this interpretation, the problematic point
is that 'value' does not have linkage. This is so,
because of [temp.arg.type]/2 says:
"A local type, a type with no linkage, an unnamed type
or a type compounded from any of these types shall
not be used as a template-argument for a template
type-parameter.[..]"
{The current draft has s shortened version of this:
"A type without linkage (3.5) shall not be used as a
template-argument for a template type-parameter."}
Whether this program is valid or not, is currently
still an open question - and (2) can currently not be
answered for your example - see:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#488
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]