Void cast runtime-unused variables. Patch from STL@microsoft.com

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@268284 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-05-02 19:15:48 +00:00
parent 61a220ae5b
commit a9ea11398d
23 changed files with 69 additions and 15 deletions

View File

@@ -19,6 +19,7 @@
int main() int main()
{ {
jmp_buf jb; jmp_buf jb;
((void)jb); // Prevent unused warning
static_assert((std::is_same<decltype(longjmp(jb, 0)), void>::value), static_assert((std::is_same<decltype(longjmp(jb, 0)), void>::value),
"std::is_same<decltype(longjmp(jb, 0)), void>::value"); "std::is_same<decltype(longjmp(jb, 0)), void>::value");
} }

View File

@@ -108,10 +108,16 @@ int main()
{ {
FILE* fp = 0; FILE* fp = 0;
fpos_t fpos = {0}; fpos_t fpos = {0};
size_t s = 0; ((void)s); size_t s = 0;
char* cp = 0; char* cp = 0;
char arr[] = {'a', 'b'}; char arr[] = {'a', 'b'};
va_list va; va_list va;
((void)fp); // Prevent unused warning
((void)fpos); // Prevent unused warning
((void)s); // Prevent unused warning
((void)cp); // Prevent unused warning
((void)arr); // Prevent unused warning
((void)va); // Prevent unused warning
static_assert((std::is_same<decltype(remove("")), int>::value), ""); static_assert((std::is_same<decltype(remove("")), int>::value), "");
static_assert((std::is_same<decltype(rename("","")), int>::value), ""); static_assert((std::is_same<decltype(rename("","")), int>::value), "");
static_assert((std::is_same<decltype(tmpfile()), FILE*>::value), ""); static_assert((std::is_same<decltype(tmpfile()), FILE*>::value), "");

View File

@@ -91,6 +91,11 @@ int main()
std::size_t s = 0; std::size_t s = 0;
char* cp = 0; char* cp = 0;
std::va_list va; std::va_list va;
((void)fp); // Prevent unused warning
((void)fpos); // Prevent unused warning
((void)s); // Prevent unused warning
((void)cp); // Prevent unused warning
((void)va); // Prevent unused warning
static_assert((std::is_same<decltype(std::fclose(fp)), int>::value), ""); static_assert((std::is_same<decltype(std::fclose(fp)), int>::value), "");
static_assert((std::is_same<decltype(std::fflush(fp)), int>::value), ""); static_assert((std::is_same<decltype(std::fflush(fp)), int>::value), "");
static_assert((std::is_same<decltype(std::setbuf(fp,cp)), void>::value), ""); static_assert((std::is_same<decltype(std::setbuf(fp,cp)), void>::value), "");

View File

@@ -56,7 +56,7 @@ void test_hex(const char *expected)
assert(str == expected); assert(str == expected);
} }
int main(int argc, char* argv[]) int main()
{ {
test_octal<uint16_t>( "177777"); test_octal<uint16_t>( "177777");

View File

@@ -17,6 +17,7 @@
int main() int main()
{ {
std::bidirectional_iterator_tag tag; std::bidirectional_iterator_tag tag;
((void)tag); // Prevent unused warning
static_assert((std::is_base_of<std::forward_iterator_tag, static_assert((std::is_base_of<std::forward_iterator_tag,
std::bidirectional_iterator_tag>::value), ""); std::bidirectional_iterator_tag>::value), "");
static_assert((!std::is_base_of<std::output_iterator_tag, static_assert((!std::is_base_of<std::output_iterator_tag,

View File

@@ -17,6 +17,7 @@
int main() int main()
{ {
std::forward_iterator_tag tag; std::forward_iterator_tag tag;
((void)tag); // Prevent unused warning
static_assert((std::is_base_of<std::input_iterator_tag, static_assert((std::is_base_of<std::input_iterator_tag,
std::forward_iterator_tag>::value), ""); std::forward_iterator_tag>::value), "");
static_assert((!std::is_base_of<std::output_iterator_tag, static_assert((!std::is_base_of<std::output_iterator_tag,

View File

@@ -17,6 +17,7 @@
int main() int main()
{ {
std::input_iterator_tag tag; std::input_iterator_tag tag;
((void)tag); // Prevent unused warning
static_assert((!std::is_base_of<std::output_iterator_tag, static_assert((!std::is_base_of<std::output_iterator_tag,
std::input_iterator_tag>::value), ""); std::input_iterator_tag>::value), "");
} }

View File

@@ -17,6 +17,7 @@
int main() int main()
{ {
std::output_iterator_tag tag; std::output_iterator_tag tag;
((void)tag); // Prevent unused warning
static_assert((!std::is_base_of<std::input_iterator_tag, static_assert((!std::is_base_of<std::input_iterator_tag,
std::output_iterator_tag>::value), ""); std::output_iterator_tag>::value), "");
} }

View File

@@ -17,6 +17,7 @@
int main() int main()
{ {
std::random_access_iterator_tag tag; std::random_access_iterator_tag tag;
((void)tag); // Prevent unused warning
static_assert((std::is_base_of<std::bidirectional_iterator_tag, static_assert((std::is_base_of<std::bidirectional_iterator_tag,
std::random_access_iterator_tag>::value), ""); std::random_access_iterator_tag>::value), "");
static_assert((!std::is_base_of<std::output_iterator_tag, static_assert((!std::is_base_of<std::output_iterator_tag,

View File

@@ -112,7 +112,7 @@ int main()
std::throw_with_nested(Final()); std::throw_with_nested(Final());
assert(false); assert(false);
} }
catch (const Final &f) catch (const Final &)
{ {
} }
} }

View File

@@ -74,7 +74,7 @@ int main()
throw A(); throw A();
assert(false); assert(false);
} }
catch (A& a) catch (A&)
{ {
std::exception_ptr p = std::current_exception(); std::exception_ptr p = std::current_exception();
assert(A::constructed == 1); assert(A::constructed == 1);
@@ -94,7 +94,7 @@ int main()
throw A(); throw A();
assert(false); assert(false);
} }
catch (A a) catch (A)
{ {
std::exception_ptr p = std::current_exception(); std::exception_ptr p = std::current_exception();
assert(A::constructed == 2); assert(A::constructed == 2);

View File

@@ -19,6 +19,7 @@
int main() int main()
{ {
std::jmp_buf jb; std::jmp_buf jb;
((void)jb); // Prevent unused warning
static_assert((std::is_same<decltype(std::longjmp(jb, 0)), void>::value), static_assert((std::is_same<decltype(std::longjmp(jb, 0)), void>::value),
"std::is_same<decltype(std::longjmp(jb, 0)), void>::value"); "std::is_same<decltype(std::longjmp(jb, 0)), void>::value");
} }

View File

@@ -23,10 +23,13 @@
int main() int main()
{ {
std::clock_t c = 0; std::clock_t c = 0;
((void)c);
std::size_t s = 0; std::size_t s = 0;
std::time_t t = 0; std::time_t t = 0;
std::tm tm = {0}; std::tm tm = {0};
((void)c); // Prevent unused warning
((void)s); // Prevent unused warning
((void)t); // Prevent unused warning
((void)tm); // Prevent unused warning
static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");
@@ -39,5 +42,7 @@ int main()
#endif #endif
char* c1 = 0; char* c1 = 0;
const char* c2 = 0; const char* c2 = 0;
((void)c1); // Prevent unused warning
((void)c2); // Prevent unused warning
static_assert((std::is_same<decltype(std::strftime(c1,s,c2,&tm)), std::size_t>::value), ""); static_assert((std::is_same<decltype(std::strftime(c1,s,c2,&tm)), std::size_t>::value), "");
} }

View File

@@ -47,6 +47,7 @@
int main() int main()
{ {
std::lconv lc; std::lconv lc;
((void)lc); // Prevent unused warning
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
static_assert((std::is_same<decltype(std::setlocale(0, "")), char*>::value), ""); static_assert((std::is_same<decltype(std::setlocale(0, "")), char*>::value), "");
#endif #endif

View File

@@ -24415,7 +24415,6 @@ void test11()
void test12() void test12()
{ {
char str[200];
output_iterator<char*> iter; output_iterator<char*> iter;
std::locale lc = std::locale::classic(); std::locale lc = std::locale::classic();
std::locale lg(lc, new my_numpunct); std::locale lg(lc, new my_numpunct);
@@ -24423,6 +24422,7 @@ void test12()
// This test is failing on FreeBSD, possibly due to different representations // This test is failing on FreeBSD, possibly due to different representations
// of the floating point numbers. // of the floating point numbers.
const my_facet f(1); const my_facet f(1);
char str[200];
{ {
long double v = 1234567890.125; long double v = 1234567890.125;
std::ios ios(0); std::ios ios(0);
@@ -26221,7 +26221,6 @@ int main()
test10(); test10();
test11(); test11();
test12(); test12();
char str[200];
output_iterator<char*> iter; output_iterator<char*> iter;
std::locale lc = std::locale::classic(); std::locale lc = std::locale::classic();
std::locale lg(lc, new my_numpunct); std::locale lg(lc, new my_numpunct);

View File

@@ -62,6 +62,8 @@ int main()
{ {
std::fenv_t fenv; std::fenv_t fenv;
std::fexcept_t fex; std::fexcept_t fex;
((void)fenv); // Prevent unused warning
((void)fex); // Prevent unused warning
static_assert((std::is_same<decltype(std::feclearexcept(0)), int>::value), ""); static_assert((std::is_same<decltype(std::feclearexcept(0)), int>::value), "");
static_assert((std::is_same<decltype(std::fegetexceptflag(&fex, 0)), int>::value), ""); static_assert((std::is_same<decltype(std::fegetexceptflag(&fex, 0)), int>::value), "");
static_assert((std::is_same<decltype(std::feraiseexcept(0)), int>::value), ""); static_assert((std::is_same<decltype(std::feraiseexcept(0)), int>::value), "");

View File

@@ -30,7 +30,7 @@ int main()
r(); r();
assert(false); assert(false);
} }
catch (const std::system_error& e) catch (const std::system_error&)
{ {
} }
} }

View File

@@ -35,7 +35,7 @@ extern "C" void LLVMFuzzerTestOneInput(const char *data)
std::regex re(s, flag); std::regex re(s, flag);
std::regex_match(s, re); std::regex_match(s, re);
} }
catch (std::regex_error &ex) {} catch (std::regex_error &) {}
} }
} }

View File

@@ -40,6 +40,16 @@ int main()
char* ns = 0; char* ns = 0;
wchar_t* ws = 0; wchar_t* ws = 0;
((void)mb); // Prevent unused warning
((void)s); // Prevent unused warning
((void)tm); // Prevent unused warning
((void)w); // Prevent unused warning
((void)fp); // Prevent unused warning
((void)va); // Prevent unused warning
((void)ns); // Prevent unused warning
((void)ws); // Prevent unused warning
static_assert((std::is_same<decltype(std::fwprintf(fp, L"")), int>::value), ""); static_assert((std::is_same<decltype(std::fwprintf(fp, L"")), int>::value), "");
static_assert((std::is_same<decltype(std::fwscanf(fp, L"")), int>::value), ""); static_assert((std::is_same<decltype(std::fwscanf(fp, L"")), int>::value), "");
static_assert((std::is_same<decltype(std::swprintf(ws, s, L"")), int>::value), ""); static_assert((std::is_same<decltype(std::swprintf(ws, s, L"")), int>::value), "");

View File

@@ -38,6 +38,9 @@ void test_pointer()
typename std::allocator_traits<Alloc>::pointer vp; typename std::allocator_traits<Alloc>::pointer vp;
typename std::allocator_traits<Alloc>::const_pointer cvp; typename std::allocator_traits<Alloc>::const_pointer cvp;
((void)vp); // Prevent unused warning
((void)cvp); // Prevent unused warning
static_assert(std::is_same<bool, decltype( vp == vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
static_assert(std::is_same<bool, decltype( vp != vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
static_assert(std::is_same<bool, decltype( vp > vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");
@@ -72,6 +75,9 @@ void test_void_pointer()
typename std::allocator_traits<Alloc>::void_pointer vp; typename std::allocator_traits<Alloc>::void_pointer vp;
typename std::allocator_traits<Alloc>::const_void_pointer cvp; typename std::allocator_traits<Alloc>::const_void_pointer cvp;
((void)vp); // Prevent unused warning
((void)cvp); // Prevent unused warning
static_assert(std::is_same<bool, decltype( vp == vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
static_assert(std::is_same<bool, decltype( vp != vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
static_assert(std::is_same<bool, decltype( vp > vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");

View File

@@ -37,6 +37,9 @@ void test_pointer()
typename std::allocator_traits<Alloc>::pointer vp; typename std::allocator_traits<Alloc>::pointer vp;
typename std::allocator_traits<Alloc>::const_pointer cvp; typename std::allocator_traits<Alloc>::const_pointer cvp;
((void)vp); // Prevent unused warning
((void)cvp); // Prevent unused warning
static_assert(std::is_same<bool, decltype( vp == vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
static_assert(std::is_same<bool, decltype( vp != vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
static_assert(std::is_same<bool, decltype( vp > vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");
@@ -71,6 +74,9 @@ void test_void_pointer()
typename std::allocator_traits<Alloc>::void_pointer vp; typename std::allocator_traits<Alloc>::void_pointer vp;
typename std::allocator_traits<Alloc>::const_void_pointer cvp; typename std::allocator_traits<Alloc>::const_void_pointer cvp;
((void)vp); // Prevent unused warning
((void)cvp); // Prevent unused warning
static_assert(std::is_same<bool, decltype( vp == vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
static_assert(std::is_same<bool, decltype( vp != vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
static_assert(std::is_same<bool, decltype( vp > vp)>::value, ""); static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");

View File

@@ -21,11 +21,15 @@
int main() int main()
{ {
std::clock_t c = 0; std::clock_t c = 0;
((void)c); // avoid unused warning
std::size_t s = 0; std::size_t s = 0;
std::time_t t = 0; std::time_t t = 0;
std::tm tm = {0}; std::tm tm = {0};
char str[3]; char str[3];
((void)c); // Prevent unused warning
((void)s); // Prevent unused warning
((void)t); // Prevent unused warning
((void)tm); // Prevent unused warning
((void)str); // Prevent unused warning
static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");

View File

@@ -39,6 +39,9 @@ int main()
A a; A a;
const A ca = A(); const A ca = A();
((void)a); // Prevent unused warning
((void)ca); // Prevent unused warning
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); static_assert(sizeof(test(std::forward<A&>(a))) == 1, "");
static_assert(sizeof(test(std::forward<A>(a))) == 4, ""); static_assert(sizeof(test(std::forward<A>(a))) == 4, "");