public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: "gprocida at google dot com" <sourceware-bugzilla@sourceware.org>
To: libabigail@sourceware.org
Subject: [Bug default/29679] New: C++20 compilation failure - ambiguous comparisons
Date: Thu, 13 Oct 2022 08:04:28 +0000	[thread overview]
Message-ID: <bug-29679-9487@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=29679

            Bug ID: 29679
           Summary: C++20 compilation failure - ambiguous comparisons
           Product: libabigail
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: default
          Assignee: dodji at redhat dot com
          Reporter: gprocida at google dot com
                CC: libabigail at sourceware dot org
  Target Milestone: ---

This was reported internally, along with a proposed fix.

To reproduce, change the C++ standard in configure.ac from 11 and 20,
reconfigure and rebuild.

With GCC:

  CXX      abg-dwarf-reader.lo
../../src/abg-dwarf-reader.cc: In function ‘bool
abigail::dwarf_reader::op_is_control_flow(Dwarf_Op*, size_t, size_t, size_t&,
dwarf_expr_eval_context&)’:
../../src/abg-dwarf-reader.cc:9007:16: error: ambiguous overload for
‘operator!=’ (operand types are ‘abigail::dwarf_reader::expr_result’ and ‘int’)
 9007 |       if (val1 != 0)
      |           ~~~~ ^~ ~
      |           |       |
      |           |       int
      |           abigail::dwarf_reader::expr_result
../../src/abg-dwarf-reader.cc:1735:3: note: candidate: ‘bool
abigail::dwarf_reader::expr_result::operator==(const
abigail::dwarf_reader::expr_result&) const’ (rewritten)
 1735 |   operator==(const expr_result& o) const
      |   ^~~~~~~~
../../src/abg-dwarf-reader.cc:9007:16: note: candidate: ‘operator!=(int64_t
{aka long int}, int)’ (built-in)
 9007 |       if (val1 != 0)
      |           ~~~~~^~~~

With Clang there are several more errors, but they are explained by:
https://github.com/llvm/llvm-project/issues/57711

The fix that was proposed internally was:

--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -1638,6 +1638,10 @@ public:
   {return const_value_ == o.const_value_ && is_const_ == o.is_const_;}

   bool
+  operator!=(const expr_result& o) const
+  {return !(*this == o);}
+
+  bool
   operator>=(const expr_result& o) const
   {return const_value_ >= o.const_value_;}

@@ -8364,7 +8368,7 @@ op_is_control_flow(Dwarf_Op* expr,

     case DW_OP_bra:
       val1 = ctxt.pop();
-      if (val1 != 0)
+      if (0 != val1)
        index += val1.const_value() - 1;
       break;

And the accompanying explanation was:

1. operator==(const expr_result&, const expr_result&) is ambiguous because
C++20 could call this with args (val1, 0) or with reversed args (0, val1).
This is because of implicit conversion from int to expr_result.
Adding operator!= disables argument reversal and resolves the ambiguity.

2. 0 == val1 is then illegal because the LHS (int) does not provide operator==.
When argument reversal is disabled, the LHS should provide operator==.
(Same for !=).

I'll be honest and say that I haven't followed the details of this.
However, another way to resolve the issue might be to eliminate the
implicit conversion - these tend to be sources of other surprises
anyway.

Regards,
Giuliano.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2022-10-13  8:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-13  8:04 gprocida at google dot com [this message]
2023-01-23 11:55 ` [Bug default/29679] " gprocida at google dot com

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=bug-29679-9487@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=libabigail@sourceware.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: link
Be 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).