Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

c++ - Constructor with by-value parameter & noexcept

In this example code:

explicit MyClass(std::wstring text) noexcept;

Is the use of noexcept here correct? wstring can potentially throw on construction but does the throw happen before we are in the constructor or while we are in the constructor?

EDIT: Suppose this can be generalised to any function taking a by-value parameter.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The construction and destruction of function parameters happens in the context of the caller. So no, if the construction of text throws, that is not a violation of noexcept.

Soon folks would comment and ask for a spec quote :) So I will give you 5.2.2p4

The initialization and destruction of each parameter occurs within the context of the calling function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...