473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Pointer to array template parameter in partial specialization

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<inta;
x<int*[10]b;
return 0;
}

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

bashicc -strict-ansi -o tst tstst.cpp
bash>
thanks
/Oskar
Feb 21 '07 #1
8 3072
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<inta;
x<int*[10]b;
return 0;
}

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

bashicc -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
Feb 21 '07 #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?

template<typename T>
struct x {};

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

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

bashg++-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 ?
Feb 21 '07 #3
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<inta;
x<int*[10]b;
return 0;
}

bashg++-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
Feb 21 '07 #4
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.
Feb 21 '07 #5
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
Feb 21 '07 #6
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<inta;
x<int*[10]b;
return 0;
}

bashg++-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?
Feb 22 '07 #7
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 ?
Feb 22 '07 #8
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
Feb 22 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; ...
1
by: BekTek | last post by:
I'm still confused about the template partial specialization which is used in many libraries.. due to lack of introduction for beginner.. Could you tell me about that in short? Thanks in...
13
by: Imre | last post by:
Please take a look at the following code: template <typename T, typename Enable = void> class A { public: enum { value = 0 }; }; template <typename T>
2
by: Michael Stembera | last post by:
Here is a very simple piece of code to repro this bug. template<typename T, int N> inline bool foo( void ) { return true; } template<typename T> inline bool foo<T, 1>( void ) { return...
2
by: lhr_cool_guy | last post by:
C++ doesn't allow partial specialization of function templates. I want to know why this is so? Is the concept of function template partial specialization not well defined? I have a case where I...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
6
by: Andre Kempe | last post by:
hej folks. i have a heap with fixed size and want to determine the depth of a element with given index at compile-time. therefore i wrote some templates. however, when i use template...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.