https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80827
Bug ID: 80827
Summary: False strict-aliasing warning with certain settings
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: s-beyer at gmx dot net
Target Milestone: ---
Hi,
$ cat foo.cc
#include <sstream>
template<typename Ignored>
void foo() {
std::istringstream ss("a\nb\nc");
std::string attr;
while (std::getline(ss, attr));
}
$ g++-7 -Wall -O2 -c foo.cc # warning with -O2
foo.cc: In function ‘void foo()’:
foo.cc:7:30: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
while (std::getline(ss, attr));
^
$ g++-7 -Wall -O1 -c foo.cc # works with -O1
$ g++-7 --version
g++-7 (Debian 7.1.0-5) 7.1.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Interestingly, when using a function instead of a function template,
it works:
$ cat foo.cc
#include <sstream>
void foo() {
std::istringstream ss("a\nb\nc");
std::string attr;
while (std::getline(ss, attr));
}
$ g++-7 -Wall -O2 -c foo.cc
Btw it works with 6.3.0
Best
Stephan