public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61122] New: too many initializers
@ 2014-05-09 4:32 f.heckenbach@fh-soft.de
2014-05-09 10:41 ` [Bug c++/61122] "too many initializers" for NSDMI for array of unknown bound redi at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: f.heckenbach@fh-soft.de @ 2014-05-09 4:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61122
Bug ID: 61122
Summary: too many initializers
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: f.heckenbach@fh-soft.de
g++ says "too many initializers" for an array of vectors with initializers, but
only within a struct.
Not sure if it should work (I don't see why not), but it seems inconsistent
that it only fails within a struct. Also, the error message is misleading ("too
many initializers" even for an empty brace-list).
#include <vector>
std::vector <int> a1[] { { } };
std::vector <int> a2[] { { 1, 2, 3 } };
std::vector <int> a3[] { std::vector <int> () };
std::vector <int> a4[] { std::vector <int> (1) };
struct s
{
std::vector <int> b1[] { { } };
std::vector <int> b2[] { { 1, 2, 3 } };
std::vector <int> b3[] { std::vector <int> () };
std::vector <int> b4[] { std::vector <int> (1) };
};
% g++ -std=c++11 test.cpp
test.cpp:10:32: error: too many initializers for 'std::vector<int> [0]'
test.cpp:11:40: error: too many initializers for 'std::vector<int> [0]'
test.cpp:12:49: error: too many initializers for 'std::vector<int> [0]'
test.cpp:13:50: error: too many initializers for 'std::vector<int> [0]'
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/61122] "too many initializers" for NSDMI for array of unknown bound
2014-05-09 4:32 [Bug c++/61122] New: too many initializers f.heckenbach@fh-soft.de
@ 2014-05-09 10:41 ` redi at gcc dot gnu.org
2014-05-09 10:45 ` f.heckenbach@fh-soft.de
2014-05-09 11:13 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-09 10:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61122
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-05-09
Summary|too many initializers |"too many initializers" for
| |NSDMI for array of unknown
| |bound
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think you can specify an array bound from an NSDMI, but the diagnostic
is not very helpful.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/61122] "too many initializers" for NSDMI for array of unknown bound
2014-05-09 4:32 [Bug c++/61122] New: too many initializers f.heckenbach@fh-soft.de
2014-05-09 10:41 ` [Bug c++/61122] "too many initializers" for NSDMI for array of unknown bound redi at gcc dot gnu.org
@ 2014-05-09 10:45 ` f.heckenbach@fh-soft.de
2014-05-09 11:13 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: f.heckenbach@fh-soft.de @ 2014-05-09 10:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61122
--- Comment #2 from Frank Heckenbach <f.heckenbach@fh-soft.de> ---
If it's not allowed, it should also fail at file-scope or function-scope,
shouldn't it?
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/61122] "too many initializers" for NSDMI for array of unknown bound
2014-05-09 4:32 [Bug c++/61122] New: too many initializers f.heckenbach@fh-soft.de
2014-05-09 10:41 ` [Bug c++/61122] "too many initializers" for NSDMI for array of unknown bound redi at gcc dot gnu.org
2014-05-09 10:45 ` f.heckenbach@fh-soft.de
@ 2014-05-09 11:13 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-09 11:13 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61122
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No. At file or function scope the initializer is definitely used, and can
provide the array bound. On a non-static data member it is not used until the
object is constructed (and then might be ignored if there's a mem-initializer
for the member) and that's too late, the array bound for non-static data
members must be known at class definition time to know sizeof(s).
That's my understanding, and I've just checked clang agrees, with a better
diagnostic:
in.cc:10:26: error: array bound cannot be deduced from an in-class initializer
std::vector <int> b1[] { { } };
^
in.cc:11:26: error: array bound cannot be deduced from an in-class initializer
std::vector <int> b2[] { { 1, 2, 3 } };
^
in.cc:12:26: error: array bound cannot be deduced from an in-class initializer
std::vector <int> b3[] { std::vector <int> () };
^
in.cc:13:26: error: array bound cannot be deduced from an in-class initializer
std::vector <int> b4[] { std::vector <int> (1) };
^
4 errors generated.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-09 11:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-09 4:32 [Bug c++/61122] New: too many initializers f.heckenbach@fh-soft.de
2014-05-09 10:41 ` [Bug c++/61122] "too many initializers" for NSDMI for array of unknown bound redi at gcc dot gnu.org
2014-05-09 10:45 ` f.heckenbach@fh-soft.de
2014-05-09 11:13 ` redi at gcc dot gnu.org
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).