This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/14083] New: ICE in conditional expression operator with throw
- From: "gcc at online dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 9 Feb 2004 13:40:37 -0000
- Subject: [Bug c++/14083] New: ICE in conditional expression operator with throw
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code generates an ICE:
int main(int argc,char**argv)
{
std::string s("hello world");
try {
cerr << ( s=="hello" ? s : throw exception() ) << endl;
} catch (...) {
cerr << "Exception" << endl;
};
};
The program should output 'Exception'.
ISO 14882-98:
(15)
A throw-expression is of type void.
(5.16)
If either the second or the third operand has type void, then the
lvalue-to-rvalue ... standard conversions are performed on the second and third
operands, and one of the following shall hold:
- The second or third operand (but not both) is a throw-expression (15.1); the
result is of the type of the other and is an rvalue.
...
END ISO14882-98
Personal Interpretation:
Conditional operator in the above code:
s=="hello" ? s : throw exception()
1st operand/expression: 's=="hello"' (type bool)
2nd operand/expression: 's' (type std::string)
3rd operand/expression: 'throw exception()' (type void)
The third operand (throw-expression) is of type void and with that, one of the
conditions in 5.16 holds, so the result should be of the type of the other
(second) expression (std::string), but the compiler generates an ICE as follows:
[user@host] /usr/local/bin/g++ test.cc
test.cc: In function `int main(int, char**)':
test.cc:764: internal compiler error: in cp_expr_size, at cp/cp-lang.c:312
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
ICE does not occur if in above code type of 's' is substituted for integral type
(together with appropriate integral comparisons in above code).
Experienced with default redhat 9 i386 compiler and now with self compiled gcc
3.3.2 i686-pc-linux-gnu compiler.
--
Summary: ICE in conditional expression operator with throw
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcc at online dot nl
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14083