Pointer to array template parameter in partial specialization

O

Oskar Enoksson

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
 
V

Victor Bazarov

Oskar said:
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
 
G

Gianni Mariani

Oskar said:
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 ?
 
V

Victor Bazarov

Gianni said:
Oskar said:
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
 
G

Gianni Mariani

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.
 
V

Victor Bazarov

Gianni said:
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
 
O

Oskar Enoksson

Victor said:
Gianni said:
Oskar said:
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?
 
G

Gianni Mariani

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 ?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top