util/bitset: Make C++ wrapper trivially constructible.
authorFrancisco Jerez <currojerez@riseup.net>
Sun, 25 Feb 2018 02:37:34 +0000 (18:37 -0800)
committerFrancisco Jerez <currojerez@riseup.net>
Tue, 27 Feb 2018 19:38:18 +0000 (11:38 -0800)
In order to fix a build failure on compilers not implementing
unrestricted unions, which is a C++11 feature.

v2: Provide signed integer comparison and assignment operators instead
    of BITSET_WORD ones to avoid spurious ambiguity warnings on
    comparisons with a signed integer literal.

Fixes: ba79a90fb52e1e81fb "glsl: Switch ast_type_qualifier to a 128-bit bitset."
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105238
Tested-by: Roland Scheidegger <sroland@vmware.com>
Tested-By: George Kyriazis <george.kyriazis@intel.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/compiler/glsl/ast.h
src/compiler/glsl/glsl_parser.yy
src/util/bitset.h

index e5e4b572fff45d7704dba03864e09ce197dc6a93..a1ec0d566f45c2eaac7e688bb48fdfb8dcfa3bb6 100644 (file)
@@ -477,8 +477,6 @@ struct ast_type_qualifier {
    DECLARE_BITSET_T(bitset_t, 128);
 
    union flags {
-      flags() : i(0) {}
-
       struct {
         unsigned invariant:1;
          unsigned precise:1;
index f1986ed0a8ac1bef2c6f0a2cdf0c1b3410296401..e5ea41d4dff2e880e5353965feef437bdd1fb79a 100644 (file)
@@ -96,7 +96,6 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
 %parse-param {struct _mesa_glsl_parse_state *state}
 
 %union {
-   YYSTYPE() {}
    int n;
    int64_t n64;
    float real;
index 7bb5f3c83cfdb811e00d426d6ef0a7ab6dee41a3..b4c21520238ef4c65657b0c419c28d54ff968367 100644 (file)
@@ -142,23 +142,6 @@ __bitset_next_set(unsigned i, BITSET_WORD *tmp,
  * it as, and N is the number of bits in the bitset.
  */
 #define DECLARE_BITSET_T(T, N) struct T {                       \
-      /* XXX - Replace this with an implicitly-defined          \
-       * constructor when support for C++11 defaulted           \
-       * constructors can be assumed (available on GCC 4.4 and  \
-       * later) in order to make the object trivially           \
-       * constructible like a fundamental integer type for      \
-       * convenience.                                           \
-       */                                                       \
-      T()                                                       \
-      {                                                         \
-      }                                                         \
-                                                                \
-      T(BITSET_WORD x)                                          \
-      {                                                         \
-         for (unsigned i = 0; i < BITSET_WORDS(N); i++, x = 0)  \
-            words[i] = x;                                       \
-      }                                                         \
-                                                                \
       EXPLICIT_CONVERSION                                       \
       operator bool() const                                     \
       {                                                         \
@@ -168,6 +151,13 @@ __bitset_next_set(unsigned i, BITSET_WORD *tmp,
          return false;                                          \
       }                                                         \
                                                                 \
+      T &                                                       \
+      operator=(int x)                                          \
+      {                                                         \
+         const T c = {{ (BITSET_WORD)x }};                      \
+         return *this = c;                                      \
+      }                                                         \
+                                                                \
       friend bool                                               \
       operator==(const T &b, const T &c)                        \
       {                                                         \
@@ -180,6 +170,19 @@ __bitset_next_set(unsigned i, BITSET_WORD *tmp,
          return !(b == c);                                      \
       }                                                         \
                                                                 \
+      friend bool                                               \
+      operator==(const T &b, int x)                             \
+      {                                                         \
+         const T c = {{ (BITSET_WORD)x }};                      \
+         return b == c;                                         \
+      }                                                         \
+                                                                \
+      friend bool                                               \
+      operator!=(const T &b, int x)                             \
+      {                                                         \
+         return !(b == x);                                      \
+      }                                                         \
+                                                                \
       friend T                                                  \
       operator~(const T &b)                                     \
       {                                                         \