DWARF reader: avoid C++20 operator!= overload ambiguity

Message ID 20230109092044.787665-1-gprocida@google.com
State New
Headers
Series DWARF reader: avoid C++20 operator!= overload ambiguity |

Commit Message

Giuliano Procida Jan. 9, 2023, 9:20 a.m. UTC
  C++20 automatically generates overloads for certain comparison
operators based on others and this can create ambiguity with older
code. The type expr_result has various operators defined and comparing
expr_result != int becomes ambiguous.

This change just avoids this comparison by extracting the underlying
value, rather than making changes to the type itself. There should be
no change in behaviour and no tests are affected.

	* (src/abg-dwarf-reader.cc) op_is_control_flow: In the
	DW_OP_bra case, when testing the popped value, use the
	expr_result's const_value explicitly.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-dwarf-reader.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Dodji Seketeli Jan. 9, 2023, 4:03 p.m. UTC | #1
Hello Giuliano,

First of all, Happy New Year to you and your beloved ones!

Giuliano Procida <gprocida@google.com> a écrit:

> C++20 automatically generates overloads for certain comparison
> operators based on others and this can create ambiguity with older
> code. The type expr_result has various operators defined and comparing
> expr_result != int becomes ambiguous.
>
> This change just avoids this comparison by extracting the underlying
> value, rather than making changes to the type itself. There should be
> no change in behaviour and no tests are affected.
>
> 	* (src/abg-dwarf-reader.cc) op_is_control_flow: In the
> 	DW_OP_bra case, when testing the popped value, use the
> 	expr_result's const_value explicitly.
>
> Signed-off-by: Giuliano Procida <gprocida@google.com>

Applied to the master branch, thanks!

[...]

Cheers,
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index e3a1348d..ce6b52d4 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -8279,7 +8279,7 @@  op_is_control_flow(Dwarf_Op* expr,
 
     case DW_OP_bra:
       val1 = ctxt.pop();
-      if (val1 != 0)
+      if (val1.const_value() != 0)
 	index += val1.const_value() - 1;
       break;