Can a successfully compileable template definition fail on instantiation?

Discussion in 'C++' started by David, May 13, 2004.

  1. David

    David Guest

    Assuming of course that the instantiation statement is 100% ok.
    As a matter of fact, that very instantiation passes successfuly on VC++ 7.1
    (and Borland) but since I was suspicious that it was OK there "more by luck
    than brain", I checked the same on Linux\GNU were the instantiation failed.

    This question is more for people who know well the C++ ISO standard, the
    chapter on templates. My hunch is that the problem is with the language spec.

    Thanks
     
    David, May 13, 2004
    #1
    1. Advertising

  2. David wrote:
    > Assuming of course that the instantiation statement is 100% ok.
    > As a matter of fact, that very instantiation passes successfuly on

    VC++ 7.1
    > (and Borland) but since I was suspicious that it was OK there "more by

    luck
    > than brain", I checked the same on Linux\GNU were the instantiation

    failed.
    >
    > This question is more for people who know well the C++ ISO standard, the
    > chapter on templates. My hunch is that the problem is with the

    language spec.

    Why don't you just post some minimal piece of code that reproduces the
    problem?

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, May 13, 2004
    #2
    1. Advertising

  3. (David) wrote in message news:<>...
    > Assuming of course that the instantiation statement is 100% ok.
    > As a matter of fact, that very instantiation passes successfuly on VC++ 7.1
    > (and Borland) but since I was suspicious that it was OK there "more by luck
    > than brain", I checked the same on Linux\GNU were the instantiation failed.


    Yes, and this is in fact a very common technique. For instance,
    std::vector<T>::vector( size_type, T const& = T(), {default allocator} )

    It is impossible to instantiate this member when only the size_type
    argument is provided and T doesn't have an accessible default ctor.

    Basically templates compile if there is at least one set of arguments
    for which they can be instantiated. The reverse is not true; some
    errors are too hard to detect without instantiating.

    E.g. a template with unsigned integer parameters A,B,C and N that
    could only compile if A^(N+3)+B^(N+3)==C^(N+3). A compiler may
    reject this, because there is no set of arguments for which this holds
    but it isn't required to be aware of the proof to Fermats theorem.
    It may instead reject every attempt to instantiate.

    Regards,
    Michiel Salters
     
    Michiel Salters, May 13, 2004
    #3
    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. Fernando Cuenca
    Replies:
    4
    Views:
    2,537
    Gianni Mariani
    Sep 6, 2004
  2. ES Kim
    Replies:
    4
    Views:
    356
    ES Kim
    Apr 15, 2005
  3. Replies:
    1
    Views:
    587
    Salt_Peter
    Dec 25, 2006
  4. Pierre Yves
    Replies:
    2
    Views:
    499
    Pierre Yves
    Jan 10, 2008
  5. Alessandro [AkiRoss] Re
    Replies:
    3
    Views:
    453
    Michael Doubez
    May 13, 2009
Loading...

Share This Page