Thread overview
[Issue 8231] New: conv.to fails to convert string with trailing "u"
Jun 12, 2012
Andrej Mitrovic
Jun 17, 2013
John Colvin
June 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8231

           Summary: conv.to fails to convert string with trailing "u"
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-06-11 18:36:57 PDT ---
import std.conv;

void main()
{
    uint x = 3u;  // ok
    uint y = to!uint("3u");  // fail
}

std.conv.ConvException@D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(1597): Unexpected 'u' when converting from type string to type uint

If it can be used in D syntax it should be convertible by conv.to.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8231



--- Comment #1 from github-bugzilla@puremagic.com 2012-07-01 22:13:53 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/9f5c180b667faa512dac2e01dff19490688c07ac Disable test for bug 8231 temporarily.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 17, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8231


John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.loughran.colvin@gmail.
                   |                            |com


--- Comment #2 from John Colvin <john.loughran.colvin@gmail.com> 2013-06-17 23:21:56 BST ---
This is quite easily fixed with a little utility function that checks if the remainder after parsing is a floating point or integer suffix.

However, it is potentially a nasty subtle breaking change as it's quite a common pattern to rely on functions like "to" to check for unusual input, which this would change the definition of. It also introduces a difference in attitude between "to" and "parse", which currently work together very neatly.

On those grounds, I'm against it.

To be acceptable it would have to be enabled with a template argument (an enum with names RAW and D_LITERAL_AWARE ?), or be in a function with a different name.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 17, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8231


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from bearophile_hugs@eml.cc 2013-06-17 15:39:28 PDT ---
Both converting regular numbers and converting D literals to their values are important needs and use cases, but mixing them transparently is probably a not so good idea.

So better to give it a different function name or to add some compile-time argument to tell apart the two cases, as Comment #2 says.

D number literals also allow underscores: 1_000_000u

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