This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/69852] New: std::vector out of bounds access does not crash
- From: "adtieni at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 17 Feb 2016 12:56:20 +0000
- Subject: [Bug c++/69852] New: std::vector out of bounds access does not crash
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69852
Bug ID: 69852
Summary: std::vector out of bounds access does not crash
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: adtieni at gmail dot com
Target Milestone: ---
#include <iostream>
#include <string>
#include <vector>
int main() {
std::vector<std::string> words(6);
std::vector<std::string> words2;
std::cout << "Before assignment: size " << words.size() << " capacity " <<
words.capacity() << std::endl;
words = words2;
std::cout << "After assignment: size " << words.size() << " capacity " <<
words.capacity() << std::endl;
words[1] = "I should crash here";
std::cout << "I did not crash. Words contains:" << std::endl;
for (auto& el : words) {
std::cout << el << ' ';
}
}
Ran both
$ clang++ -v -std=c++14 -Wall -Wextra -pedantic -pthread test_vector.cpp
clang version 3.7.1 (tags/RELEASE_371/final)
$ g++ -v -std=c++14 -Wall -Wextra -pedantic -pthread test_vector.cpp
GNU C++14 (GCC) version 5.3.0 (x86_64-unknown-linux-gnu)
Outputs:
Before assignment: size 6 capacity 6
After assignment: size 0 capacity 6
I did not crash. Words contains: