[gjs] maint: Make all operator bool explicit



commit 488a224c25d74e621d7a193f5d88be07af3acba4
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Feb 24 10:36:50 2020 -0800

    maint: Make all operator bool explicit
    
    Tip from Steve Fink, this still allows using the object in the condition
    of an if statement, but prevents auto-converting to int.

 gjs/engine.cpp        | 4 +---
 gjs/jsapi-util-root.h | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)
---
diff --git a/gjs/engine.cpp b/gjs/engine.cpp
index 9592b2c5..e3bd937a 100644
--- a/gjs/engine.cpp
+++ b/gjs/engine.cpp
@@ -194,9 +194,7 @@ public:
         JS_ShutDown();
     }
 
-    operator bool() const {
-        return true;
-    }
+    explicit operator bool() const { return true; }
 };
 
 static GjsInit gjs_is_inited;
diff --git a/gjs/jsapi-util-root.h b/gjs/jsapi-util-root.h
index f8ce4cfc..b06d83ee 100644
--- a/gjs/jsapi-util-root.h
+++ b/gjs/jsapi-util-root.h
@@ -229,7 +229,7 @@ class GjsMaybeOwned {
     inline bool operator!=(std::nullptr_t) const { return !(*this == nullptr); }
 
     /* Likewise the truth value does not require a read barrier */
-    inline operator bool() const { return *this != nullptr; }
+    inline explicit operator bool() const { return *this != nullptr; }
 
     /* You can get a Handle<T> if the thing is rooted, so that you can use this
      * wrapper with stack rooting. However, you must not do this if the


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]