[Bug c++/71052] New: Use of Range Based For Loop in unsupported dialect results in malformed code
dengel at synopsys dot com
gcc-bugzilla@gcc.gnu.org
Tue May 10 21:16:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71052
Bug ID: 71052
Summary: Use of Range Based For Loop in unsupported dialect
results in malformed code
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dengel at synopsys dot com
Target Milestone: ---
Using GCC 5.1 if range based for loop is present and we are not compiling in
c++11 or gnu++11 mode some weird behavior is observed.
Upon compilation, we are met with a warning, however, we compile successfully
and the resulting code is broken. The below code snippet compiles and runs as
expected in c++11 mode, but in c++98 mode we see a warning, and the resulting
binary loops infinitely.
Reproducer:
$ cat t.cpp
int arr[10] = { 0 };
void foo() {
for (int i: arr) {
}
}
$ g++ -c -std=c++98 -O0 t.cpp
t.cpp: In function ‘void foo()’:
t.cpp:3:17: warning: range-based ‘for’ loops only available with -std=c++11 or
-std=gnu++11
for (int i: arr) {
^
$ objdump -d t.o
t.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z3foov>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: eb fe jmp 4 <_Z3foov+0x4>
More information about the Gcc-bugs
mailing list