lmi
[Top][All Lists]
Advanced

[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

Attachment: pgpvQtUytl7p0.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]