[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] const or reference members
From: |
Vadim Zeitlin |
Subject: |
Re: [lmi] const or reference members |
Date: |
Wed, 13 Jul 2022 13:20:22 +0200 |
On Wed, 13 Jul 2022 03:03:38 +0000 Greg Chicares <gchicares@sbcglobal.net>
wrote:
GC> The saddest words in the language standard are "no diagnostic required".
GC>
GC> Let's see what our compilers do with this patch:
GC>
GC> --8<----8<----8<----8<----8<----8<----8<----8<--
GC> diff --git a/gpt_server.hpp b/gpt_server.hpp
GC> index 524be42e2..431b75bd5 100644
GC> --- a/gpt_server.hpp
GC> +++ b/gpt_server.hpp
GC> @@ -66,6 +66,8 @@ class LMI_SO gpt_server final
GC> double seconds_for_output () const;
GC>
GC> private:
GC> + int i {0};
GC> + int& ri {i};
GC> mcenum_emission emission_ {mce_emit_nothing};
GC> gpt_state state_ {};
GC> double seconds_for_input_ {0.0};
GC> --8<----8<----8<----8<----8<----8<----8<----8<--
GC>
GC> gcc-11: it compiles and links, with no diagnostics.
I think this is reasonable because nothing bad happens here until you try
to actually copy gpt_server objects and even then you'd "just" get a
compiler error, which is the best possible kind of error.
GC> However, clang says:
GC>
GC> /opt/lmi/src/lmi/gpt_server.hpp:53:17: error: explicitly defaulted copy
assignment operator i
GC> s implicitly deleted [-Werror,-Wdefaulted-function-deleted]
But I also think this is reasonable and useful because it's more clear to
use "= delete" than "= default" here and this warning is useful for finding
all the places where it should be done. IOW clang moves compiler error to
the place which triggers instead of postponing it until the point of use,
which is, I think, a good thing.
Regards,
VZ
pgpvQtUytl7p0.pgp
Description: PGP signature
- [lmi] Compiler diagnostics [Was: master 6a59da54 8/8: When in doubt, prefer the Rule of Five to the Rule of Zero], (continued)
Re: [lmi] [lmi-commits] master 6a59da54 8/8: When in doubt, prefer the Rule of Five to the Rule of Zero, Vadim Zeitlin, 2022/07/11
- Re: [lmi] [lmi-commits] master 6a59da54 8/8: When in doubt, prefer the Rule of Five to the Rule of Zero, Greg Chicares, 2022/07/12
- Re: [lmi] [lmi-commits] master 6a59da54 8/8: When in doubt, prefer the Rule of Five to the Rule of Zero, Vadim Zeitlin, 2022/07/12
- [lmi] const or reference members [Was: When in doubt, prefer the Rule of Five to the Rule of Zero], Greg Chicares, 2022/07/12
- Re: [lmi] const or reference members, Vadim Zeitlin, 2022/07/12
- Re: [lmi] const or reference members, Greg Chicares, 2022/07/12
- Re: [lmi] const or reference members,
Vadim Zeitlin <=
[lmi] Is this class moveable or not? [Was: master 6a59da54 8/8: When in doubt, prefer the Rule of Five to the Rule of Zero], Greg Chicares, 2022/07/12
Re: [lmi] Is this class moveable or not?, Vadim Zeitlin, 2022/07/13
Re: [lmi] Is this class moveable or not?, Greg Chicares, 2022/07/13
[lmi] Move decays to copy [Was: When in doubt, prefer the Rule of Five to the Rule of Zero], Greg Chicares, 2022/07/12
Re: [lmi] Move decays to copy, Vadim Zeitlin, 2022/07/12
Re: [lmi] Move decays to copy, Greg Chicares, 2022/07/12
Re: [lmi] Move decays to copy, Vadim Zeitlin, 2022/07/13