https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89004

            Bug ID: 89004
           Summary: mtype.c:2329:33: error: comparison of integer
                    expressions of different signedness: ‘int’ and
                    ‘size_t’ {aka ‘long unsigned int’}
                    [-Werror=sign-compare]
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: marxin at gcc dot gnu.org
  Target Milestone: ---

Started with merge from upstream dmd r268124. Full warning:

In file included from ../../gcc/d/d-system.h:23,
                 from ../../gcc/d/dmd/root/dsystem.h:24,
                 from ../../gcc/d/dmd/mtype.c:11:
../../gcc/d/dmd/mtype.c: In member function ‘Identifier*
Type::getTypeInfoIdent()’:
../../gcc/d/dmd/mtype.c:2329:33: error: comparison of integer expressions of
different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
[-Werror=sign-compare]
 2329 |     assert(0 < length && length < namelen);     // don't overflow the
buffer
      |                          ~~~~~~~^~~~~~~~~
../../gcc/system.h:742:14: note: in definition of macro ‘gcc_assert’
  742 |    ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0
: 0))
      |              ^~~~
../../gcc/d/dmd/mtype.c:2329:5: note: in expansion of macro ‘assert’
 2329 |     assert(0 < length && length < namelen);     // don't overflow the
buffer
      |     ^~~~~~

Patch candidate:
diff --git a/gcc/d/dmd/mtype.c b/gcc/d/dmd/mtype.c
index 09161a313ee..2a23cab74fd 100644
--- a/gcc/d/dmd/mtype.c
+++ b/gcc/d/dmd/mtype.c
@@ -2326,7 +2326,7 @@ Identifier *Type::getTypeInfoIdent()

     int length = sprintf(name, "_D%lluTypeInfo_%s6__initZ", (unsigned long
long) 9 + len, buf.data);
     //printf("%p, deco = %s, name = %s\n", this, deco, name);
-    assert(0 < length && length < namelen);     // don't overflow the buffer
+    assert(0 < length && (size_t)length < namelen);     // don't overflow the
buffer

     Identifier *id = Identifier::idPool(name, length);

Reply via email to