Commit 9821a48d authored by Lynn Garren's avatar Lynn Garren

using __attribute__((unused)) in tests

parent 10cdd9f0
2015-05-27 Lynn Garren <garren@fnal.gov>
* use __attribute__((unused)) for variables only used in assert inside a test
affects Geometry, Random, Utility, and Vector
* Random/Random/Randomize.h: protect against unused variable warning
* Utility/Utility/memory.h: protect against non virtual destructor warning
==============================
10.02.15 Release CLHEP-2.2.0.5
==============================
......
remove_definitions(-DNDEBUG)
clhep_test( testBasicVector3D )
clhep_test( testBug6740 SIMPLE )
......@@ -38,7 +38,7 @@ using namespace HepGeom;
\
/* Check conversion to array */ \
const point p05(1,2,3); \
const type * a = p05; \
const type * a __attribute__((unused)) = p05; \
assert(a[0] == 1 && a[1] == 2 && a[2] == 3); \
point p06(4,5,6); \
a = p06; \
......@@ -223,34 +223,12 @@ using namespace HepGeom;
assert(p121 != Normal3D<type> (2,4,7)); \
// don't generate warnings about unused variables inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
#endif
#ifdef __clang__
#if __clang_major__ < 4
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
#endif
#endif
void CheckPointFloat() { CHECK(Point3D<float> , float) }
void CheckVectorFloat() { CHECK(Vector3D<float> , float) }
void CheckNormalFloat() { CHECK(Normal3D<float> , float) }
void CheckPointDouble() { CHECK(Point3D<double> , double) }
void CheckVectorDouble() { CHECK(Vector3D<double>, double) }
void CheckNormalDouble() { CHECK(Normal3D<double>, double) }
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#if __clang_major__ < 4
#pragma clang diagnostic pop
#endif
#endif
int main()
{
......
......@@ -60,6 +60,20 @@
#include "CLHEP/Random/RandSkewNormal.h"
#include "CLHEP/Random/RandStudentT.h"
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#if __GNUC__ > 4
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
namespace CLHEP {
#define HepUniformRand() HepRandom::getTheEngine()->flat()
......@@ -69,7 +83,19 @@ namespace CLHEP {
static const int HepRandomGenActive = HepRandom::createInstance();
} // namespace CLHEP
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#if __GNUC__ > 4
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#ifdef ENABLE_BACKWARDS_COMPATIBILITY
// backwards compatibility will be enabled ONLY in CLHEP 1.9
......
remove_definitions(-DNDEBUG)
set( Random_tests testRandom
testRandDists )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
......
......@@ -36,6 +36,10 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
#endif
#if __GNUC__ > 4
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
......@@ -1490,6 +1494,9 @@ do_nothing_deleter::operator () ( void const * ) const
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#if __GNUC__ > 4
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
......
remove_definitions(-DNDEBUG)
set( Utility_simple_tests testNoncopyable
testPrimaryTraits
testCategories
......
......@@ -369,16 +369,6 @@ typedef const double (UDT::*mp2) ;
// don't generate warnings about unused variables inside asserts
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-local-typedefs"
#endif
int
main()
{
......@@ -397,12 +387,12 @@ int
assert(evaluate<char const >() == cat_int);
assert(evaluate<char volatile >() == cat_int);
assert(evaluate<char const volatile >() == cat_int);
typedef signed char schar;
typedef signed char schar __attribute__((unused));
assert(evaluate<schar >() == cat_int);
assert(evaluate<schar const >() == cat_int);
assert(evaluate<schar volatile >() == cat_int);
assert(evaluate<schar const volatile >() == cat_int);
typedef unsigned char uchar;
typedef unsigned char uchar __attribute__((unused));
assert(evaluate<uchar >() == cat_int);
assert(evaluate<uchar const >() == cat_int);
assert(evaluate<uchar volatile >() == cat_int);
......@@ -411,7 +401,7 @@ int
assert(evaluate<short const >() == cat_int);
assert(evaluate<short volatile >() == cat_int);
assert(evaluate<short const volatile >() == cat_int);
typedef unsigned short ushort;
typedef unsigned short ushort __attribute__((unused));
assert(evaluate<ushort >() == cat_int);
assert(evaluate<ushort const >() == cat_int);
assert(evaluate<ushort volatile >() == cat_int);
......@@ -420,7 +410,7 @@ int
assert(evaluate<int const >() == cat_int);
assert(evaluate<int volatile >() == cat_int);
assert(evaluate<int const volatile >() == cat_int);
typedef unsigned int uint;
typedef unsigned int uint __attribute__((unused));
assert(evaluate<uint >() == cat_int);
assert(evaluate<uint const >() == cat_int);
assert(evaluate<uint volatile >() == cat_int);
......@@ -429,7 +419,7 @@ int
assert(evaluate<long const >() == cat_int);
assert(evaluate<long volatile >() == cat_int);
assert(evaluate<long const volatile >() == cat_int);
typedef unsigned long ulong;
typedef unsigned long ulong __attribute__((unused));
assert(evaluate<ulong >() == cat_int);
assert(evaluate<ulong const >() == cat_int);
assert(evaluate<ulong volatile >() == cat_int);
......@@ -444,7 +434,7 @@ int
assert(evaluate<double const >() == cat_flt);
assert(evaluate<double volatile >() == cat_flt);
assert(evaluate<double const volatile >() == cat_flt);
typedef long double ldouble;
typedef long double ldouble __attribute__((unused));
assert(evaluate<ldouble >() == cat_flt);
assert(evaluate<ldouble const >() == cat_flt);
assert(evaluate<ldouble volatile >() == cat_flt);
......@@ -555,11 +545,3 @@ int
return 0;
}
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
......@@ -370,63 +370,27 @@ void
int m = 0;
// don't generate warnings about unused parameter inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
void
deleter(int * p)
{
assert(p == 0);
}
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
void
deleter2(int * p)
deleter2(int * p __attribute__((unused)))
{
assert(p == &m);
++*p;
}
// don't generate warnings about unused parameter inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
struct deleter3
{
void operator()(incomplete * p)
void operator()(incomplete * p __attribute__((unused)))
{
assert(p == 0);
}
};
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
incomplete * p0 = 0;
......@@ -996,19 +960,9 @@ void
}
// don't generate warnings about unused variable q
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
{
std::auto_ptr<int> p(new int(7));
int * q = p.get();
int * q __attribute__((unused))= p.get();
shared_ptr<int> pi(p);
assert(pi? true: false);
assert(!!pi);
......@@ -1022,7 +976,7 @@ void
{
std::auto_ptr<int> p(new int(7));
int * q = p.get();
int * q __attribute__((unused))= p.get();
shared_ptr<int const> pi(p);
assert(pi? true: false);
assert(!!pi);
......@@ -1036,7 +990,7 @@ void
{
std::auto_ptr<int> p(new int(7));
int * q = p.get();
int * q __attribute__((unused))= p.get();
shared_ptr<void> pv(p);
assert(pv? true: false);
assert(!!pv);
......@@ -1049,7 +1003,7 @@ void
{
std::auto_ptr<int> p(new int(7));
int * q = p.get();
int * q __attribute__((unused))= p.get();
shared_ptr<void const> pv(p);
assert(pv? true: false);
assert(!!pv);
......@@ -1064,7 +1018,7 @@ void
{
std::auto_ptr<X> p(new X);
X * q = p.get();
X * q __attribute__((unused)) = p.get();
shared_ptr<X> px(p);
assert(px? true: false);
assert(!!px);
......@@ -1080,7 +1034,7 @@ void
{
std::auto_ptr<X> p(new X);
X * q = p.get();
X * q __attribute__((unused)) = p.get();
shared_ptr<X const> px(p);
assert(px? true: false);
assert(!!px);
......@@ -1096,7 +1050,7 @@ void
{
std::auto_ptr<X> p(new X);
X * q = p.get();
X * q __attribute__((unused)) = p.get();
shared_ptr<void> pv(p);
assert(pv? true: false);
assert(!!pv);
......@@ -1112,7 +1066,7 @@ void
{
std::auto_ptr<X> p(new X);
X * q = p.get();
X * q __attribute__((unused)) = p.get();
shared_ptr<void const> pv(p);
assert(pv? true: false);
assert(!!pv);
......@@ -1129,7 +1083,7 @@ void
{
std::auto_ptr<Y> p(new Y);
Y * q = p.get();
Y * q __attribute__((unused)) = p.get();
shared_ptr<X> px(p);
assert(px? true: false);
assert(!!px);
......@@ -1147,7 +1101,7 @@ void
{
std::auto_ptr<Y> p(new Y);
Y * q = p.get();
Y * q __attribute__((unused)) = p.get();
shared_ptr<X const> px(p);
assert(px? true: false);
assert(!!px);
......@@ -1159,14 +1113,6 @@ void
assert(p.get() == 0);
}
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
assert(X::instances == 0);
assert(Y::instances == 0);
......
......@@ -42,16 +42,6 @@ int * get_object()
{ return &++cnt; }
// don't generate warnings about unused parameter inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
void release_object(int * p)
{
assert(p == &cnt);
......@@ -64,14 +54,6 @@ template< class T >
assert(p->id() == 1);
assert((*p).id() == 1);
}
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
template< class T >
void test_is_X(weak_ptr<T> const & p)
......@@ -81,30 +63,12 @@ template< class T >
}
// don't generate warnings about unused parameter inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
template< class T >
void test_is_Y(shared_ptr<T> const & p)
{
assert(p->id() == 2);
assert((*p).id() == 2);
}
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
template< class T >
void test_is_Y(weak_ptr<T> const & p)
......@@ -115,16 +79,6 @@ template< class T >
}
// don't generate warnings about unused parameter inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
template< class T >
void test_eq(T const & a, T const & b)
{
......@@ -187,26 +141,8 @@ template< class T >
assert(p? true: false);
assert(p.get() != 0);
}
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
// don't generate warnings about unused variable inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
int main()
{
......@@ -309,8 +245,8 @@ int main()
weak_ptr<X> wp5;
bool b1 = wp1 < wp5;
bool b2 = wp5 < wp1;
bool b1 __attribute__((unused)) = wp1 < wp5;
bool b2 __attribute__((unused)) = wp5 < wp1;
p5.reset();
......@@ -336,11 +272,3 @@ int main()
return 0;
} // main()
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
......@@ -993,16 +993,6 @@ namespace n_comparison
{
// don't generate warnings about unused variable inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
void
test()
{
......@@ -1028,8 +1018,8 @@ void
assert(wp < wp2 || wp2 < wp);
assert(!(wp < wp2 && wp2 < wp));
bool b1 = wp < wp2;
bool b2 = wp2 < wp;
bool b1 __attribute__((unused)) = wp < wp2;
bool b2 __attribute__((unused)) = wp2 < wp;
{
weak_ptr<X> wp3(wp);
......@@ -1077,8 +1067,8 @@ void
assert(wp < wp2 || wp2 < wp);
assert(!(wp < wp2 && wp2 < wp));
bool b1 = wp < wp2;
bool b2 = wp2 < wp;
bool b1 __attribute__((unused)) = wp < wp2;
bool b2 __attribute__((unused)) = wp2 < wp;
{
weak_ptr<X> wp3(wp);
......@@ -1146,8 +1136,8 @@ void
assert(!(wp < wp2 || wp2 < wp));
assert(!(wp < wp2 && wp2 < wp));
bool b1 = wp < wp2;
bool b2 = wp2 < wp;
bool b1 __attribute__((unused)) = wp < wp2;
bool b2 __attribute__((unused)) = wp2 < wp;
{
weak_ptr<X> wp3(wp);
......@@ -1283,14 +1273,6 @@ void
assert(!(pvy < pvz || pvz < pvy));
}
}
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
} // namespace n_comparison
......
remove_definitions(-DNDEBUG)
set( Vector_tests testThreeVector
testLorentzVector )
set( Vector_simple_tests testRotation
......
......@@ -22,22 +22,12 @@ typedef Hep3Vector Vector;
#define DEL 10.e-16
// don't generate warnings about unused variables inside assert
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
int main() {
int i,k;
double angA=CLHEP::pi/3, angB=CLHEP::pi/4, angC=CLHEP::pi/6;
double cosA=std::cos(angA), sinA=std::sin(angA);
double cosB=std::cos(angB), sinB=std::sin(angB);
double cosC=std::cos(angC), sinC=std::sin(angC);
double cosA __attribute__((unused))=std::cos(angA), sinA __attribute__((unused))=std::sin(angA);
double cosB __attribute__((unused))=std::cos(angB), sinB __attribute__((unused))=std::sin(angB);
double cosC __attribute__((unused))=std::cos(angC), sinC __attribute__((unused))=std::sin(angC);
Rotation R; // default constructor
assert ( R.xx() == 1 );
......@@ -215,11 +205,3 @@ int main() {
return 0;