This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/70126] VLA accepted in sizeof and typedef, allowing integer overflow


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70126

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Yes, there are some significant differences between C99 VLAs and N3639.  I
don't know how common using sizeof with VLA types is in C++.  I suspect not
very.

VLAs never did make it into C++ 14 (though I'm not sure if they will stay out
of C++ 17 or whichever next version finally adopts a more recent version of the
C standard), but they will very likely continue to be supported by G++ for C
(and GCC) compatibility.  The problem is that the current G++ implementation is
a hybrid of N3639 and C11, with the most treacherous elements included from
each (G++ allows initialization which disallowed by C, and as noted in bug
70075, for example, gets it wrong, and it allows applying sizeof to VLA
typedefs which is disallowed by N3639, and as noted in this bug, gets that
wrong as well).

I think a good way to resolve this bug would be in the same spirit as in my
proposed patch for bug 69517: by continuing to accept VLA typedefs and VLA
types in [runtime] sizeof expressions (perhaps with a warning noting that they
are evaluated at runtime) for compatibility with C, and by having the sizeof
expression throw an exception on overflow.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]