LoginSignup
1
0

N4606 Working Draft 2016, ISO/IEC 14882, C++ standard(33)4.13 Function pointer conversions [conv.fctptr] p89

Last updated at Posted at 2018-04-15

はじめに

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

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++が標準化の動きとの時間的な擦れの確認が結果としてできれば幸いです。

list

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

Compiler

###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)

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

#(33)4.13 Function pointer conversions [conv.fctptr]
p89

p89.cpp
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf 
#define msg "p89.cpp (33)4.13 Function pointer conversions [conv.fctptr]"

#include <iostream>

void (*p)() throw(int);
void (**pp)() noexcept = &p; // error: cannot convert to pointer to noexcept function
struct S { typedef void (*p)(); operator p(); };
void (*q)() noexcept = S(); // error: cannot convert to pointer to noexcept function

int main(int argc, char *argv[], char *envp[]){
  std::cout << "q="<<q <<" p=" <<p <<" pp="<< pp<< std::endl;
  std::cout << msg << std::endl;
  return EXIT_SUCCESS;
}
$ clang++ p89.cpp
p89.cpp:8:9: error: exception specifications are not allowed beyond a single level of indirection
void (**pp)() noexcept = &p; // error: cannot convert to pointer to noexcept function
        ^
1 error generated.

$ g++ p89.cpp
p89.cpp:8:15: error: 'pp' declared with an exception specification
 void (**pp)() noexcept = &p; // error: cannot convert to pointer to noexcept function
               ^~~~~~~~
$ ./cppgl17.sh p89
$ clang++ p89.cpp
p89.cpp:7:13: error: ISO C++17 does not allow dynamic exception specifications [-Wdynamic-exception-spec]
void (*p)() throw(int);
            ^~~~~~~~~~
p89.cpp:7:13: note: use 'noexcept(false)' instead
void (*p)() throw(int);
            ^~~~~~~~~~
            noexcept(false)
p89.cpp:8:9: error: cannot initialize a variable of type 'void (**)() noexcept' with an rvalue of type 'void (**)() throw(int)'
void (**pp)() noexcept = &p; // error: cannot convert to pointer to noexcept function
        ^                ~~
p89.cpp:10:8: error: no viable conversion from 'S' to 'void (*)() noexcept'
void (*q)() noexcept = S(); // error: cannot convert to pointer to noexcept function
       ^               ~~~
p89.cpp:9:33: note: candidate function
struct S { typedef void (*p)(); operator p(); };
                                ^
3 errors generated.

$ g++-7 p89.cpp
p89.cpp:7:13: error: ISO C++1z does not allow dynamic exception specifications
 void (*p)() throw(int);
             ^~~~~
p89.cpp:8:26: error: invalid conversion from 'void (**)()' to 'void (**)() noexcept' [-fpermissive]
 void (**pp)() noexcept = &p; // error: cannot convert to pointer to noexcept function
                          ^~
p89.cpp:10:24: error: invalid user-defined conversion from 'S' to 'void (*)() noexcept' [-fpermissive]
 void (*q)() noexcept = S(); // error: cannot convert to pointer to noexcept function
                        ^~~
p89.cpp:9:33: note: candidate is: S::operator S::p() <near match>
 struct S { typedef void (*p)(); operator p(); };
                                 ^~~~~~~~
p89.cpp:9:33: note:   no known conversion from 'S::p {aka void (*)()}' to 'void (*)() noexcept'

#検討事項
-std=c++17でのエラーになる事項の検討。
 内容の出力。

#参考資料

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da
Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d
#文書履歴

0.10 初稿 2080415

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0