https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88543
Bug ID: 88543
Summary: ICE template function specialization with auto
returning tipe
Product: gcc
Version: 7.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: archivio.rp at gmail dot com
Target Milestone: ---
I was simply testing the templates specialization for a function in order to
convert a string into a number. The following code should produce an error,
while the compiler crashes with a segmentation error:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
template<typename Type>
Type to_number(const string& str) {
Type v;
stringstream buff(str);
buff >> v;
return v;
}
// Specializations
template<> int to_number(const string& str) { return stoi(str); }
template<> auto to_number(const string& str) { return stof(str); }
...
as shown here:
-------------------------------
toNumber.cc: In function ‘Type to_number(const string&) [with Type = auto]’:
toNumber.cc:18:66: internal compiler error: Segmentation fault
template<> auto to_number(const string& str) { return stof(str); }
^
Please submit a full bug report,
with preprocessed source if appropriate.
-----------------------------------------------
I have compiled the code with different versions:
gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)
gcc version 7.4.0 (Debian 7.4.0-1)
gcc version 7.3.0 (Windows - 10 + Cynwin)
gcc version 8.2.0 (Debian 8.2.0-12)
and only the last one works correctly.