public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101937] New: error: variable-sized object may not be initialized
@ 2021-08-16 13:17 unlvsur at live dot com
2021-08-16 13:23 ` [Bug libstdc++/101937] " rguenth at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: unlvsur at live dot com @ 2021-08-16 13:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
Bug ID: 101937
Summary: error: variable-sized object may not be initialized
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: unlvsur at live dot com
Target Milestone: ---
const char spacing[ctx._M_indent + 1] = " ";
VLA does not initialize variable. GCC does not detect this. However when I use
clang --target=wasm32-wasi, clang complains it.
https://github.com/gcc-mirror/gcc/blob/e660441f94f2ca2ca1bd63c922c6a43737c2259e/libstdc%2B%2B-v3/src/c%2B%2B11/debug.cc#L628
../../../../gcc/libstdc++-v3/src/c++11/debug.cc:628:17: error: variable-sized
object may not be initialized
const char spacing[ctx._M_indent + 1] = " ";
^ ~~~~~~
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
@ 2021-08-16 13:23 ` rguenth at gcc dot gnu.org
2021-08-16 13:26 ` jakub at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-08-16 13:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
but it's 'const' so it must be initialized?
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
2021-08-16 13:23 ` [Bug libstdc++/101937] " rguenth at gcc dot gnu.org
@ 2021-08-16 13:26 ` jakub at gcc dot gnu.org
2021-08-16 14:09 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-16 13:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
VLAs are an extension in C++, so there is no standard that says whether they
can or can't be initialized. C99 says they can't, but that doesn't mean they
can't be in C++...
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
2021-08-16 13:23 ` [Bug libstdc++/101937] " rguenth at gcc dot gnu.org
2021-08-16 13:26 ` jakub at gcc dot gnu.org
@ 2021-08-16 14:09 ` redi at gcc dot gnu.org
2021-08-16 14:13 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-16 14:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's not a VLA though, _M_indent is an enumerator with the value 4, and
ctx._M_index + 1 is 5.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
` (2 preceding siblings ...)
2021-08-16 14:09 ` redi at gcc dot gnu.org
@ 2021-08-16 14:13 ` redi at gcc dot gnu.org
2021-08-16 14:15 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-16 14:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Clang accepts this:
struct S {
enum { _M_indent = 4 };
};
int f(S s)
{
const char str[s._M_indent + 1] = " ";
return sizeof(str);
}
But rejects the same program with a reference parameter:
struct S {
enum { _M_indent = 4 };
};
int f(S& s)
{
const char str[s._M_indent + 1] = " ";
return sizeof(str);
}
This will fix it for clang:
--- a/libstdc++-v3/src/c++11/debug.cc
+++ b/libstdc++-v3/src/c++11/debug.cc
@@ -625,8 +625,8 @@ namespace
// If this isn't the first line, indent
if (ctx._M_column == 1 && !ctx._M_first_line)
{
- const char spacing[ctx._M_indent + 1] = " ";
- print_raw(ctx, spacing, ctx._M_indent);
+ const char spacing[PrintContext::_M_indent + 1] = " ";
+ print_raw(ctx, spacing, PrintContext::_M_indent);
}
int written = fprintf(stderr, "%.*s", (int)length, word);
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
` (3 preceding siblings ...)
2021-08-16 14:13 ` redi at gcc dot gnu.org
@ 2021-08-16 14:15 ` jakub at gcc dot gnu.org
2021-08-16 14:16 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-16 14:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Do we need to work around clang bugs here though? In headers I can understand
it, but this is in the libstdc++.{so,a} only code.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
` (4 preceding siblings ...)
2021-08-16 14:15 ` jakub at gcc dot gnu.org
@ 2021-08-16 14:16 ` redi at gcc dot gnu.org
2021-08-16 14:38 ` unlvsur at live dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-16 14:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-08-16
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The problem is that ctx._M_indent is a member access expression through a
reference, which is not allowed in constant expressions. This is a silly
restriction that https://wg21.link/p2280r2 aims to change.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
` (5 preceding siblings ...)
2021-08-16 14:16 ` redi at gcc dot gnu.org
@ 2021-08-16 14:38 ` unlvsur at live dot com
2021-08-16 16:52 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: unlvsur at live dot com @ 2021-08-16 14:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
--- Comment #7 from cqwrteur <unlvsur at live dot com> ---
(In reply to Jakub Jelinek from comment #5)
> Do we need to work around clang bugs here though? In headers I can
> understand it, but this is in the libstdc++.{so,a} only code.
well i love gcc, however, unfortunately, gcc does not provide webassembly
backend ( wasm32/64-wasi).
The only thing i could do is to use clang to compile libstdc++ and get partial
experience with it.
hope you guys can work on providing backend in the future.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
` (6 preceding siblings ...)
2021-08-16 14:38 ` unlvsur at live dot com
@ 2021-08-16 16:52 ` cvs-commit at gcc dot gnu.org
2021-08-16 16:54 ` redi at gcc dot gnu.org
2021-08-16 18:24 ` pinskia at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-16 16:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:6c25932ac399423b09b730fb8f894ada568deb2a
commit r12-2933-g6c25932ac399423b09b730fb8f894ada568deb2a
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Aug 16 15:35:58 2021 +0100
libstdc++: Use qualified-id for class member constant [PR101937]
The expression ctx._M_indent is not a constant expression when ctx is a
reference parameter, even though _M_indent is an enumerator. Rename it
to _S_indent to be consistent with our conventions, and refer to it as
PrintContext::_S_indent to be valid C++ code (at least until P2280 is
accepted as a DR).
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
PR libstdc++/101937
* src/c++11/debug.cc (PrintContext::_M_indent): Replace with a
static data member.
(print_word): Use qualified-id to access it.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
` (7 preceding siblings ...)
2021-08-16 16:52 ` cvs-commit at gcc dot gnu.org
@ 2021-08-16 16:54 ` redi at gcc dot gnu.org
2021-08-16 18:24 ` pinskia at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-16 16:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/101937] error: variable-sized object may not be initialized
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
` (8 preceding siblings ...)
2021-08-16 16:54 ` redi at gcc dot gnu.org
@ 2021-08-16 18:24 ` pinskia at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-16 18:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101937
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> The problem is that ctx._M_indent is a member access expression through a
> reference, which is not allowed in constant expressions. This is a silly
> restriction that https://wg21.link/p2280r2 aims to change.
Just FYI the GCC bug accepting this code is PR 72756.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-08-16 18:24 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 13:17 [Bug libstdc++/101937] New: error: variable-sized object may not be initialized unlvsur at live dot com
2021-08-16 13:23 ` [Bug libstdc++/101937] " rguenth at gcc dot gnu.org
2021-08-16 13:26 ` jakub at gcc dot gnu.org
2021-08-16 14:09 ` redi at gcc dot gnu.org
2021-08-16 14:13 ` redi at gcc dot gnu.org
2021-08-16 14:15 ` jakub at gcc dot gnu.org
2021-08-16 14:16 ` redi at gcc dot gnu.org
2021-08-16 14:38 ` unlvsur at live dot com
2021-08-16 16:52 ` cvs-commit at gcc dot gnu.org
2021-08-16 16:54 ` redi at gcc dot gnu.org
2021-08-16 18:24 ` pinskia 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).