public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21510] New: Possible bug
@ 2005-05-11 10:28 sven at clio dot in-berlin dot de
2005-05-11 11:10 ` [Bug c++/21510] " pinskia at gcc dot gnu dot org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: sven at clio dot in-berlin dot de @ 2005-05-11 10:28 UTC (permalink / raw)
To: gcc-bugs
The following code contains a test template is_class which tries to determine,
if the given argument is a class. Unlike other implementations it should not
return true if the argument is a union. I have used the 'substitution failure
is not an error' principle but g++ V3.3.5 (Debian 1:3.3.5-12) (i486-linux)
fails with an error though it has a default function available. Since I do not
have the standard I can't declare this a bug.
---- bug.c
cusing namespace std;
#include <iostream>
template<typename _T>
struct is_class
{
typedef char no;
struct yes { char c[2]; };
template<typename _U>
struct c: _U
{
c(int);
};
template<typename _U> static no test (...);
template<typename _U> static yes test(c<_U>);
static const bool v = (sizeof (test<_T>(0))==sizeof(yes));
};
union u { int i; double f; };
struct c {};
int main (void)
{
cout << "union:" << is_class<u>::v << endl;
cout << "class:" << is_class<c>::v << endl;
cout << "int:" << is_class<int>::v << endl;
return 0;
};
--
Summary: Possible bug
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sven at clio dot in-berlin dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i486-linux
GCC host triplet: i486-linux
GCC target triplet: i486-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
@ 2005-05-11 11:10 ` pinskia at gcc dot gnu dot org
2005-05-12 9:49 ` sven at clio dot in-berlin dot de
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-11 11:10 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-11 11:10 -------
I don't think you used SFINF correctly.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
2005-05-11 11:10 ` [Bug c++/21510] " pinskia at gcc dot gnu dot org
@ 2005-05-12 9:49 ` sven at clio dot in-berlin dot de
2005-05-15 12:37 ` lerdsuwa at gcc dot gnu dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: sven at clio dot in-berlin dot de @ 2005-05-12 9:49 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From sven at clio dot in-berlin dot de 2005-05-12 09:48 -------
(In reply to comment #1)
> I don't think you used SFINF correctly.
The substitution of the formal parameter with the actual argument fails, thus
it is a form of substitution failure. I do not know, if the example is
conforming to the standard. It would be a working method to distinguish
between classes and non classes. On the other hand the more stricter
interpretation is more safe.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
2005-05-11 11:10 ` [Bug c++/21510] " pinskia at gcc dot gnu dot org
2005-05-12 9:49 ` sven at clio dot in-berlin dot de
@ 2005-05-15 12:37 ` lerdsuwa at gcc dot gnu dot org
2005-05-15 14:08 ` sven at clio dot in-berlin dot de
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2005-05-15 12:37 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From lerdsuwa at gcc dot gnu dot org 2005-05-15 12:37 -------
The code is invalid. In the section 14.8.2 [temp.deduct] paragraph 2 of the
standard
does not include creating a class with invalid base class. Examples of valid
SNINF cases:
- Attempting to create an array with an element type that is void, a function type,
or a reference type, or attempting to create an array with a size that is zero
or negative.
- Attempting to use a type that is not a class type in a qualified name.
etc. (there are many more they are clearly mentioned in the mentioned part of
standard)
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
` (2 preceding siblings ...)
2005-05-15 12:37 ` lerdsuwa at gcc dot gnu dot org
@ 2005-05-15 14:08 ` sven at clio dot in-berlin dot de
2005-05-15 14:13 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: sven at clio dot in-berlin dot de @ 2005-05-15 14:08 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From sven at clio dot in-berlin dot de 2005-05-15 14:08 -------
(In reply to comment #3)
> The code is invalid. In the section 14.8.2 [temp.deduct] paragraph 2 of the
> standard
> does not include creating a class with invalid base class.
If there is no other way to distinguish reliable between unions and classes,
add it into the extension list. Unions should be avoided in object oriented
design, anyway, but it is a nice-to-have feature.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
` (3 preceding siblings ...)
2005-05-15 14:08 ` sven at clio dot in-berlin dot de
@ 2005-05-15 14:13 ` pinskia at gcc dot gnu dot org
2005-05-15 14:46 ` sven at clio dot in-berlin dot de
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-15 14:13 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-15 14:12 -------
(In reply to comment #4)
> If there is no other way to distinguish reliable between unions and classes,
> add it into the extension list. Unions should be avoided in object oriented
> design, anyway, but it is a nice-to-have feature.
Extensions are bad. Even just bugs in the compiler is a bad thing beause people would think the bug
was an extension and start depending on it and then when the bug was fixed, people complain their
code no longer compiles.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
` (4 preceding siblings ...)
2005-05-15 14:13 ` pinskia at gcc dot gnu dot org
@ 2005-05-15 14:46 ` sven at clio dot in-berlin dot de
2005-05-15 15:04 ` pcarlini at suse dot de
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: sven at clio dot in-berlin dot de @ 2005-05-15 14:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From sven at clio dot in-berlin dot de 2005-05-15 14:46 -------
(In reply to comment #5)
> Extensions are bad. Even just bugs in the compiler is a bad thing beause
> people would think the bug
> was an extension and start depending on it and then when the bug was fixed,
>people complain their
> code no longer compiles.
Is there a way to distinguish between unions (which are not usable as base
classes) and classes? If not, the standard is incomplete.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
` (5 preceding siblings ...)
2005-05-15 14:46 ` sven at clio dot in-berlin dot de
@ 2005-05-15 15:04 ` pcarlini at suse dot de
2005-05-16 10:22 ` sven at clio dot in-berlin dot de
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pcarlini at suse dot de @ 2005-05-15 15:04 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pcarlini at suse dot de 2005-05-15 15:03 -------
> Is there a way to distinguish between unions (which are not usable as base
> classes) and classes? If not, the standard is incomplete.
You should know that 10 years ago people didn't even imagine the kind of
template usages that you are assuming as obvious. Indeed, everyone wants
to tell unions from classes now and you bet, it will be possible sometime
in the future, likely not using SFINAE at all. Before posting other
messages with this attitude, please, please have a look to the papers
available from the ISO Web site:
http://www.open-std.org/jtc1/sc22/wg21/
Thanks.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
` (6 preceding siblings ...)
2005-05-15 15:04 ` pcarlini at suse dot de
@ 2005-05-16 10:22 ` sven at clio dot in-berlin dot de
2005-05-16 19:19 ` gdr at integrable-solutions dot net
2005-05-17 11:43 ` sven at clio dot in-berlin dot de
9 siblings, 0 replies; 11+ messages in thread
From: sven at clio dot in-berlin dot de @ 2005-05-16 10:22 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From sven at clio dot in-berlin dot de 2005-05-16 10:22 -------
(In reply to comment #7)
> > Is there a way to distinguish between unions (which are not usable as base
> > classes) and classes? If not, the standard is incomplete.
>
> You should know that 10 years ago people didn't even imagine the kind of
> template usages that you are assuming as obvious. Indeed, everyone wants
> to tell unions from classes now and you bet, it will be possible sometime
> in the future, likely not using SFINAE at all.
I know and accept this. SFINAE is a possible dangerous feature, anyway. It may
be better if the ISO standard declares something like the following
(incomplete, feel free to propose it to the standard comitee):
The pragma statements
_Pragme(set, "sfinae", on) // enables SFINAE
_Pragma(set, "sfinae", off) // disables SFINAE
_Pragma(reset, "sfinae") // sets SFINAE to the previous state
control the substitution-failure-is-not-an-error-feature. When setting to "on"
any substitution of a template argument of a class or function declared or
defined in the context may fail without an error, if
- the statement is syntactical correct
- there is a less specific template which could be instantiated without an
error.
When leaving the context, _Pragma(reset, "sfinae") is called automatical. The
user is complete responsible for using SFINAE, no further compiler support is
standardized.
This would localize the feature and alert the user that this is a potential
dangerous construct. And it is much more general, possible easier to
implement.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
` (7 preceding siblings ...)
2005-05-16 10:22 ` sven at clio dot in-berlin dot de
@ 2005-05-16 19:19 ` gdr at integrable-solutions dot net
2005-05-17 11:43 ` sven at clio dot in-berlin dot de
9 siblings, 0 replies; 11+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-05-16 19:19 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at integrable-solutions dot net 2005-05-16 19:19 -------
Subject: Re: Possible bug
"sven at clio dot in-berlin dot de" <gcc-bugzilla@gcc.gnu.org> writes:
| (In reply to comment #7)
| > > Is there a way to distinguish between unions (which are not usable as base
| > > classes) and classes? If not, the standard is incomplete.
| >
| > You should know that 10 years ago people didn't even imagine the kind of
| > template usages that you are assuming as obvious. Indeed, everyone wants
| > to tell unions from classes now and you bet, it will be possible sometime
| > in the future, likely not using SFINAE at all.
|
| I know and accept this. SFINAE is a possible dangerous feature, anyway. It may
| be better if the ISO standard declares something like the following
| (incomplete, feel free to propose it to the standard comitee):
|
| The pragma statements
|
| _Pragme(set, "sfinae", on) // enables SFINAE
| _Pragma(set, "sfinae", off) // disables SFINAE
| _Pragma(reset, "sfinae") // sets SFINAE to the previous state
Over my dead body. :-)
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/21510] Possible bug
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
` (8 preceding siblings ...)
2005-05-16 19:19 ` gdr at integrable-solutions dot net
@ 2005-05-17 11:43 ` sven at clio dot in-berlin dot de
9 siblings, 0 replies; 11+ messages in thread
From: sven at clio dot in-berlin dot de @ 2005-05-17 11:43 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From sven at clio dot in-berlin dot de 2005-05-17 11:42 -------
(In reply to comment #9)
> Over my dead body. :-)
Oh, come on. It isn't that bad an idea to localize substitution failures,
isn't it:-)
> -- Gaby
Sven
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21510
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2005-05-17 11:43 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-11 10:28 [Bug c++/21510] New: Possible bug sven at clio dot in-berlin dot de
2005-05-11 11:10 ` [Bug c++/21510] " pinskia at gcc dot gnu dot org
2005-05-12 9:49 ` sven at clio dot in-berlin dot de
2005-05-15 12:37 ` lerdsuwa at gcc dot gnu dot org
2005-05-15 14:08 ` sven at clio dot in-berlin dot de
2005-05-15 14:13 ` pinskia at gcc dot gnu dot org
2005-05-15 14:46 ` sven at clio dot in-berlin dot de
2005-05-15 15:04 ` pcarlini at suse dot de
2005-05-16 10:22 ` sven at clio dot in-berlin dot de
2005-05-16 19:19 ` gdr at integrable-solutions dot net
2005-05-17 11:43 ` sven at clio dot in-berlin dot de
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).