<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3606: Missing regex_traits::locale_type requirements</title>
<meta property="og:title" content="Issue 3606: Missing regex_traits::locale_type requirements">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3606.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p>
<h3 id="3606"><a href="lwg-active.html#3606">3606</a>. Missing <code>regex_traits::locale_type</code> requirements</h3>
<p><b>Section:</b> 28.6.2 <a href="https://wg21.link/re.req">[re.req]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2021-09-28 <b>Last modified:</b> 2021-10-14</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#re.req">active issues</a> in [re.req].</p>
<p><b>View all other</b> <a href="lwg-index.html#re.req">issues</a> in [re.req].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Why is <code>locale_type</code> part of the regular expression traits requirements in 28.6.2 <a href="https://wg21.link/re.req">[re.req]</a>? 
When would <code>locale_type</code> not be <code>std::locale</code>? What are the requirements on the type? 
Does it have to provide exactly the same interface as <code>std::locale</code>, or just some unspecified 
interface that a custom regex traits type needs from it? Why is none of this specified?
<p/>
Currently the only requirement on <code>locale_type</code> in the standard is that it's copy constructible. 
Clearly it needs to be default constructible as well, otherwise you can't construct a <code>basic_regex</code>, 
since none of them allows passing in a locale, so they have to default construct it (see also LWG <a href="lwg-active.html#2431" title="Missing regular expression traits requirements (Status: New)">2431</a><sup><a href="https://cplusplus.github.io/LWG/issue2431" title="Latest snapshot">(i)</a></sup>).
<p/>
The other requirements on <code>locale_type</code> are a mystery. Why do we allow custom locale types, 
but not say anything about what they should do? Can we just require <code>locale_type</code> to be <code>std::locale</code>? 
Is anybody really going to use <code>boost::locale</code> with <code>std::basic_regex</code>, when they 
could just use <code>boost::basic_regex</code> instead?
<p/>
Why does the regular expression traits requirements table say that <code>imbue</code> and <code>getloc</code> 
talk about the locale used, "if any". How would there not be one already?
<p/>
Why is imbuing a locale into a <code>basic_regex</code> a separate operation from compiling the regular expression 
pattern? Is the following supposed to change the compiled regex?
</p>
<blockquote><pre>
std::regex r("[a-z]");
r.imbue(std::locale("en_GB.UTF-8"));
</pre></blockquote>
<p>
Hasn't the regex constructor already made use of the locale to compile the <code>"[a-z]"</code> pattern, 
and so changing the locale is too late? So do we need to do the following to compile the regex with 
a specific locale?
</p>
<blockquote><pre>
std::regex r;
r.imbue(std::locale("en_GB.UTF-8"));
r.assign("[a-z]");
</pre></blockquote>
<p>
Why require two-stage initialization like this, is it just so that we appear consistent with the 
<code>imbue</code>/<code>getloc</code> API of <code>std::ios_base</code>? It works for <code>ios_base</code>, 
because the new locale is effective after imbuing it, but for <code>basic_regex</code> the pattern 
has already been compiled using the old locale and imbuing a new one can't change that. Is the 
<code>basic_regex</code> supposed to store the pattern and recompile it after <code>imbue</code>, or is 
this just an inappropriate API for <code>basic_regex</code>?
</p>

<p><i>[2021-10-14; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>



<p id="res-3606"><b>Proposed resolution:</b></p>





</body>
</html>
