Fix compile-cplus-types.c build errors

Message ID 1535640184-20543-1-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi Aug. 30, 2018, 2:43 p.m. UTC
  I see these errors when building with clang:

  CXX    compile/compile-cplus-types.o
/home/emaisin/src/binutils-gdb/gdb/compile/compile-cplus-types.c:262:61: error: cannot pass non-trivial object of type 'compile_scope' to variadic function; expected type from format string was 'void *' [-Wnon-pod-varargs]
        fprintf_unfiltered (gdb_stdlog, "entering new scope %p\n", new_scope);
                                                            ~~     ^~~~~~~~~
/home/emaisin/src/binutils-gdb/gdb/compile/compile-cplus-types.c:306:56: error: cannot pass non-trivial object of type 'compile_scope' to variadic function; expected type from format string was 'void *' [-Wnon-pod-varargs]
        fprintf_unfiltered (gdb_stdlog, "leaving scope %p\n", current);
                                                       ~~     ^~~~~~~
/home/emaisin/src/binutils-gdb/gdb/compile/compile-cplus-types.c:1058:13: error: comparison of two values with different enumeration types ('enum_flags<gcc_cp_qualifiers>::enum_type' (aka 'gcc_cp_qualifiers') and 'gcc_cp_ref_qualifiers') [-Werror,-Wenum-compare]
  if (quals != GCC_CP_REF_QUAL_NONE)
      ~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~

Fix the first two by taking the address of the object.

Fix the third one by comparing to 0 instead.  I think the current
comparison simply uses the wrong enum type.  Comparing to 0 seems like
the right thing to do, because we want to check whether any flags are
specified.

gdb/ChangeLog:

	* compile/compile-cplus-types.c
	(compile_cplus_instance::enter_scope): Take the address of scope
	object.
	(compile_cplus_instance::leave_scope): Likewise.
	(compile_cplus_instance::convert_qualified_base): Compare quals
	to 0.
---
 gdb/compile/compile-cplus-types.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Joel Brobecker Aug. 30, 2018, 3:04 p.m. UTC | #1
Hi Simon,

> gdb/ChangeLog:
> 
> 	* compile/compile-cplus-types.c
> 	(compile_cplus_instance::enter_scope): Take the address of scope
> 	object.
> 	(compile_cplus_instance::leave_scope): Likewise.
> 	(compile_cplus_instance::convert_qualified_base): Compare quals
> 	to 0.
[...]
> diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
> index 9425fc6..844c8ce 100644
> --- a/gdb/compile/compile-cplus-types.c
> +++ b/gdb/compile/compile-cplus-types.c
> @@ -259,7 +259,7 @@ compile_cplus_instance::enter_scope (compile_scope &new_scope)
>    if (must_push)
>      {
>        if (debug_compile_cplus_scopes)
> -	fprintf_unfiltered (gdb_stdlog, "entering new scope %p\n", new_scope);
> +	fprintf_unfiltered (gdb_stdlog, "entering new scope %p\n", &new_scope);

While at it, can you change the use of %p by using %s combined with
host_address_to_string? Using %p triggers an ARI warning.

> @@ -1055,7 +1055,7 @@ compile_cplus_instance::convert_qualified_base (gcc_type base,
>  {
>    gcc_type result = base;
>  
> -  if (quals != GCC_CP_REF_QUAL_NONE)
> +  if (quals != 0)
>      result = plugin ().build_qualified_type (base, quals);
>  
>    return result;
> -- 
> 2.7.4
  
Tom Tromey Aug. 30, 2018, 3:06 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> writes:

Simon> Fix the third one by comparing to 0 instead.  I think the current
Simon> comparison simply uses the wrong enum type.  Comparing to 0 seems like
Simon> the right thing to do, because we want to check whether any flags are
Simon> specified.

I think this is fine, but at the same time, it seems reasonable to me to
want to compare an enum flags object against an enumerator from the
underlying type.  So maybe enum_flags should have operator== and operator!=.

What do you think of this?  I am trying to think of a counter-example
where this would cause problems.

Simon> 	* compile/compile-cplus-types.c
Simon> 	(compile_cplus_instance::enter_scope): Take the address of scope
Simon> 	object.
Simon> 	(compile_cplus_instance::leave_scope): Likewise.
Simon> 	(compile_cplus_instance::convert_qualified_base): Compare quals
Simon> 	to 0.

Looks good.

Tom
  

Patch

diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 9425fc6..844c8ce 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -259,7 +259,7 @@  compile_cplus_instance::enter_scope (compile_scope &new_scope)
   if (must_push)
     {
       if (debug_compile_cplus_scopes)
-	fprintf_unfiltered (gdb_stdlog, "entering new scope %p\n", new_scope);
+	fprintf_unfiltered (gdb_stdlog, "entering new scope %p\n", &new_scope);
 
       /* Push the global namespace. */
       plugin ().push_namespace ("");
@@ -303,7 +303,7 @@  compile_cplus_instance::leave_scope ()
   if (current.m_pushed)
     {
       if (debug_compile_cplus_scopes)
-	fprintf_unfiltered (gdb_stdlog, "leaving scope %p\n", current);
+	fprintf_unfiltered (gdb_stdlog, "leaving scope %p\n", &current);
 
       /* Pop namespaces.  */
       std::for_each
@@ -1055,7 +1055,7 @@  compile_cplus_instance::convert_qualified_base (gcc_type base,
 {
   gcc_type result = base;
 
-  if (quals != GCC_CP_REF_QUAL_NONE)
+  if (quals != 0)
     result = plugin ().build_qualified_type (base, quals);
 
   return result;