www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2469] New: arbitrary struct accepted as struct initializer

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469

           Summary: arbitrary struct accepted as struct initializer
           Product: D
           Version: 1.035
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: kamm-removethis incasoftware.de


The following code compiles

struct Foo { double d; }
struct Bar { byte b; }
void main() { Foo foo; Bar bar = foo; }

even though Foo is not implicitly convertible to Bar. In contrast, assigning

Foo foo;
Bar bar;
bar = foo;

fails as expected.


-- 
Nov 23 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469


Christian Kamm <kamm-removethis incasoftware.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jarrett.billingsley gmail.c
                   |                            |om





2009-06-17 23:19:21 PDT ---
*** Issue 3076 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469


Christian Kamm <kamm-removethis incasoftware.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code





2009-06-17 23:20:41 PDT ---
Jarett found this pretty ICE in ztc\cod1.c:1673:

This can lead to the ICE mentioned in the description, if the source type is
smaller than the destination, at least for some values of "smaller," *and* the
source is a function call.  The following, for instance, causes it:

struct Small { uint x; }
struct Large { uint x, y, z; }
Small foo() { return Small(); }
void main() { Large l = foo(); } // bang!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469






2009-06-18 06:45:55 PDT ---
Ah poop.  I was searching for ICEs and never even came across this one :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 18 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469






PDT ---
possibly related to bug 3036.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 23 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469


Jarrett Billingsley <jarrett.billingsley gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rayerd.wiz gmail.com





2009-07-30 08:42:40 PDT ---
*** Issue 3216 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 30 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469






There are two completely different bugs in this report. One is the implicit
conversion one, which is a bad code generation bug.

The ICE is actually a quite different bug. Here's a test case which doesn't
involve the initialisation bug.

struct Small { uint x; }
struct Large { uint x, y, z; }
Small foo() { return Small(); }
void main() { 
  Large l; Small s; 
  l = cast(Large)foo();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 07 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxmo pochta.ru





*** Issue 3036 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 07 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469






There's a patch for the original bug in bug 2702. It's unrelated to the ICE.
(It's really annoying when new bugs are reported in the comments for existing
bugs, it's not clear what to do with them).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 08 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469






2009-09-03 09:48:19 PDT ---
*** Issue 3287 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
         OS/Version|Linux                       |All



The root cause is that all kinds of nonsense is allowed in struct casts.
Explicit struct casts only make sense when the source and destination are of
the same size.

Patch against DMD 2.032.

Index: cast.c
===================================================================
--- cast.c    (revision 196)
+++ cast.c    (working copy)
   -822,6 +822,15   
             return e;
         }
         }
+        // Struct casts are possible only when the sizes match
+        if (typeb->ty==Tstruct || tb->ty==Tstruct) {
+        size_t fromsize = tb->size(loc);
+        size_t tosize = typeb->size(loc);
+        if (fromsize !=tosize) {
+            error("Cannot cast from %s to %s", type->toChars(), t->toChars());
+            return this;
+        }
+        }
         e = new CastExp(loc, e, tb);
     }
     }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2469


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



02:14:23 PDT ---
Fixed dmd 1.048 and 2.033

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 06 2009