Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Gary Benson <gbenson@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix -Wstring-compare testcase build failure
Date: Tue, 23 Jun 2020 16:57:30 +0100	[thread overview]
Message-ID: <db26442d-4830-0154-f2ab-4e51f70bd484@redhat.com> (raw)
In-Reply-To: <1592924228-13346-1-git-send-email-gbenson@redhat.com>

On 6/23/20 3:57 PM, Gary Benson via Gdb-patches wrote:
> Hi all,
> 
> Clang fails to compile the file gdb/testsuite/gdb.cp/try_catch.cc
> with the following error:
>   warning: result of comparison against a string literal is
>   unspecified (use strncmp instead) [-Wstring-compare]
> 
> This patch replaces the string literal with a pointer, to avoid
> the error.
> 
> Is it ok to commit?

Hmm, no, I don't think so.

>  
>    // 3 use standard library
>    using namespace std;
> +  const char *throwme = "gdb.1";
>    try
>      {
>        if (j < 100)
> -	throw invalid_argument("gdb.1"); // marker 3-throw
> +	throw invalid_argument(throwme); // marker 3-throw
>      }
>    catch (exception& obj)
>      {
> -      if (obj.what() != "gdb.1")	// marker 3-catch
> +      if (obj.what() != throwme)	// marker 3-catch
>  	test &= false;
>      }
>    return 0;
invalid_argument stores a copy of the string, so with or
without your patch, that (obj.what() != "gdb.1") comparison
is returning false.  Thus the "test &= false;" statement is
executing.

IOW, that Clang warning found a bug in the test program...

The fix should be to use strcmp instead.

And also, please add a market at the "return 0;" line,
let the program run to it, and then add a gdb_test checking
that "test" is still true at that point.

Thanks,
Pedro Alves



  reply	other threads:[~2020-06-23 15:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23 14:57 Gary Benson
2020-06-23 15:57 ` Pedro Alves [this message]
2020-06-26 13:05   ` [PATCH v2] " Gary Benson
2020-06-26 13:19     ` Pedro Alves
2020-06-26 13:54       ` Gary Benson

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=db26442d-4830-0154-f2ab-4e51f70bd484@redhat.com \
    --to=palves@redhat.com \
    --cc=gbenson@redhat.com \
    --cc=gdb-patches@sourceware.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