C++N4606(239)18.8 Exception handling [support.exception] p509


はじめに(Introduction)

C++N4606 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/#mailing2016-11
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf

C++N4606は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。

作業方針(sequence)

1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。

1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。

C++N4606符号断片編纂一覧(example code compile list)

C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

編纂器(Compiler)

clang++ --version

clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0

g++-7 --version

g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.

(239)18.8 Exception handling [support.exception] p509

算譜(source code)

p509.cpp
// C++N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
#define msg "C++N4606(239)18.8 Exception handling [support.exception] p509.cpp"
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.

#include <iostream>
#include <cstdlib>

//18.8.1 Header <exception> synopsis [exception.syn]
namespace std {
class exception;
class bad_exception;
class nested_exception;
using unexpected_handler = void (*)();
unexpected_handler get_unexpected() noexcept;
unexpected_handler set_unexpected(unexpected_handler f) noexcept;
[[noreturn]] void unexpected();
using terminate_handler = void (*)();
terminate_handler get_terminate() noexcept;
terminate_handler set_terminate(terminate_handler f) noexcept;
[[noreturn]] void terminate() noexcept;
int uncaught_exceptions() noexcept;
// D.7, uncaught_exception (deprecated)
bool uncaught_exception() noexcept;
using exception_ptr = unspecified ;
exception_ptr current_exception() noexcept;
[[noreturn]] void rethrow_exception(exception_ptr p);
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
template <class T> [[noreturn]] void throw_with_nested(T&& t);
template <class E> void rethrow_if_nested(const E& e);
}

//18.8.2 Class exception [exception]
namespace std {
class exception {
public:
  exception() noexcept;
  exception(const exception&) noexcept;
  exception& operator=(const exception&) noexcept;
  virtual ~exception();
  virtual const char* what() const noexcept;
};
}

//18.8.3 Class bad_exception [bad.exception]
namespace std {
class bad_exception : public exception {
public:
  bad_exception() noexcept;
  bad_exception(const bad_exception&) noexcept;
  bad_exception& operator=(const bad_exception&) noexcept;
  const char* what() const noexcept override;
};
}

//18.8.4 Abnormal termination [exception.terminate]
//18.8.4.1 Type terminate_handler [terminate.handler]
using terminate_handler = void (*)();

//18.8.4.2 set_terminate [set.terminate]
terminate_handler set_terminate(terminate_handler f) noexcept;

//18.8.4.3 get_terminate [get.terminate]
terminate_handler get_terminate() noexcept;

//18.8.4.4 terminate [terminate]
[[noreturn]] void terminate() noexcept;

//18.8.5 uncaught_exceptions [uncaught.exceptions]
int uncaught_exceptions() noexcept;

//18.8.6 Exception propagation [propagation]
using exception_ptr = unspecified ;
exception_ptr current_exception() noexcept;
[[noreturn]] void rethrow_exception(exception_ptr p);

try {
  throw e;
} catch(...) {
  return current_exception();
}

//18.8.7 nested_exception [except.nested]
namespace std {
class nested_exception {
public:
  nested_exception() noexcept;
  nested_exception(const nested_exception&) noexcept = default;
  nested_exception& operator=(const nested_exception&) noexcept = default;
  virtual ~nested_exception() = default;
// access functions
  [[noreturn]] void rethrow_nested() const;
  exception_ptr nested_ptr() const noexcept;
};
template<class T> [[noreturn]] void throw_with_nested(T&& t);
template <class E> void rethrow_if_nested(const E& e);
}

nested_exception() noexcept;
[[noreturn]] void rethrow_nested() const;
exception_ptr nested_ptr() const noexcept;
template <class T> [[noreturn]] void throw_with_nested(T&& t);
template <class E> void rethrow_if_nested(const E& e);
dynamic_cast<const nested_exception&>(e).rethrow_nested();

//18.9 Initializer lists [support.initlist]
//18.9.1 Header <initializer_list> synopsis [initializer_list.syn]
namespace std {
template<class E> class initializer_list {
public:
  using value_type = E;
  using reference = const E&;
  using const_reference = const E&;
  using size_type = size_t;
  using iterator = const E*;
  using const_iterator = const E*;
  constexpr initializer_list() noexcept;
  constexpr size_t size() const noexcept; // number of elements
  constexpr const E* begin() const noexcept; // first element
  constexpr const E* end() const noexcept; // one past the last element
};
// 18.9.4 initializer list range access
template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
}

//18.9.2 Initializer list constructors [support.initlist.cons]
constexpr initializer_list() noexcept;

//18.9.3 Initializer list access [support.initlist.access]
constexpr const E* begin() const noexcept;
constexpr const E* end() const noexcept;
constexpr size_t size() const noexcept;

//18.9.4 Initializer list range access [support.initlist.range]
template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
template<class E> constexpr const E* end(initializer_list<E> il) noexcept;

//18.10.3 Header <cstdbool> synopsis [cstdbool.syn]
#define __bool_true_false_are_defined 1

//18.10.4 Header <cstdalign> synopsis [cstdalign.syn]
#define __alignas_is_defined 1

int main() {
  std::cout<< msg << std::endl;
  return EXIT_SUCCESS;
}

編纂・実行結果(compile and go)

cppall.sh
$ ./cppall.sh p509
$ clang++ p509.cpp -std=c++03 -Wall
p509.cpp:16:28: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using unexpected_handler = void (*)();
                           ^
p509.cpp:17:37: error: expected function body after function declarator
unexpected_handler get_unexpected() noexcept;
                                    ^
p509.cpp:18:57: error: expected function body after function declarator
unexpected_handler set_unexpected(unexpected_handler f) noexcept;
                                                        ^
p509.cpp:19:2: error: expected expression
[[noreturn]] void unexpected();
 ^
p509.cpp:19:14: error: expected unqualified-id
[[noreturn]] void unexpected();
             ^
p509.cpp:20:27: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using terminate_handler = void (*)();
                          ^
p509.cpp:21:35: error: expected function body after function declarator
terminate_handler get_terminate() noexcept;
                                  ^
p509.cpp:22:54: error: expected function body after function declarator
terminate_handler set_terminate(terminate_handler f) noexcept;
                                                     ^
p509.cpp:23:2: error: expected expression
[[noreturn]] void terminate() noexcept;
 ^
p509.cpp:23:14: error: expected unqualified-id
[[noreturn]] void terminate() noexcept;
             ^
p509.cpp:24:27: error: expected function body after function declarator
int uncaught_exceptions() noexcept;
                          ^
p509.cpp:26:27: error: expected function body after function declarator
bool uncaught_exception() noexcept;
                          ^
p509.cpp:27:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using exception_ptr = unspecified ;
                      ^
p509.cpp:27:7: error: typedef redefinition with different types ('unspecified' (aka 'int') vs 'std::exception_ptr')
using exception_ptr = unspecified ;
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:139:24: note: previous definition is here
class _LIBCPP_TYPE_VIS exception_ptr
                       ^
p509.cpp:28:35: error: expected function body after function declarator
exception_ptr current_exception() noexcept;
                                  ^
p509.cpp:29:2: error: expected expression
[[noreturn]] void rethrow_exception(exception_ptr p);
 ^
p509.cpp:29:14: error: expected unqualified-id
[[noreturn]] void rethrow_exception(exception_ptr p);
             ^
p509.cpp:30:33: error: 'make_exception_ptr' is missing exception specification 'throw()'
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
                                ^
                                                        throw()
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:167:1: note: previous declaration is here
make_exception_ptr(_Ep __e) _NOEXCEPT
^
p509.cpp:30:56: error: expected ';' at end of declaration
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
                                                       ^
                                                       ;
p509.cpp:30:57: error: C++ requires a type specifier for all declarations
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
                                                        ^
p509.cpp:31:21: error: expected expression
template <class T> [[noreturn]] void throw_with_nested(T&& t);
                    ^
p509.cpp:31:33: error: expected unqualified-id
template <class T> [[noreturn]] void throw_with_nested(T&& t);
                                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
3 warnings and 20 errors generated.
$ clang++ p509.cpp -std=c++11 -Wall
p509.cpp:27:7: error: typedef redefinition with different types ('unspecified' (aka 'int') vs 'std::exception_ptr')
using exception_ptr = unspecified ;
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:139:24: note: previous definition is here
class _LIBCPP_TYPE_VIS exception_ptr
                       ^
p509.cpp:37:7: error: redefinition of 'exception'
class exception {
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:97:29: note: previous definition is here
class _LIBCPP_EXCEPTION_ABI exception
                            ^
p509.cpp:49:7: error: redefinition of 'bad_exception'
class bad_exception : public exception {
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:105:29: note: previous definition is here
class _LIBCPP_EXCEPTION_ABI bad_exception
                            ^
p509.cpp:79:1: error: expected unqualified-id
try {
^
p509.cpp:81:3: error: expected unqualified-id
} catch(...) {
  ^
p509.cpp:87:7: error: redefinition of 'nested_exception'
class nested_exception {
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:234:29: note: previous definition is here
class _LIBCPP_EXCEPTION_ABI nested_exception
                            ^
p509.cpp:101:1: error: C++ requires a type specifier for all declarations
nested_exception() noexcept;
^
p509.cpp:102:36: error: non-member function cannot have 'const' qualifier
[[noreturn]] void rethrow_nested() const;
                                   ^~~~~
p509.cpp:103:28: error: non-member function cannot have 'const' qualifier
exception_ptr nested_ptr() const noexcept;
                           ^~~~~~
p509.cpp:106:1: error: expected unqualified-id
dynamic_cast<const nested_exception&>(e).rethrow_nested();
^
p509.cpp:111:25: error: redefinition of 'initializer_list'
template<class E> class initializer_list {
                        ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/initializer_list:59:28: note: previous definition is here
class _LIBCPP_TEMPLATE_VIS initializer_list
                           ^
p509.cpp:125:38: error: constexpr declaration of 'begin' follows non-constexpr declaration
template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/initializer_list:100:1: note: previous declaration is here
begin(initializer_list<_Ep> __il) _NOEXCEPT
^
p509.cpp:126:38: error: constexpr declaration of 'end' follows non-constexpr declaration
template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/initializer_list:109:1: note: previous declaration is here
end(initializer_list<_Ep> __il) _NOEXCEPT
^
p509.cpp:130:11: error: C++ requires a type specifier for all declarations
constexpr initializer_list() noexcept;
~~~~~~~~~ ^
p509.cpp:133:17: error: unknown type name 'E'
constexpr const E* begin() const noexcept;
                ^
p509.cpp:133:28: error: non-member function cannot have 'const' qualifier
constexpr const E* begin() const noexcept;
                           ^~~~~~
p509.cpp:134:17: error: unknown type name 'E'
constexpr const E* end() const noexcept;
                ^
p509.cpp:134:26: error: non-member function cannot have 'const' qualifier
constexpr const E* end() const noexcept;
                         ^~~~~~
p509.cpp:135:25: error: non-member function cannot have 'const' qualifier
constexpr size_t size() const noexcept;
                        ^~~~~~
p509.cpp:138:38: warning: variable templates are a C++14 extension [-Wc++14-extensions]
template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.
$ clang++ p509.cpp -std=c++17 -Wall
p509.cpp:27:7: error: typedef redefinition with different types ('unspecified' (aka 'int') vs 'std::exception_ptr')
using exception_ptr = unspecified ;
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:139:24: note: previous definition is here
class _LIBCPP_TYPE_VIS exception_ptr
                       ^
p509.cpp:37:7: error: redefinition of 'exception'
class exception {
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:97:29: note: previous definition is here
class _LIBCPP_EXCEPTION_ABI exception
                            ^
p509.cpp:49:7: error: redefinition of 'bad_exception'
class bad_exception : public exception {
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:105:29: note: previous definition is here
class _LIBCPP_EXCEPTION_ABI bad_exception
                            ^
p509.cpp:79:1: error: expected unqualified-id
try {
^
p509.cpp:81:3: error: expected unqualified-id
} catch(...) {
  ^
p509.cpp:87:7: error: redefinition of 'nested_exception'
class nested_exception {
      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/exception:234:29: note: previous definition is here
class _LIBCPP_EXCEPTION_ABI nested_exception
                            ^
p509.cpp:101:1: error: C++ requires a type specifier for all declarations
nested_exception() noexcept;
^
p509.cpp:102:36: error: non-member function cannot have 'const' qualifier
[[noreturn]] void rethrow_nested() const;
                                   ^~~~~
p509.cpp:103:28: error: non-member function cannot have 'const' qualifier
exception_ptr nested_ptr() const noexcept;
                           ^~~~~~
p509.cpp:106:1: error: expected unqualified-id
dynamic_cast<const nested_exception&>(e).rethrow_nested();
^
p509.cpp:111:25: error: redefinition of 'initializer_list'
template<class E> class initializer_list {
                        ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/initializer_list:59:28: note: previous definition is here
class _LIBCPP_TEMPLATE_VIS initializer_list
                           ^
p509.cpp:130:11: error: no template named 'initializer_list'; did you mean 'std::initializer_list'?
constexpr initializer_list() noexcept;
          ^~~~~~~~~~~~~~~~
          std::initializer_list
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/initializer_list:59:28: note: 'std::initializer_list' declared here
class _LIBCPP_TEMPLATE_VIS initializer_list
                           ^
p509.cpp:130:11: error: deduction guide must be declared in the same scope as template 'std::initializer_list'
constexpr initializer_list() noexcept;
          ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/initializer_list:59:28: note: template is declared here
class _LIBCPP_TEMPLATE_VIS initializer_list
                           ^
p509.cpp:130:11: error: deduction guide cannot be declared 'constexpr'
constexpr initializer_list() noexcept;
~~~~~~~~~ ^
p509.cpp:130:11: error: deduction guide declaration without trailing return type
p509.cpp:133:17: error: unknown type name 'E'
constexpr const E* begin() const noexcept;
                ^
p509.cpp:133:28: error: non-member function cannot have 'const' qualifier
constexpr const E* begin() const noexcept;
                           ^~~~~~
p509.cpp:134:17: error: unknown type name 'E'
constexpr const E* end() const noexcept;
                ^
p509.cpp:134:26: error: non-member function cannot have 'const' qualifier
constexpr const E* end() const noexcept;
                         ^~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

$ g++-7 p509.cpp -std=c++03  -Wall
p509.cpp:17:1: warning: identifier 'noexcept' is a keyword in C++11 [-Wc++11-compat]
 unexpected_handler get_unexpected() noexcept;
 ^~~~~~~~~~~~~~~~~~
p509.cpp:119:1: warning: identifier 'constexpr' is a keyword in C++11 [-Wc++11-compat]
 constexpr initializer_list() noexcept;
 ^~~~~~~~~
p509.cpp:16:7: error: expected nested-name-specifier before 'unexpected_handler'
 using unexpected_handler = void (*)();
       ^~~~~~~~~~~~~~~~~~
p509.cpp:17:37: error: expected initializer before 'noexcept'
 unexpected_handler get_unexpected() noexcept;
                                     ^~~~~~~~
p509.cpp:18:57: error: expected initializer before 'noexcept'
 unexpected_handler set_unexpected(unexpected_handler f) noexcept;
                                                         ^~~~~~~~
p509.cpp:19:1: error: expected unqualified-id before '[' token
 [[noreturn]] void unexpected();
 ^
p509.cpp:20:7: error: expected nested-name-specifier before 'terminate_handler'
 using terminate_handler = void (*)();
       ^~~~~~~~~~~~~~~~~
p509.cpp:21:35: error: expected initializer before 'noexcept'
 terminate_handler get_terminate() noexcept;
                                   ^~~~~~~~
p509.cpp:22:54: error: expected initializer before 'noexcept'
 terminate_handler set_terminate(terminate_handler f) noexcept;
                                                      ^~~~~~~~
p509.cpp:23:1: error: expected unqualified-id before '[' token
 [[noreturn]] void terminate() noexcept;
 ^
p509.cpp:24:27: error: expected initializer before 'noexcept'
 int uncaught_exceptions() noexcept;
                           ^~~~~~~~
p509.cpp:26:27: error: expected initializer before 'noexcept'
 bool uncaught_exception() noexcept;
                           ^~~~~~~~
p509.cpp:27:7: error: expected nested-name-specifier before 'exception_ptr'
 using exception_ptr = unspecified ;
       ^~~~~~~~~~~~~
p509.cpp:28:1: error: 'exception_ptr' does not name a type; did you mean 'exception'?
 exception_ptr current_exception() noexcept;
 ^~~~~~~~~~~~~
 exception
p509.cpp:29:1: error: expected unqualified-id before '[' token
 [[noreturn]] void rethrow_exception(exception_ptr p);
 ^
p509.cpp:30:19: error: 'exception_ptr' does not name a type; did you mean 'exception'?
 template<class E> exception_ptr make_exception_ptr(E e) noexcept;
                   ^~~~~~~~~~~~~
                   exception
p509.cpp:31:20: error: expected unqualified-id before '[' token
 template <class T> [[noreturn]] void throw_with_nested(T&& t);
                    ^
p509.cpp:37:7: error: redefinition of 'class std::exception'
 class exception {
       ^~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:38:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/exception.h:60:9: note: previous definition of 'class std::exception'
   class exception
         ^~~~~~~~~
p509.cpp:49:7: error: redefinition of 'class std::bad_exception'
 class bad_exception : public exception {
       ^~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:46:9: note: previous definition of 'class std::bad_exception'
   class bad_exception : public exception
         ^~~~~~~~~~~~~
p509.cpp:60:7: error: expected nested-name-specifier before 'terminate_handler'
 using terminate_handler = void (*)();
       ^~~~~~~~~~~~~~~~~
p509.cpp:63:1: error: 'terminate_handler' does not name a type; did you mean 'sa_handler'?
 terminate_handler set_terminate(terminate_handler f) noexcept;
 ^~~~~~~~~~~~~~~~~
 sa_handler
p509.cpp:66:1: error: 'terminate_handler' does not name a type; did you mean 'sa_handler'?
 terminate_handler get_terminate() noexcept;
 ^~~~~~~~~~~~~~~~~
 sa_handler
p509.cpp:69:1: error: expected unqualified-id before '[' token
 [[noreturn]] void terminate() noexcept;
 ^
p509.cpp:72:27: error: expected initializer before 'noexcept'
 int uncaught_exceptions() noexcept;
                           ^~~~~~~~
p509.cpp:75:7: error: expected nested-name-specifier before 'exception_ptr'
 using exception_ptr = unspecified ;
       ^~~~~~~~~~~~~
p509.cpp:76:1: error: 'exception_ptr' does not name a type
 exception_ptr current_exception() noexcept;
 ^~~~~~~~~~~~~
p509.cpp:77:1: error: expected unqualified-id before '[' token
 [[noreturn]] void rethrow_exception(exception_ptr p);
 ^
p509.cpp:79:1: error: expected unqualified-id before 'try'
 try {
 ^~~
p509.cpp:81:3: error: expected unqualified-id before 'catch'
 } catch(...) {
   ^~~~~
p509.cpp:89:18: error: expected ';' at end of member declaration
 nested_exception() noexcept;
                  ^
p509.cpp:89:20: error: 'noexcept' does not name a type
 nested_exception() noexcept;
                    ^~~~~~~~
p509.cpp:89:20: note: C++11 'noexcept' only available with -std=c++11 or -std=gnu++11
p509.cpp:90:41: error: expected ';' at end of member declaration
 nested_exception(const nested_exception&) noexcept = default;
                                         ^
p509.cpp:90:43: error: 'noexcept' does not name a type
 nested_exception(const nested_exception&) noexcept = default;
                                           ^~~~~~~~
p509.cpp:90:43: note: C++11 'noexcept' only available with -std=c++11 or -std=gnu++11
p509.cpp:91:52: error: expected ';' at end of member declaration
 nested_exception& operator=(const nested_exception&) noexcept = default;
                                                    ^
p509.cpp:91:54: error: 'noexcept' does not name a type
 nested_exception& operator=(const nested_exception&) noexcept = default;
                                                      ^~~~~~~~
p509.cpp:91:54: note: C++11 'noexcept' only available with -std=c++11 or -std=gnu++11
p509.cpp:92:31: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
 virtual ~nested_exception() = default;
                               ^~~~~~~
p509.cpp:94:1: error: expected unqualified-id before '[' token
 [[noreturn]] void rethrow_nested() const;
 ^
p509.cpp:95:1: error: 'exception_ptr' does not name a type; did you mean 'exception'?
 exception_ptr nested_ptr() const noexcept;
 ^~~~~~~~~~~~~
 exception
p509.cpp:97:19: error: expected unqualified-id before '[' token
 template<class T> [[noreturn]] void throw_with_nested(T&& t);
                   ^
p509.cpp:101:20: error: expected constructor, destructor, or type conversion before 'noexcept'
 nested_exception() noexcept;
                    ^~~~~~~~
p509.cpp:102:1: error: expected unqualified-id before '[' token
 [[noreturn]] void rethrow_nested() const;
 ^
p509.cpp:103:1: error: 'exception_ptr' does not name a type
 exception_ptr nested_ptr() const noexcept;
 ^~~~~~~~~~~~~
p509.cpp:104:20: error: expected unqualified-id before '[' token
 template <class T> [[noreturn]] void throw_with_nested(T&& t);
                    ^
p509.cpp:106:1: error: expected unqualified-id before 'dynamic_cast'
 dynamic_cast<const nested_exception&>(e).rethrow_nested();
 ^~~~~~~~~~~~
p509.cpp:113:7: error: expected nested-name-specifier before 'value_type'
 using value_type = E;
       ^~~~~~~~~~
p509.cpp:114:7: error: expected nested-name-specifier before 'reference'
 using reference = const E&;
       ^~~~~~~~~
p509.cpp:115:7: error: expected nested-name-specifier before 'const_reference'
 using const_reference = const E&;
       ^~~~~~~~~~~~~~~
p509.cpp:116:7: error: expected nested-name-specifier before 'size_type'
 using size_type = size_t;
       ^~~~~~~~~
p509.cpp:117:7: error: expected nested-name-specifier before 'iterator'
 using iterator = const E*;
       ^~~~~~~~
p509.cpp:118:7: error: expected nested-name-specifier before 'const_iterator'
 using const_iterator = const E*;
       ^~~~~~~~~~~~~~
p509.cpp:119:1: error: 'constexpr' does not name a type
 constexpr initializer_list() noexcept;
 ^~~~~~~~~
p509.cpp:119:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:120:1: error: 'constexpr' does not name a type
 constexpr size_t size() const noexcept; // number of elements
 ^~~~~~~~~
p509.cpp:120:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:121:1: error: 'constexpr' does not name a type
 constexpr const E* begin() const noexcept; // first element
 ^~~~~~~~~
p509.cpp:121:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:122:1: error: 'constexpr' does not name a type
 constexpr const E* end() const noexcept; // one past the last element
 ^~~~~~~~~
p509.cpp:122:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:125:19: error: 'constexpr' does not name a type
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                   ^~~~~~~~~
p509.cpp:125:19: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:126:19: error: 'constexpr' does not name a type
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                   ^~~~~~~~~
p509.cpp:126:19: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:130:1: error: 'constexpr' does not name a type
 constexpr initializer_list() noexcept;
 ^~~~~~~~~
p509.cpp:130:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:133:1: error: 'constexpr' does not name a type
 constexpr const E* begin() const noexcept;
 ^~~~~~~~~
p509.cpp:133:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:134:1: error: 'constexpr' does not name a type
 constexpr const E* end() const noexcept;
 ^~~~~~~~~
p509.cpp:134:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:135:1: error: 'constexpr' does not name a type
 constexpr size_t size() const noexcept;
 ^~~~~~~~~
p509.cpp:135:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:138:19: error: 'constexpr' does not name a type
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                   ^~~~~~~~~
p509.cpp:138:19: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
p509.cpp:139:19: error: 'constexpr' does not name a type
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                   ^~~~~~~~~
p509.cpp:139:19: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11

$ g++-7 p509.cpp -std=c++11  -Wall
p509.cpp:27:35: error: 'using exception_ptr = unspecified' conflicts with a previous declaration
 using exception_ptr = unspecified ;
                                   ^
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:142:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/exception_ptr.h:79:11: note: previous declaration 'class std::__exception_ptr::exception_ptr'
     class exception_ptr
           ^~~~~~~~~~~~~
p509.cpp:27:35: error: 'using exception_ptr = unspecified' conflicts with a previous declaration
 using exception_ptr = unspecified ;
                                   ^
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:142:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/exception_ptr.h:79:11: note: previous declaration 'class std::__exception_ptr::exception_ptr'
     class exception_ptr
           ^~~~~~~~~~~~~
p509.cpp:37:7: error: redefinition of 'class std::exception'
 class exception {
       ^~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:38:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/exception.h:60:9: note: previous definition of 'class std::exception'
   class exception
         ^~~~~~~~~
p509.cpp:49:7: error: redefinition of 'class std::bad_exception'
 class bad_exception : public exception {
       ^~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:46:9: note: previous definition of 'class std::bad_exception'
   class bad_exception : public exception
         ^~~~~~~~~~~~~
p509.cpp:79:1: error: expected unqualified-id before 'try'
 try {
 ^~~
p509.cpp:81:3: error: expected unqualified-id before 'catch'
 } catch(...) {
   ^~~~~
p509.cpp:87:7: error: redefinition of 'class std::nested_exception'
 class nested_exception {
       ^~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:143:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/nested_exception.h:52:9: note: previous definition of 'class std::nested_exception'
   class nested_exception
         ^~~~~~~~~~~~~~~~
p509.cpp:101:28: error: expected constructor, destructor, or type conversion before ';' token
 nested_exception() noexcept;
                            ^
p509.cpp:102:36: error: non-member function 'void rethrow_nested()' cannot have cv-qualifier
 [[noreturn]] void rethrow_nested() const;
                                    ^~~~~
p509.cpp:103:34: error: non-member function 'exception_ptr nested_ptr()' cannot have cv-qualifier
 exception_ptr nested_ptr() const noexcept;
                                  ^~~~~~~~
p509.cpp:106:1: error: expected unqualified-id before 'dynamic_cast'
 dynamic_cast<const nested_exception&>(e).rethrow_nested();
 ^~~~~~~~~~~~
p509.cpp:111:25: error: redefinition of 'class std::initializer_list<_E>'
 template<class E> class initializer_list {
                         ^~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/range_access.h:36:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/string:51,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/locale_classes.h:40,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ios_base.h:41,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:42,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/initializer_list:47:11: note: previous definition of 'class std::initializer_list<_E>'
     class initializer_list
           ^~~~~~~~~~~~~~~~
p509.cpp:130:30: error: ISO C++ forbids declaration of 'initializer_list' with no type [-fpermissive]
 constexpr initializer_list() noexcept;
                              ^~~~~~~~
p509.cpp:133:17: error: 'E' does not name a type
 constexpr const E* begin() const noexcept;
                 ^
p509.cpp:134:17: error: 'E' does not name a type
 constexpr const E* end() const noexcept;
                 ^
p509.cpp:135:31: error: non-member function 'constexpr size_t size()' cannot have cv-qualifier
 constexpr size_t size() const noexcept;
                               ^~~~~~~~
p509.cpp:138:62: error: expected primary-expression before '>' token
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                                              ^
p509.cpp:138:64: error: 'il' was not declared in this scope
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                                                ^~
p509.cpp:138:38: warning: variable templates only available with -std=c++14 or -std=gnu++14
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                      ^~~~~
p509.cpp:138:68: error: expected ';' before 'noexcept'
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                                                    ^~~~~~~~
p509.cpp:139:60: error: expected primary-expression before '>' token
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                                                            ^
p509.cpp:139:62: error: 'il' was not declared in this scope
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                                                              ^~
p509.cpp:139:38: warning: variable templates only available with -std=c++14 or -std=gnu++14
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                                      ^~~
p509.cpp:139:66: error: expected ';' before 'noexcept'
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                                                                  ^~~~~~~~

$ g++-7 p509.cpp -std=c++17  -Wall
p509.cpp:27:35: error: 'using exception_ptr = unspecified' conflicts with a previous declaration
 using exception_ptr = unspecified ;
                                   ^
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:142:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/exception_ptr.h:79:11: note: previous declaration 'class std::__exception_ptr::exception_ptr'
     class exception_ptr
           ^~~~~~~~~~~~~
p509.cpp:27:35: error: 'using exception_ptr = unspecified' conflicts with a previous declaration
 using exception_ptr = unspecified ;
                                   ^
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:142:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/exception_ptr.h:79:11: note: previous declaration 'class std::__exception_ptr::exception_ptr'
     class exception_ptr
           ^~~~~~~~~~~~~
p509.cpp:37:7: error: redefinition of 'class std::exception'
 class exception {
       ^~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:38:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/exception.h:60:9: note: previous definition of 'class std::exception'
   class exception
         ^~~~~~~~~
p509.cpp:49:7: error: redefinition of 'class std::bad_exception'
 class bad_exception : public exception {
       ^~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:46:9: note: previous definition of 'class std::bad_exception'
   class bad_exception : public exception
         ^~~~~~~~~~~~~
p509.cpp:79:1: error: expected unqualified-id before 'try'
 try {
 ^~~
p509.cpp:81:3: error: expected unqualified-id before 'catch'
 } catch(...) {
   ^~~~~
p509.cpp:87:7: error: redefinition of 'class std::nested_exception'
 class nested_exception {
       ^~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/exception:143:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:39,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/nested_exception.h:52:9: note: previous definition of 'class std::nested_exception'
   class nested_exception
         ^~~~~~~~~~~~~~~~
p509.cpp:101:28: error: expected constructor, destructor, or type conversion before ';' token
 nested_exception() noexcept;
                            ^
p509.cpp:102:36: error: non-member function 'void rethrow_nested()' cannot have cv-qualifier
 [[noreturn]] void rethrow_nested() const;
                                    ^~~~~
p509.cpp:103:34: error: non-member function 'exception_ptr nested_ptr()' cannot have cv-qualifier
 exception_ptr nested_ptr() const noexcept;
                                  ^~~~~~~~
p509.cpp:106:1: error: expected unqualified-id before 'dynamic_cast'
 dynamic_cast<const nested_exception&>(e).rethrow_nested();
 ^~~~~~~~~~~~
p509.cpp:111:25: error: redefinition of 'class std::initializer_list<_E>'
 template<class E> class initializer_list {
                         ^~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/range_access.h:36:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/string:51,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/locale_classes.h:40,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ios_base.h:41,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:42,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from p509.cpp:6:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/initializer_list:47:11: note: previous definition of 'class std::initializer_list<_E>'
     class initializer_list
           ^~~~~~~~~~~~~~~~
p509.cpp:130:30: error: ISO C++ forbids declaration of 'initializer_list' with no type [-fpermissive]
 constexpr initializer_list() noexcept;
                              ^~~~~~~~
p509.cpp:133:17: error: 'E' does not name a type
 constexpr const E* begin() const noexcept;
                 ^
p509.cpp:134:17: error: 'E' does not name a type
 constexpr const E* end() const noexcept;
                 ^
p509.cpp:135:31: error: non-member function 'constexpr size_t size()' cannot have cv-qualifier
 constexpr size_t size() const noexcept;
                               ^~~~~~~~
p509.cpp:138:62: error: expected primary-expression before '>' token
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                                              ^
p509.cpp:138:64: error: 'il' was not declared in this scope
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                                                ^~
p509.cpp:138:68: error: expected ';' before 'noexcept'
 template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
                                                                    ^~~~~~~~
p509.cpp:139:60: error: expected primary-expression before '>' token
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                                                            ^
p509.cpp:139:62: error: 'il' was not declared in this scope
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                                                              ^~
p509.cpp:139:66: error: expected ';' before 'noexcept'
 template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
                                                                  ^~~~~~~~

検討事項(agenda)

コンパイルエラーの分類
役に立つまたは意味のある出力

参考資料(reference)

N4606 Working Draft 2016, ISO/IEC 14882, C++ standardのコード断片をコンパイルするためにしていること
https://qiita.com/kaizen_nagoya/items/a8d7ee2f2e29e76c19c1

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

Clang/Clang++(LLVM) gcc/g++(GNU) コンパイラ警告等比較
https://qiita.com/kaizen_nagoya/items/9a82b958cc3aeef0403f

Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d

MISRA C++ 5-0-16
https://qiita.com/kaizen_nagoya/items/7df2d4e05db724752a74

C++ Templates Part1 BASICS Chapter 3. Class Templates 3.2 Use of Class Template Stack stack1test.cpp
https://qiita.com/kaizen_nagoya/items/cd5fc49106fad5a4e9ed

ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1

C言語(C++)に対する誤解、曲解、無理解、爽快。
https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9

'wchar.h' file not found で困った clang++ macOS
https://qiita.com/kaizen_nagoya/items/de15cd46d657517fac11

Open POSIX Test Suiteの使い方を調べはじめました
https://qiita.com/kaizen_nagoya/items/644d5e407f5faf96e6dc

MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認
https://qiita.com/kaizen_nagoya/items/96dc8b125e462d5575bb

どうやって MISRA Example Suiteをコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00

MISRA C まとめ #include
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671

文書履歴(document history)

ver. 0.10 初稿 20180430