<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2462: std::ios_base::failure is overspecified</title>
<meta property="og:title" content="Issue 2462: std::ios_base::failure is overspecified">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2462.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#C++17">C++17</a> status.</em></p>
<h3 id="2462"><a href="lwg-defects.html#2462">2462</a>. <code>std::ios_base::failure</code> is overspecified</h3>
<p><b>Section:</b> 31.5.2 <a href="https://wg21.link/ios.base">[ios.base]</a>, 31.5.2.2.1 <a href="https://wg21.link/ios.failure">[ios.failure]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2014-12-15 <b>Last modified:</b> 2023-02-07</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#ios.base">issues</a> in [ios.base].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
31.5.2 <a href="https://wg21.link/ios.base">[ios.base]</a> defines <code>ios_base::failure</code> as a nested class:
</p>
<blockquote>
<pre>
namespace std {
  class ios_base {
  public:
    class failure;
    [&hellip;]
  };
  [&hellip;]
}
</pre>
</blockquote>
<p>
This means it is valid to use an elaborated-type-specifier to
refer to <code>ios_base::failure</code>:
</p>
<blockquote>
<pre>
using F = class std::ios_base::failure;
throw F();
</pre>
</blockquote>
<p>
Therefore implementations are not permitted to define
<code>ios_base::failure</code> as a typedef e.g.
</p>
<blockquote>
<pre>
 class ios_base {
 public:
#if __cplusplus &lt; 201103L
   class failure_cxx03 : public exception {...};
   typedef failure_cxx03 failure;
#else
   class failure_cxx11 : public system_error {...};
   typedef failure_cxx11 failure;
#endif
   [&hellip;]
 };
</pre>
</blockquote>
<p>
This constrains implementations, making it harder to manage the ABI
change to <code>ios_base::failure</code> between C++03 and C++11.
</p>

<p><i>[2015-05-06 Lenexa: Move to Ready]</i></p>

<p>JW: the issue is that users are currently allowed to write "class failure" with an elaborated-type-specifier and it must be well-formed, I want the freedom to make that type a typedef, so they can't necessarily use an elaborated-type-specifier (which there is no good reason to use anyway)</p>
<p>JW: ideally I'd like this everywhere for all nested classes, but that's a paper not an issue, I only need this type fixed right now.</p>
<p>RD: is a synonym the same as an alias?</p>
<p>JW: dcl.typedef says a typedef introduces a synonym for another type, so I think this is the right way to say this</p>
<p>JW: I already shipped this last month</p>
<p>PJP: we're going to have to break ABIs again some time, we need all the wiggle room we can get to make that easier. This helps.</p>
<p>MC: do we want this at all? Ready?</p>
<p>9 in favor, none opose or abstaining</p>


<p id="res-2462"><b>Proposed resolution:</b></p>
<p>This wording is relative to N4296.</p>

<ol>
<li><p>Change the synopsis in 31.5.2 <a href="https://wg21.link/ios.base">[ios.base]</a> as indicated:</p>

<blockquote>
<pre>
namespace std {
  class ios_base {
  public:
    class failure; <ins><i>// see below</i></ins>
    [&hellip;]
  };
  [&hellip;]
};
</pre>
</blockquote>
</li>

<li><p>Change 31.5.2 <a href="https://wg21.link/ios.base">[ios.base]</a> paragraph 1:</p>

<blockquote>
<p>
<code>ios_base</code> defines several member types:
</p>
<ul>
<li><p>a <del>class <code>failure</code></del><ins>type <code>failure</code>, defined as either
a class derived from <code>system_error</code> or a synonym for a class</ins> derived from 
<code>system_error</code>;</p></li>
</ul>
</blockquote>
</li>

<li><p>Change  [ios::failure] paragraph 1:</p>
<blockquote>
<p>
-1- <ins>An implementation is permitted to define <code>ios_base::failure</code> as
a synonym for a class with equivalent functionality to class <code>ios_base::failure</code> shown 
in this subclause. [<i>Note</i>: When <code>ios_base::failure</code> is a synonym for another type 
it shall provide a nested type <code>failure</code>, to emulate the injected class name. &mdash; 
<i>end note</i>]</ins> The class <code>failure</code> defines the base class for the types of all 
objects thrown as exceptions, by functions in the iostreams library, to report errors detected 
during stream buffer operations.
</p>
</blockquote>
</li>
</ol>





</body>
</html>
