legal code?

Discussion in 'C++' started by Noah Roberts, Dec 10, 2008.

  1. Noah Roberts

    Noah Roberts Guest

    Someone in another list posted this code. It compiles in G++ and
    apparently is absorbed by comeau as well. VS vomits.

    #include <cstddef>

    template < typename T, std :: size_t sz >
    struct Block
    {
    typedef T type[ sz ][ sz ];
    };

    template < typename T >
    void assign( T & assignee, const T & value )
    {}

    template < typename T, std :: size_t sz >
    void assign( T ( & assignee )[ sz ], const T ( & value )[ sz ] )
    {}

    int main( )
    {
    Block< int, 16 > :: type a;
    const Block< int, 16 > :: type b = { };

    assign( a, b );
    }


    1>e:\dev_workspace\experimental\boost_msg_test\boost_msg_test\boost_msg_test.cpp(22)
    : error C2782: 'void assign(T (&)[sz],const T (&)[sz])' : template
    parameter 'T' is ambiguous
    1>
    e:\dev_workspace\experimental\boost_msg_test\boost_msg_test\boost_msg_test.cpp(14)
    : see declaration of 'assign'
    1> could be 'const int [16]'
    1> or 'int [16]'
    1>e:\dev_workspace\experimental\boost_msg_test\boost_msg_test\boost_msg_test.cpp(22)
    : error C2782: 'void assign(T &,const T &)' : template parameter 'T' is
    ambiguous
    1>
    e:\dev_workspace\experimental\boost_msg_test\boost_msg_test\boost_msg_test.cpp(10)
    : see declaration of 'assign'
    1> could be 'const int [16][16]'
    1> or 'int [16][16]'


    G++ compiles and calls the T[] version.
     
    Noah Roberts, Dec 10, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Johnson
    Replies:
    3
    Views:
    479
    C Johnson
    Aug 14, 2003
  2. SenderX
    Replies:
    7
    Views:
    380
    Greg Comeau
    Aug 29, 2003
  3. Ed J

    Is this legal code?

    Ed J, Jun 16, 2004, in forum: C++
    Replies:
    3
    Views:
    556
  4. Jim Ford

    Is this legal C code?

    Jim Ford, Jan 26, 2004, in forum: C Programming
    Replies:
    7
    Views:
    359
    James Hu
    Jan 28, 2004
  5. Ancient_Hacker

    Weird bit of code-- legal???

    Ancient_Hacker, Sep 13, 2006, in forum: C Programming
    Replies:
    29
    Views:
    591
    jaysome
    Sep 15, 2006
Loading...

Share This Page