[Bug c++/67795] New: Wrong code generated for conditional expression with cast
frankhb1989 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Oct 1 10:52:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67795
Bug ID: 67795
Summary: Wrong code generated for conditional expression with
cast
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: frankhb1989 at gmail dot com
Target Milestone: ---
Case:
// g++ -std=c++1y
#include <iostream>
#include <string>
#include <experimental/string_view>
using namespace std;
using namespace experimental;
string_view&
erase_left(size_t n, string_view& s)
{
return static_cast<string_view&>(n != 0 ? (s.remove_prefix(n), s) : s);
// return n != 0 ? (s.remove_prefix(n), s) : s;
}
int main()
{
string_view sv("abcde");
cout << erase_left(3, sv).to_string() << endl; // expected "de"
}
The output is garbage, using i686-w64-mingw32-g++ from MSYS2. However,
x86_64-w64-mingw32-clang++ is OK. So I suspect it is a frontend bug.
More information about the Gcc-bugs
mailing list