https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119179
--- Comment #2 from Giuseppe D'Angelo <dangelog at gmail dot com> ---
For instance something like this:
class VLA
{
private:
static constexpr int DEFAULT_CAP = 256;
int m_size = 0;
int m_capacity = DEFAULT_CAP;
int m_data[DEFAULT_CAP]; // uninit; just storage
int *m_ptr = m_data; // points to the heap if exceeds local capacity
public:
VLA() = default;
~VLA() {
if (m_ptr != m_data)
delete[] m_ptr; // e.g. like this
}
void push_back(int);
// ...
};
which is basically a "std::vector<int> with SBO", found in many variations in
many codebases. Using this class causes the stack to be filled with 0xFE
https://gcc.godbolt.org/z/Mhvvv5eKo .
But the point of using a VLA class is to be performant, and the internal
invariants shouldn't cause anything unsafe to be read, so the filling sounds
counter-productive. I don't want to find every usage of VLA in a codebase and
add [[uninitialized]] to it, I'd rather add it to the class itself or to the
member I want to keep NOT filled.
By the way: while reducing this example, I've noted that if one uses `VLA()
{}`, then the byte-filling gets disabled. Is it intended? It's not exactly
discussed
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-ftrivial-auto-var-init
, and I guess could be an acceptable workaround.