From 2347da644d23390399cc060fe3f2358314efc1b6 Mon Sep 17 00:00:00 2001
From: Paolo Carlini <pcarlini@suse.de>
Date: Sat, 31 Jul 2004 09:00:09 +0000
Subject: [PATCH] locale_facets.tcc (num_get<>::_M_extract_float, [...]): In
 the main parsing loop delay the life of __q to the actual use point.

2004-07-30  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (num_get<>::_M_extract_float,
	num_get<>::_M_extract_int): In the main parsing loop delay the
	life of __q to the actual use point.

From-SVN: r85380
---
 libstdc++-v3/ChangeLog                      |   6 +
 libstdc++-v3/include/bits/locale_facets.tcc | 137 +++++++++++---------
 2 files changed, 79 insertions(+), 64 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 4a2381afe696..f56c60f50931 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,9 @@
+2004-07-30  Paolo Carlini  <pcarlini@suse.de>
+
+	* include/bits/locale_facets.tcc (num_get<>::_M_extract_float,
+	num_get<>::_M_extract_int): In the main parsing loop delay the
+	life of __q to the actual use point.
+
 2004-07-29  Paolo Carlini  <pcarlini@suse.de>
 
 	PR libstdc++/14220
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 94a2cb8d81d0..ee5ea7d1def6 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -330,7 +330,6 @@ namespace std
 	  // According to 22.2.2.1.2, p8-9, first look for thousands_sep
 	  // and decimal_point.
 	  const char_type __c = *__beg;
-	  const char_type* __q = __traits_type::find(__lit_zero, 10, __c);
           if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
 	    {
 	      if (!__found_dec && !__found_sci)
@@ -368,40 +367,44 @@ namespace std
 	      else
 		break;
 	    }
-          else if (__q != 0)
+          else
 	    {
-	      __xtrc += __num_base::_S_atoms_in[__q - __lit];
-	      __found_mantissa = true;
-	      ++__sep_pos;
-	      ++__beg;
-	    }
-	  else if ((__c == __lit[__num_base::_S_ie] 
-		    || __c == __lit[__num_base::_S_iE])
-		   && __found_mantissa && !__found_sci)
-	    {
-	      // Scientific notation.
-	      if (__found_grouping.size() && !__found_dec)
-		__found_grouping += static_cast<char>(__sep_pos);
-	      __xtrc += 'e';
-	      __found_sci = true;
-
-	      // Remove optional plus or minus sign, if they exist.
-	      if (++__beg != __end)
+	      const char_type* __q = __traits_type::find(__lit_zero, 10, __c);
+	      if (__q)
 		{
-		  const bool __plus = *__beg == __lit[__num_base::_S_iplus];
-		  if ((__plus || *__beg == __lit[__num_base::_S_iminus])
-		      && !(__lc->_M_use_grouping
-			   && *__beg == __lc->_M_thousands_sep)
-		      && !(*__beg == __lc->_M_decimal_point))
+		  __xtrc += __num_base::_S_atoms_in[__q - __lit];
+		  __found_mantissa = true;
+		  ++__sep_pos;
+		  ++__beg;
+		}
+	      else if ((__c == __lit[__num_base::_S_ie] 
+			|| __c == __lit[__num_base::_S_iE])
+		       && __found_mantissa && !__found_sci)
+		{
+		  // Scientific notation.
+		  if (__found_grouping.size() && !__found_dec)
+		    __found_grouping += static_cast<char>(__sep_pos);
+		  __xtrc += 'e';
+		  __found_sci = true;
+
+		  // Remove optional plus or minus sign, if they exist.
+		  if (++__beg != __end)
 		    {
-		      __xtrc += __plus ? '+' : '-';
-		      ++__beg;
+		      const bool __plus = *__beg == __lit[__num_base::_S_iplus];
+		      if ((__plus || *__beg == __lit[__num_base::_S_iminus])
+			  && !(__lc->_M_use_grouping
+			       && *__beg == __lc->_M_thousands_sep)
+			  && !(*__beg == __lc->_M_decimal_point))
+			{
+			  __xtrc += __plus ? '+' : '-';
+			  ++__beg;
+			}
 		    }
 		}
+	      else
+		// Not a valid input item.
+		break;
 	    }
-	  else
-	    // Not a valid input item.
-	    break;
         }
 
       // Digit grouping is checked. If grouping and found_grouping don't
@@ -516,8 +519,6 @@ namespace std
 		// According to 22.2.2.1.2, p8-9, first look for thousands_sep
 		// and decimal_point.
 		const char_type __c = *__beg;
-		const char_type* __q = __traits_type::find(__lit_zero, 
-							   __len, __c);
 		if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
 		  {
 		    // NB: Thousands separator at the beginning of a string
@@ -535,26 +536,31 @@ namespace std
 		  }
 		else if (__c == __lc->_M_decimal_point)
 		  break;
-		else if (__q != 0)
+		else
 		  {
-		    int __digit = __q - __lit_zero;
-		    if (__digit > 15)
-		      __digit -= 6;
-		    if (__result < __min)
-		      __overflow = true;
-		    else
+		    const char_type* __q = __traits_type::find(__lit_zero, 
+							       __len, __c);
+		    if (__q)
 		      {
-			const _ValueT __new_result = __result * __base
-			                             - __digit;
-			__overflow |= __new_result > __result;
-			__result = __new_result;
-			++__sep_pos;
-			__found_num = true;
+			int __digit = __q - __lit_zero;
+			if (__digit > 15)
+			  __digit -= 6;
+			if (__result < __min)
+			  __overflow = true;
+			else
+			  {
+			    const _ValueT __new_result = (__result * __base
+							  - __digit);
+			    __overflow |= __new_result > __result;
+			    __result = __new_result;
+			    ++__sep_pos;
+			    __found_num = true;
+			  }
 		      }
+		    else
+		      // Not a valid input item.
+		      break;
 		  }
-		else
-		  // Not a valid input item.
-		  break;
 	      }
 	  }
 	else
@@ -563,8 +569,6 @@ namespace std
 	    for (; __beg != __end; ++__beg)
 	      {
 		const char_type __c = *__beg;
-		const char_type* __q = __traits_type::find(__lit_zero, 
-							   __len, __c);
 		if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
 		  {
 		    if (__sep_pos)
@@ -580,25 +584,30 @@ namespace std
 		  }
 		else if (__c == __lc->_M_decimal_point)
 		  break;
-		else if (__q != 0)
+		else
 		  {
-		    int __digit = __q - __lit_zero;
-		    if (__digit > 15)
-		      __digit -= 6;
-		    if (__result > __max)
-		      __overflow = true;
-		    else
+		    const char_type* __q = __traits_type::find(__lit_zero,
+							       __len, __c);    
+		    if (__q)
 		      {
-			const _ValueT __new_result = __result * __base
-			                             + __digit;
-			__overflow |= __new_result < __result;
-			__result = __new_result;
-			++__sep_pos;
-			__found_num = true;
+			int __digit = __q - __lit_zero;
+			if (__digit > 15)
+			  __digit -= 6;
+			if (__result > __max)
+			  __overflow = true;
+			else
+			  {
+			    const _ValueT __new_result = (__result * __base
+							  + __digit);
+			    __overflow |= __new_result < __result;
+			    __result = __new_result;
+			    ++__sep_pos;
+			    __found_num = true;
+			  }
 		      }
+		    else
+		      break;
 		  }
-		else
-		  break;
 	      }
 	  }
 
-- 
GitLab