public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "michael.chapman at cortus dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/7652] -Wswitch-break : Warn if a switch case falls through
Date: Wed, 30 Apr 2014 17:20:00 -0000	[thread overview]
Message-ID: <bug-7652-4-xsPxrkTDsK@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-7652-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652

--- Comment #33 from Michael Chapman <michael.chapman at cortus dot com> ---
(In reply to Florian Weimer from comment #30)
> (In reply to Manuel López-Ibáñez from comment #29)
> 
> > I like the previous suggestion of using "goto LABEL;". In fact, the warning
> > message could explicitly say "use %<goto %D;%> to silence this warning".
> 
> Does this mean that you propose a GCC extension which allows to write this?
> 
>      goto 5;
>    case 5:
> 
> I'm not sure if the extension is worth it, and it creates another source of
> errors/unclarities if another switch branch is inserted before "case 5:". 
> It looks like fall-through, but it isn't one because the case labels aren't
> aligned.

Why an extension? What is wrong with:-

        goto case_5;
      case 5: case_5:
         ....
>From gcc-bugs-return-450284-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Apr 30 17:27:48 2014
Return-Path: <gcc-bugs-return-450284-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 11494 invoked by alias); 30 Apr 2014 17:27:48 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 11469 invoked by uid 48); 30 Apr 2014 17:27:44 -0000
From: "ppluzhnikov at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/61020] New: [4.9/4.10 Regression] typeid(typeid(X)) produces 'ud2'
Date: Wed, 30 Apr 2014 17:27:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: ppluzhnikov at google dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter
Message-ID: <bug-61020-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-04/txt/msg02304.txt.bz2
Content-length: 1275

http://gcc.gnu.org/bugzilla/show_bug.cgi?ida020

            Bug ID: 61020
           Summary: [4.9/4.10 Regression] typeid(typeid(X)) produces 'ud2'
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppluzhnikov at google dot com

The test case:

#include <typeinfo>

struct Base {
  virtual ~Base() { }
};

struct Derived : public Base {
};

int compare(const Base& base)
{
  return typeid(base) == typeid(typeid(Derived));
}

int main()
{
  Base base;
  Derived derived;

  if (compare(base)) return 1;
  if (compare(derived)) return 2;
  return 0;
}


Using trunk @ r209848
g++ -g t.cc && ./a.out && echo OK
OK

g++ -g t.cc -O2 && ./a.out
Segmentation fault (core dumped)

(gdb) disas main
Dump of assembler code for function main():
   0x00000000004004c0 <+0>:     mov    0x8,%rax
   0x00000000004004c8 <+8>:     ud2
End of assembler dump.


It appears that GCC believes the test to invoke undefined behavior.
However, I don't see anything in the standard to support this.

P.S. Same result in C++98 and C++11
P.P.S. In the original code, the double application of typeid() was a bug.


  parent reply	other threads:[~2014-04-30 17:20 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-7652-4@http.gcc.gnu.org/bugzilla/>
2011-02-02  1:04 ` alsuren+gcc at gmail dot com
2011-05-09 14:48 ` barnes.leo at gmail dot com
2011-07-29 13:29 ` daniel.marjamaki at gmail dot com
2012-02-21  1:04 ` eric at brouhaha dot com
2012-02-21  1:14 ` eric at brouhaha dot com
2012-07-14  4:55 ` pinskia at gcc dot gnu.org
2012-07-14 11:54 ` redi at gcc dot gnu.org
2012-07-14 15:15 ` david at doublewise dot net
2012-09-17 22:02 ` alexfh at google dot com
2012-09-18 11:12 ` manu at gcc dot gnu.org
2012-11-26 22:49 ` arthur.j.odwyer at gmail dot com
2012-11-26 23:03 ` arthur.j.odwyer at gmail dot com
2013-06-23  6:44 ` dcb314 at hotmail dot com
2013-06-23 10:38 ` manu at gcc dot gnu.org
2013-06-23 12:21 ` jasonwucj at gmail dot com
2014-02-16 13:18 ` jackie.rosen at hushmail dot com
2014-04-30 15:45 ` michael.chapman at cortus dot com
2014-04-30 16:09 ` mw_triad at users dot sourceforge.net
2014-04-30 16:10 ` manu at gcc dot gnu.org
2014-04-30 16:18 ` fweimer at redhat dot com
2014-04-30 16:23 ` mpolacek at gcc dot gnu.org
2014-04-30 16:35 ` alexfh at google dot com
2014-04-30 16:40 ` manu at gcc dot gnu.org
2014-04-30 17:04 ` mw_triad at users dot sourceforge.net
2014-04-30 17:20 ` michael.chapman at cortus dot com [this message]
2014-09-23  7:25 ` m.j.thayer at googlemail dot com
     [not found] <bug-7652-1366@http.gcc.gnu.org/bugzilla/>
2010-03-04 20:48 ` pinskia at gcc dot gnu dot org
     [not found] <20020820073602.7652.ac131313@redhat.com>
2004-07-29  9:43 ` brendan at zen 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=bug-7652-4-xsPxrkTDsK@http.gcc.gnu.org/bugzilla/ \
    --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: link
Be 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).