473,396 Members | 2,029 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.

SFINAE -- basis: array of void is invalid type

The problem brought by one earlier post from comp.lang.c++
http://groups.google.com/group/comp....636c48b84957b/

I take part of the question and reproduce the code to represent (partly)
the question.

#include <iostream>

template <class>
void f(...)
{
std::cout << "..." << std::endl;
}

template <class T>
void f(T[1])
{
std::cout << "T" << std::endl;
}

int main()
{
f<int>(0);
f<void>(0);
}
as "array of void" is invalid type, so the f<voidshould applies SFINAE
and chooses the "f(...)" version

the code above compiles and runs _expectedly_ with VC8
but fails to compile with Comuea Online, producing the error message:

"ComeauTest.c", line 10: error: array of void is not allowed
void f(T[1])
^
detected during instantiation of "f" based on template argument
<voidat line 18

compiles with gcc 4.3.0 but produced unexpected result, producing
T
T
which means that f<int>, f<voidboth chooses the second version.

so who's right about this?

one more question:
should

8.3.5.3 [...] The type of a function is determined using the
following rules. The type of each parameter is determined from its own
decl-specifier-seq and declarator. After determining the type of each
parameter, any parameter of type “array of T” or “function returning
T” is adjusted to be “pointer to T” or “pointer to function returning
T,” respectively.
[...]

the adjustment apply before SFINAE happens?
I guess GCC4.3.0 gives an "yes" answer.
--
Best Regards
Barry
Jun 27 '08 #1
2 2445
On 29 mai, 08:36, Barry <dhb2...@gmail.comwrote:
The problem brought by one earlier post from comp.lang.c++http://groups.google.com/group/comp....ead/thread/bf6...

I take part of the question and reproduce the code to represent (partly)
the question.

#include <iostream>

template <class>
void f(...)
{
* *std::cout << "..." << std::endl;

}

template <class T>
void f(T[1])
{
* *std::cout << "T" << std::endl;

}

int main()
{
* *f<int>(0);
* *f<void>(0);

}

as "array of void" is invalid type, so the f<voidshould applies SFINAE
and chooses the "f(...)" version

the code above compiles and runs _expectedly_ with VC8
but fails to compile with Comuea Online, producing the error message:

"ComeauTest.c", line 10: error: array of void is not allowed
* *void f(T[1])
* * * * * *^
* * * * * *detected during instantiation of "f" based on template argument
* * * * * * * * * * *<voidat line 18

compiles with gcc 4.3.0 but produced unexpected result, producing
T
T
which means that f<int>, f<voidboth chooses the second version.

so who's right about this?
I guess VC8 is right.

SFINAE comes when type deduction fails, which can happen in the
following context :

14.8.2.2 :

"When an explicit template argument list is specified, the template
arguments must be compatible with the template parameter list and must
result in a valid function type as described below; otherwise type
deduction fails. Specifically, [...] Type deduction may fail for the
following reasons:
Attempting to create an array with an element type that is void"
one more question:
should

8.3.5.3 [...] The type of a function is determined using the
following rules. The type of each parameter is determined from its own
decl-specifier-seq and declarator. After determining the type of each
parameter, any parameter of type array of T or function returning
T is adjusted to be pointer to T or pointer to function returning
T, respectively.
[...]

the adjustment apply before SFINAE happens?
I guess GCC4.3.0 gives an "yes" answer.

Such adjustement is applied after SFINAE.

14.8.2.3 :

"After this substitution is performed, the function parameter type
adjustments described in 8.3.5 are performed."

Alexandre Courpron.
Jun 27 '08 #2
co******@gmail.com wrote:
On 29 mai, 08:36, Barry <dhb2...@gmail.comwrote:
>The problem brought by one earlier post from comp.lang.c++http://groups.google.com/group/comp....ead/thread/bf6...

I take part of the question and reproduce the code to represent (partly)
the question.

#include <iostream>

template <class>
void f(...)
{
std::cout << "..." << std::endl;

}

template <class T>
void f(T[1])
{
std::cout << "T" << std::endl;

}

int main()
{
f<int>(0);
f<void>(0);

}

as "array of void" is invalid type, so the f<voidshould applies SFINAE
and chooses the "f(...)" version

the code above compiles and runs _expectedly_ with VC8
but fails to compile with Comuea Online, producing the error message:

"ComeauTest.c", line 10: error: array of void is not allowed
void f(T[1])
^
detected during instantiation of "f" based on template argument
<voidat line 18

compiles with gcc 4.3.0 but produced unexpected result, producing
T
T
which means that f<int>, f<voidboth chooses the second version.

so who's right about this?

I guess VC8 is right.

SFINAE comes when type deduction fails, which can happen in the
following context :

14.8.2.2 :

"When an explicit template argument list is specified, the template
arguments must be compatible with the template parameter list and must
result in a valid function type as described below; otherwise type
deduction fails. Specifically, [...] Type deduction may fail for the
following reasons:
Attempting to create an array with an element type that is void"
>one more question:
should

8.3.5.3 [...] The type of a function is determined using the
following rules. The type of each parameter is determined from its own
decl-specifier-seq and declarator. After determining the type of each
parameter, any parameter of type array of T or function returning
T is adjusted to be pointer to T or pointer to function returning
T, respectively.
[...]

the adjustment apply before SFINAE happens?
I guess GCC4.3.0 gives an "yes" answer.


Such adjustement is applied after SFINAE.

14.8.2.3 :

"After this substitution is performed, the function parameter type
adjustments described in 8.3.5 are performed."

Alexandre Courpron.
This suggests that VC8 is probably doing the correct thing. First SFINAE
kicks in and the ... version is chosen, then void[1] decays to void *
and becomes a valid type.

Although now I could understand why comeau is reporting an error, not
taking into account the decay effect, void[1] is an invalid type
regardless. But in the same vein, it's still doing something wrong when
it takes void(*)[1] without reporting any error.

SFINAE needs to be better standardized and documented. Intel compiler
behaves exactly like comeau, different from g++ and vc8.

Fei
Jun 27 '08 #3

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

Similar topics

8
by: Peter Collingbourne | last post by:
Hello I am trying to do some template metaprogramming involving enabling or disabling a method in a parameterised class based on some condition. I am trying to use the Boost enable_if mechanism...
2
by: Clark S. Cox III | last post by:
I'm writing a class that, depending on a template parameter, has constructors that take differing numbers of arguments. I initially thought that I could use SFINAE (via boost::enable_if_c) to...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
6
by: edd | last post by:
Hello all, Is there a way to determine whether a particular type supports the -> operator at compile time? I'm trying to write a template function (or a series of overloads) that will yield the...
3
by: none | last post by:
I am trying to understand SFINAE based on this wiki page: http://en.wikipedia.org/wiki/SFINAE // Defines return type to be void for all types // besides int. template<typename T> struct...
5
by: Fei Liu | last post by:
Hello, I just hit a strange problem regarding SFINAE. The following code causes compile error (void cannot be array element type), I thought SFINA should match test(...) version instead and not...
35
by: James Kanze | last post by:
Just ran into an interesting question concerning SFINAE. Given the following code: #include <iostream> #include <typeinfo> template< typename T > class P { public:
11
by: Hendrik Schober | last post by:
Hi, I'm having two overloaded function templates, #include <iterator> template< typename T > void test( T /*a1*/, T /*a2*/ ) {} template< typename Iter >
0
by: greek_bill | last post by:
Hi, I have a template function for which I use SFINAE to restrict one of the parameters. Then I also have a partial specialization of this function.I would like to provide an explicit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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 projectplanning, 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.