Title
std::throw_with_nested("string_literal")
Status
c++17
Section
[except.nested]
Submitter
Jonathan Wakely

Created on 2017-01-17.00:00:00 last changed 89 months ago

Messages

Date: 2017-01-30.15:36:02

Proposed resolution:

This wording is relative to N4618.

  1. Edit [except.nested] as indicated:

    template <class T> [[noreturn]] void throw_with_nested(T&& t);
    

    -6- Let U be remove_referencedecay_t<T>.

    -7- Requires: U shall be CopyConstructible.

Date: 2017-01-27.00:00:00

[ 2017-01-27 Telecon ]

Priority 0

Date: 2017-01-17.00:00:00

[except.nested] says:

template <class T> [[noreturn]] void throw_with_nested(T&& t);

Let U be remove_reference_t<T>.

Requires: U shall be CopyConstructible.

This forbids std::throw_with_nested("string literal") because T gets deduced as const char(&)[15] and so U is const char[15] which is not CopyConstructible.

A throw expression decays an array argument to a pointer ([expr.throw] p2) and so works fine with string literals. GCC's throw_with_nested also worked fine until I added a static_assert to enforce the CopyConstructible requirement.

The same problem exists when throwing a function type, which should also decay:

#include <exception>

void f() { }

int main() {
  std::throw_with_nested(f);
}

(Note: LWG 1370 added the remove_reference, which was a step in the right direction but not far enough.)

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2017-03-05 23:41:16adminsetstatus: ready -> wp
2017-01-30 15:36:02adminsetmessages: + msg8831
2017-01-30 15:36:02adminsetstatus: new -> ready
2017-01-25 20:14:53adminsetmessages: + msg8789
2017-01-17 00:00:00admincreate