From: Sergey Sadovnikov <flex_ferrum@artberg.ru>
To: gcc@gcc.gnu.org
Subject: Is this code legal?
Date: Mon, 05 Oct 2009 19:29:00 -0000 [thread overview]
Message-ID: <3910074625.20091005232911@artberg.ru> (raw)
Hello all.
I try to compile the following code sample:
(with MinGW gcc version 4.5.0 20090819 (experimental) (GCC))
#include <iostream>
#include <algorithm>
#include <array>
template<wchar_t... Chars>
struct Message
{
std::array<wchar_t, sizeof ... (Chars)> m_Message;
Message() : m_Message{Chars...} // {*1}
{
std::array<wchar_t, sizeof ... (Chars)> msg = {Chars ... }; // {*2}
}
};
int main(int argc, char* argv[])
{
setlocale(LC_ALL, ".OCP");
Message<L'\x421', L'\x20', L'\x434', L'\x43D', L'\x451', L'\x43C', L'\x20', L'\x43F', L'\x440', L'\x43E',
L'\x433', L'\x440', L'\x430', L'\x43C', L'\x43C', L'\x438', L'\x441', L'\x442', L'\x430', L'\x2C', L'\x20', L'\x43A',
L'\x43E', L'\x43B', L'\x43B', L'\x435', L'\x433', L'\x438', L'\x21', L'\n'
> msg;
std::for_each(msg.m_Message.begin(), msg.m_Message.end(), [](wchar_t c){std::wcout << c;});
return 0;
}
Can anybody explain why line marked with '{*1}' produce this error
message:
hello_programmer.cpp: In constructor 'Message<Chars>::Message() [with wchar_t ...Chars = 1057u, 32u, 1076u, 1085u, 1105u
, 1084u, 32u, 1087u, 1088u, 1086u, 1075u, 1088u, 1072u, 1084u, 1084u, 1080u, 1089u, 1090u, 1072u, 44u, 32u, 1082u, 1086u
, 1083u, 1083u, 1077u, 1075u, 1080u, 33u, 10u]':
hello_programmer.cpp:48:15: instantiated from here
hello_programmer.cpp:34:35: error: could not convert '{1057u, 32u, 1076u, 1085u, 1105u, 1084u, 32u, 1087u, 1088u, 1086u,
1075u, 1088u, 1072u, 1084u, 1084u, 1080u, 1089u, 1090u, 1072u, 44u, 32u, 1082u, 1086u, 1083u, 1083u, 1077u, 1075u, 1080
u, 33u, 10u}' to 'std::array<wchar_t, 30u>'
Line marked with '{*2}' is compiled successfully.
Or there is no standard-conforming way to initialize std::array
within constructor initializer list?
-------------
Best regards, Sergey.
next reply other threads:[~2009-10-05 19:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-05 19:29 Sergey Sadovnikov [this message]
2009-10-06 10:05 ` Paolo Bonzini
2009-10-06 18:59 ` Re[2]: " Sergey Sadovnikov
2009-10-10 15:01 ` Linkage problem with rescent gcc 4.5 in MinGW build Sergey Sadovnikov
2009-10-10 15:17 ` Kai Tietz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3910074625.20091005232911@artberg.ru \
--to=flex_ferrum@artberg.ru \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).