<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2191</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="2191"></A><H4>2191.
  
Incorrect result for <TT>noexcept(typeid(v))</TT>
</H4>
<B>Section: </B>14.5&#160; [<A href="https://wg21.link/except.spec">except.spec</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++17
 &#160;&#160;&#160;

 <B>Submitter: </B>Mike Miller
 &#160;&#160;&#160;

 <B>Date: </B>2015-10-26<BR>


<P>[Adopted at the November, 2016 meeting as part of paper P0003R5.]</P>

<P>Consider the following example:</P>

<PRE>
    struct B { virtual void f() { } };
    struct D : B { } d;
    bool b = noexcept(typeid(d));
</PRE>

<P>According to 7.6.2.7 [<A href="https://wg21.link/expr.unary.noexcept#3">expr.unary.noexcept</A>] paragraph 3, the value of
<TT>b</TT> should be <TT>false</TT>, because 14.5 [<A href="https://wg21.link/except.spec">except.spec</A>]
bullet 14.6 says,</P>

<UL>
<LI>

<P>If <TT>e</TT> is a <TT>typeid</TT> expression applied to a glvalue
expression whose type is a polymorphic class type
(7.6.1.8 [<A href="https://wg21.link/expr.typeid">expr.typeid</A>]), <I>S</I> consists of the type
<TT>std::bad_typeid</TT>.</P>
</LI>

</UL>

<P>and <TT>d</TT> is such an expression. This is clearly bogus, as the
expression cannot possibly throw; according to 7.6.1.8 [<A href="https://wg21.link/expr.typeid#2">expr.typeid</A>] paragraph 2,
 the condition under which the exception might be thrown
is:</P>

<BLOCKQUOTE>

If the glvalue expression is obtained by applying the unary <TT>*</TT>
operator to a pointer<SUP>69</SUP> and the pointer is a null pointer value
(7.3.12 [<A href="https://wg21.link/conv.ptr">conv.ptr</A>]), the <TT>typeid</TT> expression throws an exception
(14.2 [<A href="https://wg21.link/except.throw">except.throw</A>]) of a type that would match a handler of type
<TT>std::bad_typeid</TT> exception (17.7.5 [<A href="https://wg21.link/bad.typeid">bad.typeid</A>]).

</BLOCKQUOTE>

<P>
<B>Proposed resolution (November, 2016):</B>
</P>

<P>Change 14.5 [<A href="https://wg21.link/except.spec#13.6">except.spec</A>] bullet 13.6 as follows:</P>

<BLOCKQUOTE>

<P>The <I>set of potential exceptions of an expression</I>
<TT>e</TT> is empty if <TT>e</TT> is a core constant expression
(7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]). Otherwise, it is the union of the sets of
potential exceptions of the immediate subexpressions of <TT>e</TT>,
including default argument expressions used in a function call, combined
with a set <I>S</I> defined by the form of <TT>e</TT>, as follows:</P>

<UL>
<LI><P>...</P></LI>

<LI><P>If <TT>e</TT> is a <TT>typeid</TT> expression applied to
a <DEL>glvalue expression whose type is</DEL> <INS>(possibly parenthesized)
built-in unary <TT>*</TT> operator applied to a pointer to</INS> a
polymorphic class type (7.6.1.8 [<A href="https://wg21.link/expr.typeid">expr.typeid</A>]), <I>S</I> consists of
the type <TT>std::bad_typeid</TT>. [<I>Example:</I> ...</P></LI>

</UL>

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
