]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
compiler: error for duplicate bool map keys
authorIan Lance Taylor <iant@golang.org>
Tue, 3 May 2022 22:48:23 +0000 (15:48 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 6 May 2022 18:15:31 +0000 (11:15 -0700)
For golang/go#35945
Fixes golang/go#28104

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/403954

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc

index ef20a0aafd69ca9532b2e36f22b3a3f0f5a5f96f..4559551ab7be4fc15e0d6b847830ae8cbc076bfe 100644 (file)
@@ -1,4 +1,4 @@
-70ca85f08edf63f46c87d540fa99c45e2903edc2
+fbadca004b1e09db177c8e071706841038d1dd64
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 1b3b3bf135eaea92a285a5d4e1edda70680974c4..dce48e03bf46e1e24ab95361e4e0289f0d28beb0 100644 (file)
@@ -17266,6 +17266,8 @@ Composite_literal_expression::lower_map(Gogo* gogo, Named_object* function,
   Location location = this->location();
   Unordered_map(unsigned int, std::vector<Expression*>) st;
   Unordered_map(unsigned int, std::vector<Expression*>) nt;
+  bool saw_false = false;
+  bool saw_true = false;
   if (this->vals_ != NULL)
     {
       if (!this->has_keys_)
@@ -17300,6 +17302,7 @@ Composite_literal_expression::lower_map(Gogo* gogo, Named_object* function,
            continue;
          std::string sval;
          Numeric_constant nval;
+         bool bval;
          if ((*p)->string_constant_value(&sval)) // Check string keys.
            {
              unsigned int h = Gogo::hash_string(sval, 0);
@@ -17373,6 +17376,19 @@ Composite_literal_expression::lower_map(Gogo* gogo, Named_object* function,
                  mit->second.push_back(*p);
                }
            }
+         else if ((*p)->boolean_constant_value(&bval))
+           {
+             if ((bval && saw_true) || (!bval && saw_false))
+               {
+                 go_error_at((*p)->location(),
+                             "duplicate key in map literal");
+                 return Expression::make_error(location);
+               }
+             if (bval)
+               saw_true = true;
+             else
+               saw_false = true;
+           }
        }
     }