[llvm] r219069 - [SystemZ] Make operator bool explicit. NFC.

Benjamin Kramer benny.kra at gmail.com
Mon Oct 6 10:16:42 PDT 2014


On 05.10.2014, at 03:12, David Blaikie <dblaikie at gmail.com> wrote:

> Clang-tidy check for non-explicit operator bool?

It might make sense to enforce this in LLVM, the only (I think) legitimate uses are in (Small)BitVector's bit reference class. The pattern is easily grepable, so clang-tidy might be overkill. 

> Clang warning for implicit calls to operator bool?

Those are (almost) always implicit ;)

It could be useful to catch implicit conversions via operator bool to a type that is not bool. In the other implicit bool patch (r219068) there was an implicit conversion from AAMDNodes to unsigned via operator bool. That's really sneaky and a warning makes a lot of sense imo. I probably won't have time to implement any of that currently though :(

- Ben

> 
> On Oct 4, 2014 3:59 PM, "Benjamin Kramer" <benny.kra at googlemail.com> wrote:
> Author: d0k
> Date: Sat Oct  4 17:44:35 2014
> New Revision: 219069
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=219069&view=rev
> Log:
> [SystemZ] Make operator bool explicit. NFC.
> 
> Modified:
>     llvm/trunk/lib/Target/SystemZ/SystemZElimCompare.cpp
>     llvm/trunk/lib/Target/SystemZ/SystemZInstrInfo.cpp
> 
> Modified: llvm/trunk/lib/Target/SystemZ/SystemZElimCompare.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZElimCompare.cpp?rev=219069&r1=219068&r2=219069&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/SystemZ/SystemZElimCompare.cpp (original)
> +++ llvm/trunk/lib/Target/SystemZ/SystemZElimCompare.cpp Sat Oct  4 17:44:35 2014
> @@ -47,7 +47,7 @@ struct Reference {
>      return *this;
>    }
> 
> -  operator bool() const { return Def || Use; }
> +  LLVM_EXPLICIT operator bool() const { return Def || Use; }
> 
>    // True if the register is defined or used in some form, either directly or
>    // via a sub- or super-register.
> 
> Modified: llvm/trunk/lib/Target/SystemZ/SystemZInstrInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZInstrInfo.cpp?rev=219069&r1=219068&r2=219069&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/SystemZ/SystemZInstrInfo.cpp (original)
> +++ llvm/trunk/lib/Target/SystemZ/SystemZInstrInfo.cpp Sat Oct  4 17:44:35 2014
> @@ -633,7 +633,7 @@ struct LogicOp {
>    LogicOp(unsigned regSize, unsigned immLSB, unsigned immSize)
>      : RegSize(regSize), ImmLSB(immLSB), ImmSize(immSize) {}
> 
> -  operator bool() const { return RegSize; }
> +  LLVM_EXPLICIT operator bool() const { return RegSize; }
> 
>    unsigned RegSize, ImmLSB, ImmSize;
>  };
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list