Every LLM hallucinates that std::vector deletes elements in a LIFO order

2 min read Original article ↗

Aman's blog

I recently needed to delete objects in a LIFO manner and employed an LLM to rubber-duck about what would be the best container. All of them said std::vector. This confused me so I posed a simpler question to all leading LLMs, and it seems like they all think std::vector destructs elements from back to front.

Firstly, we can demonstrably prove this is false using godbolt, here's the simple program:

#include <vector>
#include <iostream>

struct A{
    int i{};

    A(int i_)
    :i(i_)
    {}
    ~A() {
        std::cout << "Destruct " << i << std::endl;
    }
};

int main() {
    std::vector<A> vec;
    vec.reserve(5);

    vec.emplace_back(1);
    vec.emplace_back(2);
}

it prints

LLMs are confident it would be the other way around.

Why

The LLMs are probably confused about the order in which members of a class are destructed, which is LIFO order. When probed a little further they seem to cough up to their mistake, saying it's a contentious part of the C++ Standard and it's implementation dependent. This StackOverflow answer from 14 years ago is a bit more precise.

Observer Effect

Putting this post out on the internet might have the effect of correcting this mistake in future iterations. My guess it will take less than 6 months to correct.

Gemini 3 Pro

ChatGPT 5.2 Thinking

Claude 4.5 Opus