* [OB PATCH] Avoid testcase build failures with -Wunused-value
@ 2020-06-23 11:26 Gary Benson
2020-06-23 11:41 ` Pedro Alves
0 siblings, 1 reply; 5+ messages in thread
From: Gary Benson @ 2020-06-23 11:26 UTC (permalink / raw)
To: gdb-patches
A number of testcases fail to build with -Wunused-value enabled.
This commit adds dummy values to avoid this.
gdb/testsuite/ChangeLog:
* gdb.cp/namespace.cc: Avoid build failure with -Wunused-value.
* gdb.cp/nsimport.cc: Likewise.
* gdb.cp/nsnested.cc: Likewise.
* gdb.cp/nsnoimports.cc: Likewise.
* gdb.cp/nsusing.cc: Likewise.
* gdb.cp/smartp.cc: Likewise.
* gdb.python/py-pp-integral.c: Likewise.
* gdb.python/py-pp-re-notag.c: Likewise.
---
gdb/testsuite/ChangeLog | 11 +++++++++++
gdb/testsuite/gdb.cp/namespace.cc | 22 +++++++++++-----------
gdb/testsuite/gdb.cp/nsimport.cc | 6 +++---
gdb/testsuite/gdb.cp/nsnested.cc | 2 +-
gdb/testsuite/gdb.cp/nsnoimports.cc | 12 ++++++------
gdb/testsuite/gdb.cp/nsusing.cc | 12 ++++++------
gdb/testsuite/gdb.cp/smartp.cc | 8 ++++----
gdb/testsuite/gdb.python/py-pp-integral.c | 4 ++--
gdb/testsuite/gdb.python/py-pp-re-notag.c | 4 ++--
9 files changed, 46 insertions(+), 35 deletions(-)
diff --git a/gdb/testsuite/gdb.cp/namespace.cc b/gdb/testsuite/gdb.cp/namespace.cc
index f918b63..1ff3426 100644
--- a/gdb/testsuite/gdb.cp/namespace.cc
+++ b/gdb/testsuite/gdb.cp/namespace.cc
@@ -150,22 +150,22 @@ namespace C
// plan to have GDB try to print out, just to make sure that the
// compiler and I agree which ones should be legal! It's easy
// to screw up when testing the boundaries of namespace stuff.
- c;
+ int unused1 = c;
//cc;
- C::cc;
- cd;
+ int unused2 = C::cc;
+ int unused3 = cd;
//C::D::cd;
- E::cde;
- shadow;
+ int unused4 = E::cde;
+ int unused5 = shadow;
//E::ce;
- cX;
- F::cXf;
- F::cXfX;
- X;
- G::Xg;
+ int unused6 = cX;
+ int unused7 = F::cXf;
+ int unused8 = F::cXfX;
+ int unused9 = X;
+ int unusedA = G::Xg;
//cXOtherFile;
//XOtherFile;
- G::XgX;
+ int unusedB = G::XgX;
return;
}
diff --git a/gdb/testsuite/gdb.cp/nsimport.cc b/gdb/testsuite/gdb.cp/nsimport.cc
index 6b180d6..5fc57b0 100644
--- a/gdb/testsuite/gdb.cp/nsimport.cc
+++ b/gdb/testsuite/gdb.cp/nsimport.cc
@@ -13,8 +13,8 @@ namespace{
int main()
{
- x;
- xx;
- xxx;
+ int unused1 = x;
+ int unused2 = xx;
+ int unused3 = xxx;
return 0;
}
diff --git a/gdb/testsuite/gdb.cp/nsnested.cc b/gdb/testsuite/gdb.cp/nsnested.cc
index 9723f87..fc3e11f 100644
--- a/gdb/testsuite/gdb.cp/nsnested.cc
+++ b/gdb/testsuite/gdb.cp/nsnested.cc
@@ -15,7 +15,7 @@ namespace C
int
second()
{
- ab;
+ int unused = ab;
return 0;
}
}
diff --git a/gdb/testsuite/gdb.cp/nsnoimports.cc b/gdb/testsuite/gdb.cp/nsnoimports.cc
index d1c68ab..9968c35 100644
--- a/gdb/testsuite/gdb.cp/nsnoimports.cc
+++ b/gdb/testsuite/gdb.cp/nsnoimports.cc
@@ -18,9 +18,9 @@ namespace A
}
int first(){
- _a;
- ab;
- C::abc;
+ int unused1 = _a;
+ int unused2 = ab;
+ int unused3 = C::abc;
return C::second();
}
}
@@ -30,8 +30,8 @@ namespace A
int
main()
{
- A::_a;
- A::B::ab;
- A::B::C::abc;
+ int unused1 = A::_a;
+ int unused2 = A::B::ab;
+ int unused3 = A::B::C::abc;
return A::B::first();
}
diff --git a/gdb/testsuite/gdb.cp/nsusing.cc b/gdb/testsuite/gdb.cp/nsusing.cc
index 72ff941..980a91a 100644
--- a/gdb/testsuite/gdb.cp/nsusing.cc
+++ b/gdb/testsuite/gdb.cp/nsusing.cc
@@ -35,7 +35,7 @@ namespace L
using namespace J;
int marker8 ()
{
- jx;
+ int unused = jx;
return K::marker9 ();
}
}
@@ -53,7 +53,7 @@ namespace I
int marker7 ()
{
using namespace G::H;
- ghx;
+ int unused = ghx;
return L::marker8 ();
}
}
@@ -69,7 +69,7 @@ namespace E
using namespace E::F;
int marker6 ()
{
- efx;
+ int unused = efx;
return I::marker7 ();
}
@@ -92,7 +92,7 @@ namespace D
using namespace C;
int marker5 ()
{
- cc;
+ int unused = cc;
return marker6 ();
}
@@ -110,7 +110,7 @@ int marker3 ()
int marker2 ()
{
namespace B = A;
- B::_a;
+ int unused = B::_a;
return marker3 ();
}
@@ -134,6 +134,6 @@ int marker1 ()
int main ()
{
using namespace A;
- _a;
+ int unused = _a;
return marker1 ();
}
diff --git a/gdb/testsuite/gdb.cp/smartp.cc b/gdb/testsuite/gdb.cp/smartp.cc
index 2e71d1a..ed52102 100644
--- a/gdb/testsuite/gdb.cp/smartp.cc
+++ b/gdb/testsuite/gdb.cp/smartp.cc
@@ -131,12 +131,12 @@ int main(){
sp3->foo(1);
sp3->foo('a');
- sp4->a;
- sp4->b;
+ int unused1 = sp4->a;
+ int unused2 = sp4->b;
Type4 *mt4p = &mt4;
- mt4p->a;
- mt4p->b;
+ int unused3 = mt4p->a;
+ int unused4 = mt4p->b;
A a;
B b;
diff --git a/gdb/testsuite/gdb.python/py-pp-integral.c b/gdb/testsuite/gdb.python/py-pp-integral.c
index 5cefc00..eadb466 100644
--- a/gdb/testsuite/gdb.python/py-pp-integral.c
+++ b/gdb/testsuite/gdb.python/py-pp-integral.c
@@ -17,10 +17,10 @@
typedef long time_t;
-static void
+static time_t
tick_tock (time_t *t)
{
- *t++;
+ return *t++;
}
int
diff --git a/gdb/testsuite/gdb.python/py-pp-re-notag.c b/gdb/testsuite/gdb.python/py-pp-re-notag.c
index 5cefc00..eadb466 100644
--- a/gdb/testsuite/gdb.python/py-pp-re-notag.c
+++ b/gdb/testsuite/gdb.python/py-pp-re-notag.c
@@ -17,10 +17,10 @@
typedef long time_t;
-static void
+static time_t
tick_tock (time_t *t)
{
- *t++;
+ return *t++;
}
int
--
1.8.3.1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [OB PATCH] Avoid testcase build failures with -Wunused-value
2020-06-23 11:26 [OB PATCH] Avoid testcase build failures with -Wunused-value Gary Benson
@ 2020-06-23 11:41 ` Pedro Alves
2020-06-23 11:45 ` Gary Benson
2020-06-23 14:13 ` [OB PATCH] Improve -Wunused-value testcase build failures fix Gary Benson
0 siblings, 2 replies; 5+ messages in thread
From: Pedro Alves @ 2020-06-23 11:41 UTC (permalink / raw)
To: Gary Benson, gdb-patches
On 6/23/20 12:26 PM, Gary Benson via Gdb-patches wrote:
> --- a/gdb/testsuite/gdb.cp/namespace.cc
> +++ b/gdb/testsuite/gdb.cp/namespace.cc
> @@ -150,22 +150,22 @@ namespace C
> // plan to have GDB try to print out, just to make sure that the
> // compiler and I agree which ones should be legal! It's easy
> // to screw up when testing the boundaries of namespace stuff.
> - c;
> + int unused1 = c;
It looks like such a fix will only work until the compiler decides
to enable -Wunused-variable by default too:
testsuite/gdb.cp/namespace.cc:153:11: warning: unused variable 'unused' [-Wunused-variable]
int unused = c;
^
Try compiling the testcase with -Wall, with both g++ and clang++:
$ clang++ testsuite/gdb.cp/namespace.cc -Wall
I think we should fix this with the more usual cast-to-void way:
(void) c;
etc.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [OB PATCH] Avoid testcase build failures with -Wunused-value
2020-06-23 11:41 ` Pedro Alves
@ 2020-06-23 11:45 ` Gary Benson
2020-06-23 11:53 ` Pedro Alves
2020-06-23 14:13 ` [OB PATCH] Improve -Wunused-value testcase build failures fix Gary Benson
1 sibling, 1 reply; 5+ messages in thread
From: Gary Benson @ 2020-06-23 11:45 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
Pedro Alves wrote:
> On 6/23/20 12:26 PM, Gary Benson via Gdb-patches wrote:
> > --- a/gdb/testsuite/gdb.cp/namespace.cc
> > +++ b/gdb/testsuite/gdb.cp/namespace.cc
> > @@ -150,22 +150,22 @@ namespace C
> > // plan to have GDB try to print out, just to make sure that the
> > // compiler and I agree which ones should be legal! It's easy
> > // to screw up when testing the boundaries of namespace stuff.
> > - c;
> > + int unused1 = c;
>
> It looks like such a fix will only work until the compiler decides
> to enable -Wunused-variable by default too:
>
> testsuite/gdb.cp/namespace.cc:153:11: warning: unused variable 'unused' [-Wunused-variable]
> int unused = c;
> ^
>
> Try compiling the testcase with -Wall, with both g++ and clang++:
>
> $ clang++ testsuite/gdb.cp/namespace.cc -Wall
>
> I think we should fix this with the more usual cast-to-void way:
>
> (void) c;
Ok, but, out of interest, what stops the compiler ignoring that?
Thanks,
Gary
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [OB PATCH] Avoid testcase build failures with -Wunused-value
2020-06-23 11:45 ` Gary Benson
@ 2020-06-23 11:53 ` Pedro Alves
0 siblings, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2020-06-23 11:53 UTC (permalink / raw)
To: Gary Benson; +Cc: gdb-patches
On 6/23/20 12:45 PM, Gary Benson wrote:
> Pedro Alves wrote:
>> On 6/23/20 12:26 PM, Gary Benson via Gdb-patches wrote:
>>> --- a/gdb/testsuite/gdb.cp/namespace.cc
>>> +++ b/gdb/testsuite/gdb.cp/namespace.cc
>>> @@ -150,22 +150,22 @@ namespace C
>>> // plan to have GDB try to print out, just to make sure that the
>>> // compiler and I agree which ones should be legal! It's easy
>>> // to screw up when testing the boundaries of namespace stuff.
>>> - c;
>>> + int unused1 = c;
>>
>> It looks like such a fix will only work until the compiler decides
>> to enable -Wunused-variable by default too:
>>
>> testsuite/gdb.cp/namespace.cc:153:11: warning: unused variable 'unused' [-Wunused-variable]
>> int unused = c;
>> ^
>>
>> Try compiling the testcase with -Wall, with both g++ and clang++:
>>
>> $ clang++ testsuite/gdb.cp/namespace.cc -Wall
>>
>> I think we should fix this with the more usual cast-to-void way:
>>
>> (void) c;
>
> Ok, but, out of interest, what stops the compiler ignoring that?
I don't know. That's a pattern people have been using ages,
it may be special cased.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 5+ messages in thread
* [OB PATCH] Improve -Wunused-value testcase build failures fix
2020-06-23 11:41 ` Pedro Alves
2020-06-23 11:45 ` Gary Benson
@ 2020-06-23 14:13 ` Gary Benson
1 sibling, 0 replies; 5+ messages in thread
From: Gary Benson @ 2020-06-23 14:13 UTC (permalink / raw)
To: gdb-patches
This commit improves upon my previous -Wunused-value fix by
replacing the various dummy variables with casts to void, as
suggested by Pedro.
gdb/testsuite/ChangeLog:
* gdb.cp/namespace.cc: Improve -Wunused-value fix.
* gdb.cp/nsimport.cc: Likewise.
* gdb.cp/nsnested.cc: Likewise.
* gdb.cp/nsnoimports.cc: Likewise.
* gdb.cp/nsusing.cc: Likewise.
* gdb.cp/smartp.cc: Likewise.
* gdb.python/py-pp-integral.c: Likewise.
* gdb.python/py-pp-re-notag.c: Likewise.
---
gdb/testsuite/ChangeLog | 12 ++++++++++++
gdb/testsuite/gdb.cp/namespace.cc | 22 +++++++++++-----------
gdb/testsuite/gdb.cp/nsimport.cc | 6 +++---
gdb/testsuite/gdb.cp/nsnested.cc | 2 +-
gdb/testsuite/gdb.cp/nsnoimports.cc | 12 ++++++------
gdb/testsuite/gdb.cp/nsusing.cc | 12 ++++++------
gdb/testsuite/gdb.cp/smartp.cc | 8 ++++----
gdb/testsuite/gdb.python/py-pp-integral.c | 4 ++--
gdb/testsuite/gdb.python/py-pp-re-notag.c | 4 ++--
9 files changed, 47 insertions(+), 35 deletions(-)
diff --git a/gdb/testsuite/gdb.cp/namespace.cc b/gdb/testsuite/gdb.cp/namespace.cc
index 1ff3426..8c78a7e 100644
--- a/gdb/testsuite/gdb.cp/namespace.cc
+++ b/gdb/testsuite/gdb.cp/namespace.cc
@@ -150,22 +150,22 @@ namespace C
// plan to have GDB try to print out, just to make sure that the
// compiler and I agree which ones should be legal! It's easy
// to screw up when testing the boundaries of namespace stuff.
- int unused1 = c;
+ (void) c;
//cc;
- int unused2 = C::cc;
- int unused3 = cd;
+ (void) C::cc;
+ (void) cd;
//C::D::cd;
- int unused4 = E::cde;
- int unused5 = shadow;
+ (void) E::cde;
+ (void) shadow;
//E::ce;
- int unused6 = cX;
- int unused7 = F::cXf;
- int unused8 = F::cXfX;
- int unused9 = X;
- int unusedA = G::Xg;
+ (void) cX;
+ (void) F::cXf;
+ (void) F::cXfX;
+ (void) X;
+ (void) G::Xg;
//cXOtherFile;
//XOtherFile;
- int unusedB = G::XgX;
+ (void) G::XgX;
return;
}
diff --git a/gdb/testsuite/gdb.cp/nsimport.cc b/gdb/testsuite/gdb.cp/nsimport.cc
index 5fc57b0..92a1090 100644
--- a/gdb/testsuite/gdb.cp/nsimport.cc
+++ b/gdb/testsuite/gdb.cp/nsimport.cc
@@ -13,8 +13,8 @@ namespace{
int main()
{
- int unused1 = x;
- int unused2 = xx;
- int unused3 = xxx;
+ (void) x;
+ (void) xx;
+ (void) xxx;
return 0;
}
diff --git a/gdb/testsuite/gdb.cp/nsnested.cc b/gdb/testsuite/gdb.cp/nsnested.cc
index fc3e11f..ec992b2 100644
--- a/gdb/testsuite/gdb.cp/nsnested.cc
+++ b/gdb/testsuite/gdb.cp/nsnested.cc
@@ -15,7 +15,7 @@ namespace C
int
second()
{
- int unused = ab;
+ (void) ab;
return 0;
}
}
diff --git a/gdb/testsuite/gdb.cp/nsnoimports.cc b/gdb/testsuite/gdb.cp/nsnoimports.cc
index 9968c35..e3ea874 100644
--- a/gdb/testsuite/gdb.cp/nsnoimports.cc
+++ b/gdb/testsuite/gdb.cp/nsnoimports.cc
@@ -18,9 +18,9 @@ namespace A
}
int first(){
- int unused1 = _a;
- int unused2 = ab;
- int unused3 = C::abc;
+ (void) _a;
+ (void) ab;
+ (void) C::abc;
return C::second();
}
}
@@ -30,8 +30,8 @@ namespace A
int
main()
{
- int unused1 = A::_a;
- int unused2 = A::B::ab;
- int unused3 = A::B::C::abc;
+ (void) A::_a;
+ (void) A::B::ab;
+ (void) A::B::C::abc;
return A::B::first();
}
diff --git a/gdb/testsuite/gdb.cp/nsusing.cc b/gdb/testsuite/gdb.cp/nsusing.cc
index 980a91a..fa5c9d0 100644
--- a/gdb/testsuite/gdb.cp/nsusing.cc
+++ b/gdb/testsuite/gdb.cp/nsusing.cc
@@ -35,7 +35,7 @@ namespace L
using namespace J;
int marker8 ()
{
- int unused = jx;
+ (void) jx;
return K::marker9 ();
}
}
@@ -53,7 +53,7 @@ namespace I
int marker7 ()
{
using namespace G::H;
- int unused = ghx;
+ (void) ghx;
return L::marker8 ();
}
}
@@ -69,7 +69,7 @@ namespace E
using namespace E::F;
int marker6 ()
{
- int unused = efx;
+ (void) efx;
return I::marker7 ();
}
@@ -92,7 +92,7 @@ namespace D
using namespace C;
int marker5 ()
{
- int unused = cc;
+ (void) cc;
return marker6 ();
}
@@ -110,7 +110,7 @@ int marker3 ()
int marker2 ()
{
namespace B = A;
- int unused = B::_a;
+ (void) B::_a;
return marker3 ();
}
@@ -134,6 +134,6 @@ int marker1 ()
int main ()
{
using namespace A;
- int unused = _a;
+ (void) _a;
return marker1 ();
}
diff --git a/gdb/testsuite/gdb.cp/smartp.cc b/gdb/testsuite/gdb.cp/smartp.cc
index ed52102..eaae77f 100644
--- a/gdb/testsuite/gdb.cp/smartp.cc
+++ b/gdb/testsuite/gdb.cp/smartp.cc
@@ -131,12 +131,12 @@ int main(){
sp3->foo(1);
sp3->foo('a');
- int unused1 = sp4->a;
- int unused2 = sp4->b;
+ (void) sp4->a;
+ (void) sp4->b;
Type4 *mt4p = &mt4;
- int unused3 = mt4p->a;
- int unused4 = mt4p->b;
+ (void) mt4p->a;
+ (void) mt4p->b;
A a;
B b;
diff --git a/gdb/testsuite/gdb.python/py-pp-integral.c b/gdb/testsuite/gdb.python/py-pp-integral.c
index eadb466..cd7c914 100644
--- a/gdb/testsuite/gdb.python/py-pp-integral.c
+++ b/gdb/testsuite/gdb.python/py-pp-integral.c
@@ -17,10 +17,10 @@
typedef long time_t;
-static time_t
+static void
tick_tock (time_t *t)
{
- return *t++;
+ (void) *t++;
}
int
diff --git a/gdb/testsuite/gdb.python/py-pp-re-notag.c b/gdb/testsuite/gdb.python/py-pp-re-notag.c
index eadb466..cd7c914 100644
--- a/gdb/testsuite/gdb.python/py-pp-re-notag.c
+++ b/gdb/testsuite/gdb.python/py-pp-re-notag.c
@@ -17,10 +17,10 @@
typedef long time_t;
-static time_t
+static void
tick_tock (time_t *t)
{
- return *t++;
+ (void) *t++;
}
int
--
1.8.3.1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-06-23 14:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 11:26 [OB PATCH] Avoid testcase build failures with -Wunused-value Gary Benson
2020-06-23 11:41 ` Pedro Alves
2020-06-23 11:45 ` Gary Benson
2020-06-23 11:53 ` Pedro Alves
2020-06-23 14:13 ` [OB PATCH] Improve -Wunused-value testcase build failures fix Gary Benson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox