public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/64372] Spurious warning with throw in ternary operator returning const reference
Date: Mon, 22 Dec 2014 00:49:00 -0000	[thread overview]
Message-ID: <bug-64372-4-WnzG83qZmD@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-64372-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64372

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |glisse at gcc dot gnu.org,
                   |                            |manu at gcc dot gnu.org
      Known to fail|                            |4.9.2, 5.0

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
I think *p creates a temporary that only lasts until the end of the function,
so the code is undefined. Probably even:

const char&
foz(const char* p)
{
  return *p;
}

is undefined. However, G++ and Clang currently handles this as returning p:

;; Function const char& foz(const char*) (null)
;; enabled by -tree-original


return <retval> = (const char &) NON_LVALUE_EXPR <p>;


;; Function const char& foo(const char*, const char*) (null)
;; enabled by -tree-original


return <retval> = (const char &) (p != 0B ? NON_LVALUE_EXPR <p> :
NON_LVALUE_EXPR <q>);


;; Function const char& fzz(const char*) (null)
;; enabled by -tree-original


<<cleanup_point return <retval> = (const char &) &TARGET_EXPR <D.2338, p != 0B
? (char) *p : <<< Unknown tree: throw_expr
  <<cleanup_point TARGET_EXPR <D.2335, __cxa_allocate_exception (8)>;, *(const
char * *) D.2335 = p;>>;, __cxa_throw (D.2335, (void *) &_ZTIPKc, 0B); >>>>;,
0>>;


Note that in the testcase that throws, the gimple indicates that the reference
is set to null even when not throwing, which leads to a segmentation fault.

const char& fzz(const char*) (const char * p)
{
  const charD.10 & D.2348;
  const charD.10 D.2338;
  charD.10 iftmp.1D.2349;
  voidD.45 * D.2335;

  [test.cc:18:24] if (pD.2330 != 0B) goto <D.2350>; else goto <D.2351>;
  <D.2350>:
  [test.cc:18:24] iftmp.1D.2349 = [test.cc:18:24] *pD.2330;
  goto <D.2352>;
  <D.2351>:
  [test.cc:18:24] # USE = anything 
  # CLB = anything 
  D.2335 = __cxa_allocate_exceptionD.2334 (8);
  [test.cc:18:24] try
    {
      [test.cc:18:24] [test.cc:18:24] MEM[(const charD.10 * *)D.2335] =
pD.2330;
    }
  catch
    {
      [test.cc:18:24] # USE = anything 
      # CLB = anything 
      __cxa_free_exceptionD.2336 (D.2335);
    }
  [test.cc:18:24] # USE = anything 
  # CLB = anything 
  __cxa_throwD.2333 (D.2335, &_ZTIPKcD.2337, 0B);
  <D.2352>:
  [test.cc:18:24] D.2338 = iftmp.1D.2349;
  [test.cc:18:24] try
    {
      [test.cc:18:24] D.2348 = 0;
      [test.cc:18:24] return D.2348;
    }
  finally
    {
      [test.cc:18:24] D.2338 = {CLOBBER};
    }
}
>From gcc-bugs-return-471527-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Dec 22 02:26:43 2014
Return-Path: <gcc-bugs-return-471527-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 618 invoked by alias); 22 Dec 2014 02:26:37 -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 565 invoked by uid 48); 22 Dec 2014 02:26:27 -0000
From: "egall at gwmail dot gwu.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/61864] Feature Request, -Wcovered-switch-default to identify "dead" default branch
Date: Mon, 22 Dec 2014 02:26:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: egall at gwmail dot gwu.edu
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 5.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-61864-4-Au5kIhlMbj@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61864-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61864-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-12/txt/msg02534.txt.bz2
Content-length: 876

https://gcc.gnu.org/bugzilla/show_bug.cgi?ida864

Eric Gallager <egall at gwmail dot gwu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egall at gwmail dot gwu.edu

--- Comment #2 from Eric Gallager <egall at gwmail dot gwu.edu> ---
this(In reply to Chengnian Sun from comment #0)
> Currently, GCC supports -Wswitch and -Wswitch-enum.

It also supports "-Wswitch-default", which seems to be the exact opposite of
clang's "-Wcovered-switch-default". Personally I think gcc's "-Wswitch-default"
is the better one to listen to; having a default case is a good back-up even if
it will never actually be reached. Here is a link to a post that explains it
better than I could: http://programmers.stackexchange.com/a/242896/161051


  reply	other threads:[~2014-12-22  0:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-21 18:43 [Bug c++/64372] New: " tavianator at gmail dot com
2014-12-22  0:49 ` manu at gcc dot gnu.org [this message]
2014-12-22  7:31 ` [Bug c++/64372] " harald at gigawatt dot nl
2014-12-22  7:38 ` tavianator at gmail dot com
2014-12-23 14:15 ` [Bug c++/64372] [DR1560] Gratuitous lvalue-to-rvalue conversion in conditional-expression with throw-expression operand harald at gigawatt dot nl
2021-07-23  0:06 ` pinskia at gcc dot gnu.org
2021-07-31 22:02 ` pinskia at gcc dot gnu.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-64372-4-WnzG83qZmD@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).