Pointer to array template parameter in partial specialization

Discussion in 'C++' started by Oskar Enoksson, Feb 21, 2007.

  1. The following template specialization construct is rejected by g++ 4.1.2
    while icc 9.1 silently accepts is (even with -strict-ansi). Which
    compiler is correct?



    template<typename T>
    struct x {};

    template<typename T, unsigned N>
    struct x<T*[N]> {};

    int main() {
    x<int> a;
    x<int*[10]> b;
    return 0;
    }



    bash> g++-4.1.2 -c tst.cpp
    tst.cpp:7: error: template parameters not used in partial specialization:
    tst.cpp:7: error: ‘T’

    bash> icc -strict-ansi -o tst tstst.cpp
    bash>


    thanks
    /Oskar
     
    Oskar Enoksson, Feb 21, 2007
    #1
    1. Advertising

  2. Oskar Enoksson wrote:
    > The following template specialization construct is rejected by g++
    > 4.1.2 while icc 9.1 silently accepts is (even with -strict-ansi).
    > Which compiler is correct?


    I wanted to say that the code was fine, but went to check with Comeau
    online, and it confirmed that -- the code is accepted.

    >
    > template<typename T>
    > struct x {};
    >
    > template<typename T, unsigned N>
    > struct x<T*[N]> {};
    >
    > int main() {
    > x<int> a;
    > x<int*[10]> b;
    > return 0;
    > }
    >
    >
    >
    > bash> g++-4.1.2 -c tst.cpp
    > tst.cpp:7: error: template parameters not used in partial
    > specialization: tst.cpp:7: error: ‘T’
    >
    > bash> icc -strict-ansi -o tst tstst.cpp
    > bash>


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Feb 21, 2007
    #2
    1. Advertising

  3. Oskar Enoksson wrote:
    > The following template specialization construct is rejected by g++ 4.1.2
    > while icc 9.1 silently accepts is (even with -strict-ansi). Which
    > compiler is correct?
    >
    >
    >
    > template<typename T>
    > struct x {};
    >
    > template<typename T, unsigned N>
    > struct x<T*[N]> {};
    >
    > int main() {
    > x<int> a;
    > x<int*[10]> b;
    > return 0;
    > }
    >
    >
    >
    > bash> g++-4.1.2 -c tst.cpp
    > tst.cpp:7: error: template parameters not used in partial specialization:
    > tst.cpp:7: error: ‘T’



    Looks like a serious gcc bug to me.


    Did you file it with the gcc people ?
     
    Gianni Mariani, Feb 21, 2007
    #3
  4. Gianni Mariani wrote:
    > Oskar Enoksson wrote:
    >> The following template specialization construct is rejected by g++
    >> 4.1.2 while icc 9.1 silently accepts is (even with -strict-ansi).
    >> Which compiler is correct?
    >>
    >>
    >>
    >> template<typename T>
    >> struct x {};
    >>
    >> template<typename T, unsigned N>
    >> struct x<T*[N]> {};
    >>
    >> int main() {
    >> x<int> a;
    >> x<int*[10]> b;
    >> return 0;
    >> }
    >>
    >>
    >>
    >> bash> g++-4.1.2 -c tst.cpp
    >> tst.cpp:7: error: template parameters not used in partial
    >> specialization: tst.cpp:7: error: 'T'

    >
    >
    > Looks like a serious gcc bug to me.
    >
    >
    > Did you file it with the gcc people ?


    Oh, and I just noticed (and read carefully) the subject of your
    message, Oskar, and wanted to tell you that

    T*[N]

    is NOT a pointer to array, but rather an array of pointers to T.
    A pointer to an array would be

    T(*)[N]

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Feb 21, 2007
    #4
  5. Victor Bazarov wrote:
    ....
    > is NOT a pointer to array, but rather an array of pointers to T.
    > A pointer to an array would be
    >
    > T(*)[N]


    gcc accepts that type parameter for X. It's still a bug for gcc however.
     
    Gianni Mariani, Feb 21, 2007
    #5
  6. Gianni Mariani wrote:
    > Victor Bazarov wrote:
    > ...
    >> is NOT a pointer to array, but rather an array of pointers to T.
    >> A pointer to an array would be
    >>
    >> T(*)[N]

    >
    > gcc accepts that type parameter for X. It's still a bug for gcc
    > however.


    :) I wasn't arguing that it wasn't a bug...

    V
     
    Victor Bazarov, Feb 21, 2007
    #6
  7. Victor Bazarov wrote:
    > Gianni Mariani wrote:
    >> Oskar Enoksson wrote:
    >>> The following template specialization construct is rejected by g++
    >>> 4.1.2 while icc 9.1 silently accepts is (even with -strict-ansi).
    >>> Which compiler is correct?
    >>>
    >>>
    >>>
    >>> template<typename T>
    >>> struct x {};
    >>>
    >>> template<typename T, unsigned N>
    >>> struct x<T*[N]> {};
    >>>
    >>> int main() {
    >>> x<int> a;
    >>> x<int*[10]> b;
    >>> return 0;
    >>> }
    >>>
    >>>
    >>>
    >>> bash> g++-4.1.2 -c tst.cpp
    >>> tst.cpp:7: error: template parameters not used in partial
    >>> specialization: tst.cpp:7: error: 'T'

    >>
    >> Looks like a serious gcc bug to me.
    >>
    >>
    >> Did you file it with the gcc people ?

    >
    > Oh, and I just noticed (and read carefully) the subject of your
    > message, Oskar, and wanted to tell you that
    >
    > T*[N]
    >
    > is NOT a pointer to array, but rather an array of pointers to T.
    > A pointer to an array would be
    >
    > T(*)[N]
    >
    > V


    Yes ok thanks. This bug surprised me - it's a simple construct. I
    thought g++ was pretty stable.

    I've created a bug report on the gcc bugzilla site.

    BTW Bugzilla crashed when creating the bug report, so I also reported a
    bugzilla bug to the bugzilla maintainers in an email. If this email
    bounces I give up. Am I just unlucky or is the free software
    infrastructure deteriorating?
     
    Oskar Enoksson, Feb 22, 2007
    #7
  8. Oskar Enoksson wrote:
    ....
    > BTW Bugzilla crashed when creating the bug report, so I also reported a
    > bugzilla bug to the bugzilla maintainers in an email. If this email
    > bounces I give up. Am I just unlucky or is the free software
    > infrastructure deteriorating?


    This could be a regression in the gcc 4.X series. The gcc 3.4.4
    compiler seems to work with this.

    If it was a heavily used construct, it would have been fixed already.
    However, I was a little surprised.

    BTW - what's the bug ID ?
     
    Gianni Mariani, Feb 22, 2007
    #8
  9. Gianni Mariani wrote:
    > Oskar Enoksson wrote:
    > ...
    >> BTW Bugzilla crashed when creating the bug report, so I also reported
    >> a bugzilla bug to the bugzilla maintainers in an email. If this email
    >> bounces I give up. Am I just unlucky or is the free software
    >> infrastructure deteriorating?

    >
    > This could be a regression in the gcc 4.X series. The gcc 3.4.4
    > compiler seems to work with this.
    >
    > If it was a heavily used construct, it would have been fixed already.
    > However, I was a little surprised.
    >
    > BTW - what's the bug ID ?


    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30924

    /Oskar
     
    Oskar Enoksson, Feb 22, 2007
    #9
    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. toton
    Replies:
    1
    Views:
    627
  2. mliptak
    Replies:
    3
    Views:
    353
    mliptak
    Mar 21, 2007
  3. flopbucket
    Replies:
    5
    Views:
    519
    Greg Herlihy
    May 15, 2008
  4. vj
    Replies:
    1
    Views:
    501
  5. Hizo
    Replies:
    17
    Views:
    711
    itaj sherman
    Mar 7, 2011
Loading...

Share This Page