public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-158] compiler: error for duplicate bool map keys Date: Fri, 6 May 2022 18:16:00 +0000 (GMT) [thread overview] Message-ID: <20220506181600.C757A3857344@sourceware.org> (raw) https://gcc.gnu.org/g:374b3c936d62c8b6e7c607fdf6e84a83748e85c7 commit r13-158-g374b3c936d62c8b6e7c607fdf6e84a83748e85c7 Author: Ian Lance Taylor <iant@golang.org> Date: Tue May 3 15:48:23 2022 -0700 compiler: error for duplicate bool map keys For golang/go#35945 Fixes golang/go#28104 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/403954 Diff: --- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/expressions.cc | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index ef20a0aafd6..4559551ab7b 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -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. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 1b3b3bf135e..dce48e03bf4 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -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; + } } }
reply other threads:[~2022-05-06 18:16 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220506181600.C757A3857344@sourceware.org \ --to=ian@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).