www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1059] New: String literal concatenated with array of chars - inconsistent behavior

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

           Summary: String literal concatenated with array of chars -
                    inconsistent behavior
           Product: D
           Version: 1.009
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: gavrilyak gmail.com


char[] hi1 = "h" ~ "i";   //works
  char[] hi1 = "h" ~ ['i'];   //works
  char[] hi2 =  ['h'] ~ "i";  // semicolon expected, not '~'
                              //found '~' instead of statement
  char[] hi3 =  ['h'] ~ ['i'];// semicolon expected, not '~'
                              //found '~' instead of statement

All 4 case means the same and should behave the same way.


-- 
Mar 13 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1059






Update:
This issue occurs only in initialization, normal assignment works.
  char[] hi = "h" ~ "i";   //works
  char[] hi1 = "h" ~ ['i'];   //works
  char[] hi2 =  ['h'] ~ "i";  // semicolon expected, not '~'
                              //found '~' instead of statement
  char[] hi3 =  ['h'] ~ ['i'];// semicolon expected, not '~'
                              //found '~' instead of statement

  hi1 =  "h" ~ ['i'];   //works
  hi1 =  ['h'] ~ "i";   //works
  hi1 =  ['h'] ~ ['i']; //works


-- 
Mar 13 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1059


matti.niemenmaa+dbugzilla iki.fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matti.niemenmaa+dbugzilla ik
                   |                            |i.fi
           Severity|minor                       |normal
         OS/Version|Linux                       |All
           Platform|PC                          |All





-------
Annoying because this limits the use of array literals in templates, A doesn't
compile in the following:

//template A(char   a, char   b) { const char[] A = [a] ~ [b]; }
template B(char[] a, char[] b) { const char[] B =  a  ~  b ; }

void main() {
//      static assert (A!('a', 'b') == "ab");
        static assert (B!("a", "b") == "ab");
        static assert (['a'] ~ ['b'] == "ab");
}


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






-------
The template issue can be worked around as well, replace [a,b,...] with
(cast(typeof(a))[] ~ a ~ b ~ ...):

template A(char a, char b) { const char[] A = cast(char[])[] ~ a ~ b; }


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






-------
This one I haven't found a workaround for:

template Id(char[] s) { const Id = s; }

// succeed
static assert (Id!("x" ~ "y")     == "xy");
static assert (Id!(['x'] ~ ['y']) == "xy");

// fail
static assert (Id!("x" ~ ['y'])   == "xy");
static assert (Id!(['x'] ~ "y")   == "xy");

The second two give errors of the form:

asdf.d(7): Error: expression "x" ~ ['y'] is not a valid template value argument
asdf.d(7): template instance asdf.Id!("x" ~ ['y']) error instantiating
asdf.d(7): static assert  ("x" ~ ['y'] == "xy") is not evaluatable at compile
time


-- 
Aug 23 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1059


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |FIXED



These cases work in the current compilers. (dmd1.068 & dmd2.053)

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