[Bug 93] Template regex example fails without -release switch

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 12 19:11:00 PDT 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=93


godaves at yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |trivial
           Priority|P2                          |P5




------- Comment #4 from godaves at yahoo.com  2006-04-12 21:10 -------
(In reply to comment #3)
> I've tried to reproduce this on Windows with DMD 0.153. It always compiles for
> me.
> I also don't understand the reference to Contract Programming in message #3
> (there's no contract programming in this code).
>

The linker error happens because of array bounds checking code that is omitted
with -release. I recreated it, but it is arguably my mistake (read on).

I copied the code into two files, test_regex.d and temp_regex.d.

Then I recompiled:

C:\Zz\temp>dmd test_regex.d
C:\dmd\bin\..\..\dm\bin\link.exe test_regex,,,user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

test_regex.obj(test_regex)
 Error 42: Symbol Undefined _array_10temp_regex
--- errorlevel 1

Then I recompiled again with -release and ran it:

C:\Zz\temp>dmd test_regex.d -release
C:\dmd\bin\..\..\dm\bin\link.exe test_regex,,,user32+kernel32/noi;

C:\Zz\temp>test_regex
matches: [hello]

That recreates the problem, and I should have specified the exact steps better.

But, if I recompile w/o -release like so:

C:\Zz\temp>dmd test_regex.d temp_regex.d
C:\dmd\bin\..\..\dm\bin\link.exe test_regex+temp_regex,,,user32+kernel32/noi;

C:\Zz\temp>test_regex
matches: [hello]

Then it works. The reason I didn't compile in temp_regex.d (or link in the .obj
compiled separately) is because the code in tempregex.d is all of either const
or template code. Being used to C/++ #include <header>, I just compiled the
main() module.

So under normal circumstances (e.g. the regex code is linked into a lib and
that lib is linked with the app.) this 'bug' would probably not have happened,
so along with the other things you pointed out, I lowered the Severity for it
to 'trivial' and priority to 'informational'.

This is a potentially frustrating inconsistency between the compiler switches
because, as the templates are always instantiated in the declaritive scope, the
compiler generated stuff is (correctly) generated for the same scope. I say
potentially frustrating because sometimes compiler generated stuff is "out of
sight, out of mind", at least for me.

Walter probably spotted this right away from the linker error and just ignored
it or sat back and chuckled as the e-mails went back and forth <g>

(The reference to contract programming is because the -release switch omits pre
and post contracts, along with asserts, invariants, etc. So, what I was
referring to is that if you ran into this bug, then in order to get it to
compile the -release switch would remove your CP code, hence "blocker").

Thanks,

- Dave


-- 




More information about the Digitalmars-d-bugs mailing list