www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2706] New: invalid template instantiation (and declaration?) is not rejected

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

           Summary: invalid template instantiation (and declaration?) is not
                    rejected
           Product: D
           Version: 1.033
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: tomas famolsen.dk


The following code doesn't make sense to me, yet DMD accepts it:

module k;

enum TYP { ch, c }

class TypeBasic {
  int oo;
  /// Allocates an instance of TypeBasic and assigns it to typeName.
  template newTB(char[] typeName)
  {
    const newTB = mixin("new TypeBasic(TYP."~typeName~")");
  }

  /// Initializes predefined types.
  static this()
  {
    newTB!("c");
    newTB!("ch");
  }
  this(int inp)
  {
  oo=inp;
  }
}

void main()
{
}



I got this from a LDC bug report in IRC, and TBH I can't think anything but WTF
is going on here? DMD seems to emit two 'new' expressions in the static ctor.

I would think it should be:

error: 'new TypeBasic(TYP.c)' is not a constant expression


-- 
Mar 02 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2706





------- Comment #1 from tomas famolsen.dk  2009-03-02 22:37 -------
Anoter test case:

template newTB(char[] a, char[] b)
{
    const newTB = mixin(a~"+"~b);
}

void main()
{
    int a, b;
    auto c = newTB!("a", "b");
}


Here the bogus error message:

Error: Array operations not implemented

is produced when it should be:

Error: a + b is not a constant expression.

or am I completely off here ?


-- 
Mar 02 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2706





------- Comment #2 from tomas famolsen.dk  2009-03-02 22:45 -------
Ok the second one makes a little sense. but what about this one:

template newTB(char[] c, char[] d)
{
    const newTB = mixin(c~"+"~d);
}

int a=1, b=2;

void main()
{
    auto c = newTB!("a", "b");
    printf("%d\n", c);
    a = 4;
    b = 6;
    c = newTB!("a", "b");
    printf("%d\n", c);
}

extern(C) int printf(char*, ...);

/*
[tomas myhost tests]$ dmd bar.d
[tomas myhost tests]$ ./bar
3
10
*/

?


-- 
Mar 02 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2706


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #3 from Don <clugdbug yahoo.com.au> 2011-04-14 15:31:39 PDT ---
Updated test case for D2.052:
template newTB(string c, string d)
{
    enum newTB = mixin(c~"+"~d);
}

int a=1, b=2;

void main()
{
    auto c = newTB!("a", "b");
    a = 4;
    b = 6;
    c = newTB!("a", "b");
}

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