2015-08-23 18 views
10

Il codice compilato con GCC 4.9.2 senza nemmeno alcun preavviso, ma mostra il seguente errore nel GCC 5.2.0:errore: utilizzo dei cancellato regex_match funzione bool con gcc 5.2.0

error: use of deleted function ‘bool std::regex_match(const std::__cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&, std::__cxx11::match_results<typename std::__cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, std::regex_constants::match_flag_type) [with _Ch_traits = std::char_traits<char>; _Ch_alloc = std::allocator<char>; _Alloc = std::allocator<std::__cxx11::sub_match<__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> > > >; _Ch_type = char; _Rx_traits = std::__cxx11::regex_traits<char>; typename std::__cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>::const_iterator = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >]’ 
    if(std::regex_match(toString(index),result,re)){index=fabs(index);} 

pezzo di codice che sta gettando l'errore:

bool negative_flag=false; 
std::regex re("-[^-]*"); 
std::smatch result; 
if(std::regex_match(toString(index),result,re)){index=fabs(index);} 

l'errore è nella linea if. Cosa potrebbe causare questo?

risposta

14

In qualsiasi modo l'ho risolto. Ho trovato queste righe in regex.h:

// _GLIBCXX_RESOLVE_LIB_DEFECTS 
    // 2329. regex_match() with match_results should forbid temporary strings 
    /// Prevent unsafe attempts to get match_results from a temporary string. 

cioè si dice regex_match non consente più stringhe temporanee (che viene restituito dalla toString() funzione in questo caso) con match_results. Quindi, qualcosa di simile ha risolto il problema:

std::string tmps=toString(index); 
if(std::regex_match(tmps,result,re)){index=fabs(index);} 
+2

Il rapporto difetto rilevante è a http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2329. –

Problemi correlati