Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

なぜ人はdefault ctorのdefault指定時にconstexprを明示したくなってしまうのか #35

Open
yumetodo opened this issue Jun 25, 2019 · 8 comments
Labels
bug Something isn't working

Comments

@yumetodo
Copy link
Contributor

yumetodo commented Jun 25, 2019

#21 でも一回指摘したのですが、まだあったようです。

https://github.com/Kasugaccho/DungeonTemplateLibrary/blob/53065f516678db545264bd960f81658a4d5ab174/include/DTL/Range/BasicRect.hpp#L67

つ~か #33 の継承ctor周りが通らない原因になってたりとか、もしかしてしませんか?(未検証
ちがったぽい

@yumetodo
Copy link
Contributor Author

他にもあるかもしれんので再度確認されたほうがいいのではと

@AsPJT
Copy link
Owner

AsPJT commented Jun 25, 2019

確認してみます。

@AsPJT AsPJT added the bug Something isn't working label Jun 25, 2019
@AsPJT
Copy link
Owner

AsPJT commented Jun 29, 2019

デフォルトコンストラクタについている constexpr を全て削除しました。

それと、
#21 での指摘は constexpr の有無ではなく
noexcept の有無だと思います。

@yumetodo
Copy link
Contributor Author

あれっ私間違ったこと言っている気がしてきたぞ・・・ちょっとまてよ・・・

@yumetodo
Copy link
Contributor Author

yumetodo commented Jun 29, 2019

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index 209f395..d920a7d 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -250,7 +250,10 @@ _GLIBCXX_END_NAMESPACE_VERSION
 	// 20.11.5.1 construction / copy / destroy
 	constexpr duration() = default;
 
-	constexpr duration(const duration&) = default;
+	// NB: Make constexpr implicit. This cannot be explicitly
+	// constexpr, as any UDT that is not a literal type with a
+	// constexpr copy constructor will be ill-formed.
+	duration(const duration&) = default;
 
 	template<typename _Rep2, typename = typename
 	       enable_if<is_convertible<_Rep2, rep>::value

https://gcc.gnu.org/ml/libstdc++/2012-10/msg00120.html

これがどういう意味かさっぱり理解出来ないです。そもそもUDT #とはhttps://t.co/2oykOFuxda#constexpr #cpp @bolero_MURAKAMI @_EnumHack pic.twitter.com/Z4sgBtbvor

— yumetodo-鳥の氷河から逃げる (@yumetodo) 2016年3月14日

@yumetodo つまり、duration<Rep> の Rep は非リテラル型なユーザ定義型である可能性があるため、明示的にconstexpr指定しないようにする変更。Rep がリテラル型である場合、トリビアルコピーコンストラクタは暗黙にconstexpr指定される。

— 狂える中3女子ボレロ村上/陶芸C++er (@bolero_MURAKAMI) 2016年3月14日

@bolero_MURAKAMI >トリビアルコピーコンストラクタは暗黙にconstexpr指定される。
今日まで気がついてなかった・・・。
ありがとうございます。

— yumetodo-鳥の氷河から逃げる (@yumetodo) 2016年3月14日

@yumetodo 直訳:暗黙にconstexpr指定される。非リテラル型な任意のUDT(User-Defined Type)に対して、constexprコピーコンストラクタはill-formedになるため、明示的にconstexpr指定すべきでない。

— 狂える中3女子ボレロ村上/陶芸C++er (@bolero_MURAKAMI) 2016年3月14日

これが背景

@yumetodo
Copy link
Contributor Author

つまりこのIssueは間違っていた・・・?(落ち着いて後で考える

@yumetodo
Copy link
Contributor Author

とりあえずstatic_assertでconstexprに構築できるかテストするべき

@yumetodo
Copy link
Contributor Author

そもそもこれデフォルトコンストラクタは自動生成されると思うのでいらないような気がしている。
一方でconstexpr BasicRect() = default; みたいに書いても問題はなさそうではある・・・

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants