public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "romixlev at yahoo dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/16711] New: Bug in reporting integral constant expressions problems Date: Mon, 26 Jul 2004 08:04:00 -0000 [thread overview] Message-ID: <20040726080349.16711.romixlev@yahoo.com> (raw) G++ 3.4.1 rejects some integral constant expressions that were allowed in the earlier versions. The same file compiled with GCC as a C file does not produce any errors. This report seems to be related to Bugzilla Bug 16489. The sample file below (sample.cc) contains comments explaining the problem. How to reproduce the bug: g++ sample.cc --------------------------------------------------------------------------- /* // Bug report for gcc version 3.4.1 (Mandrakelinux (Cooker) 3.4.1-1mdk) // Recent versions of G++ refuse to accept some // constant expressions which contain casts into // non integral types, e.g. into pointer types. // It says a cast to anything // but integral or enumaration type is not an integral constant // expression. // Such expressions are often produced by some // tools generating C++ code as their output. // Previously, these expressions were accepted by // G++. // Size of array should be an integral constant expression, or? // But G++ does not complain about this expression */ int array [((int)(void*)1)]; enum MyEnum { /* // Here we use the same constant_expression, // but as a value of the enumerator. // G++ doesn't like it for some reason */ ONE = ((int)((void*)1)) }; int main(int argc) { switch(argc) { /* // Here we use the same constant_expression // as a case value of switch statement // G++ does not like it at this place, too. */ case ((int)(void*)1): break; case 2: break; } return 0; } /* There are three places in this program, that are using the same integer constant_expression. Earlier versions of G++, <= 3.2.X, didn't have this problem and accepted all three occurences of the constant_expression without any problems. More over, all other C++ compilers (Borland C++, Visual C++, etc) do not complain about this code. If this file is compiled as a C file, no errors are reported by GCC. It looks like the switch to the new C++ parser and corresponding changes in the G++ code introduced this behavior. And it looks like it is a bug in G++. After looking at the Changelog file, it seems that the following change could have introduced such a behavior: 2004-03-19 Giovanni Bajo <giovannibajo@gcc.gnu.org> PR c++/14545 * parser.c (cp_parser_functional_cast): A cast to anything but integral or enumaration type is not an integral constant expression. Probably, only the final type of the integral constant expression should be integral or enumeration. But in the middle of such expressions, it should probably be possible to cast to some other types, at least into pointer types, since conversions between pointers and integers do not involve any run-time computations. */ -- Summary: Bug in reporting integral constant expressions problems Product: gcc Version: 3.4.1 Status: UNCONFIRMED Severity: critical Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: romixlev at yahoo dot com CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16711
next reply other threads:[~2004-07-26 8:04 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2004-07-26 8:04 romixlev at yahoo dot com [this message] 2004-07-26 13:32 ` [Bug c++/16711] [3.4/3.5 regression] " bangerth at dealii dot org 2004-07-26 14:26 ` pinskia at gcc dot gnu dot org 2004-07-26 14:28 ` bangerth at dealii dot org 2004-07-26 20:30 ` jsm at polyomino dot org dot uk 2004-07-27 7:07 ` romixlev at yahoo dot com 2004-07-27 13:21 ` bangerth at dealii dot org 2004-07-27 13:25 ` bangerth at dealii dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20040726080349.16711.romixlev@yahoo.com \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).