The following codes will crash when they are compiled by clang UBSAN

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>

template<class T>
inline std::string floatToString(T i){
    printf("in floatToStringn");
    std::stringstream ss;
    ss << std::noshowpoint << i;
    printf("exit floatToStringn");
    return ss.str();

int main() {
 std::cout << floatToString(1.0) << "n";
 return 0;

Compile with Clang 3.6:

$> clang++-3.6 -fsanitize=undefined -fno-sanitize=float-divide-by-zero,vptr,function -fno-sanitize-recover -o test test.cpp

Then the program crashed:

$> ./test
in floatToString
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/ios_base.h:96:24: runtime error: load of value 4294966271, which is not a valid value for type ‘std::_Ios_Fmtflags’

Can someone help why this problem happens when I turn on clang UBSAN?