From 96f14006f55ac11e82e33913f765101c28b00d27 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 31 Aug 2016 13:22:43 +0000 Subject: [PATCH] selftest.c: avoid explicit "selftest::" qualifiers gcc/ChangeLog: * selftest.c: Move "namespace selftest {" to top of file, removing explicit "selftest::" qualifiers throughout. From-SVN: r239892 --- gcc/ChangeLog | 5 ++++ gcc/selftest.c | 78 +++++++++++++++++++++++--------------------------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e9dfc9186a9..4f113217423 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-08-31 David Malcolm + + * selftest.c: Move "namespace selftest {" to top of file, + removing explicit "selftest::" qualifiers throughout. + 2016-08-31 Marc Glisse * config/i386/avx512fintrin.h (__m512_u, __m512i_u, __m512d_u): diff --git a/gcc/selftest.c b/gcc/selftest.c index e6c95105522..69d9931fbe7 100644 --- a/gcc/selftest.c +++ b/gcc/selftest.c @@ -24,12 +24,14 @@ along with GCC; see the file COPYING3. If not see #if CHECKING_P -int selftest::num_passes; +namespace selftest { + +int num_passes; /* Record the successful outcome of some aspect of a test. */ void -selftest::pass (const location &/*loc*/, const char */*msg*/) +pass (const location &/*loc*/, const char */*msg*/) { num_passes++; } @@ -37,7 +39,7 @@ selftest::pass (const location &/*loc*/, const char */*msg*/) /* Report the failed outcome of some aspect of a test and abort. */ void -selftest::fail (const location &loc, const char *msg) +fail (const location &loc, const char *msg) { fprintf (stderr,"%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line, loc.m_function, msg); @@ -47,7 +49,7 @@ selftest::fail (const location &loc, const char *msg) /* As "fail", but using printf-style formatted output. */ void -selftest::fail_formatted (const location &loc, const char *fmt, ...) +fail_formatted (const location &loc, const char *fmt, ...) { va_list ap; @@ -65,26 +67,23 @@ selftest::fail_formatted (const location &loc, const char *fmt, ...) to be non-NULL; fail gracefully if either are NULL. */ void -selftest::assert_streq (const location &loc, - const char *desc_expected, const char *desc_actual, - const char *val_expected, const char *val_actual) +assert_streq (const location &loc, + const char *desc_expected, const char *desc_actual, + const char *val_expected, const char *val_actual) { /* If val_expected is NULL, the test is buggy. Fail gracefully. */ if (val_expected == NULL) - ::selftest::fail_formatted - (loc, "ASSERT_STREQ (%s, %s) expected=NULL", - desc_expected, desc_actual); + fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=NULL", + desc_expected, desc_actual); /* If val_actual is NULL, fail with a custom error message. */ if (val_actual == NULL) - ::selftest::fail_formatted - (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=NULL", - desc_expected, desc_actual, val_expected); + fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=NULL", + desc_expected, desc_actual, val_expected); if (0 == strcmp (val_expected, val_actual)) - ::selftest::pass (loc, "ASSERT_STREQ"); + pass (loc, "ASSERT_STREQ"); else - ::selftest::fail_formatted - (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"", - desc_expected, desc_actual, val_expected, val_actual); + fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"", + desc_expected, desc_actual, val_expected, val_actual); } /* Implementation detail of ASSERT_STR_CONTAINS. @@ -93,36 +92,35 @@ selftest::assert_streq (const location &loc, ::selftest::fail if it is not found. */ void -selftest::assert_str_contains (const location &loc, - const char *desc_haystack, - const char *desc_needle, - const char *val_haystack, - const char *val_needle) +assert_str_contains (const location &loc, + const char *desc_haystack, + const char *desc_needle, + const char *val_haystack, + const char *val_needle) { /* If val_haystack is NULL, fail with a custom error message. */ if (val_haystack == NULL) - ::selftest::fail_formatted - (loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=NULL", - desc_haystack, desc_needle); + fail_formatted (loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=NULL", + desc_haystack, desc_needle); /* If val_needle is NULL, fail with a custom error message. */ if (val_needle == NULL) - ::selftest::fail_formatted - (loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=\"%s\" needle=NULL", - desc_haystack, desc_needle, val_haystack); + fail_formatted (loc, + "ASSERT_STR_CONTAINS (%s, %s) haystack=\"%s\" needle=NULL", + desc_haystack, desc_needle, val_haystack); const char *test = strstr (val_haystack, val_needle); if (test) - ::selftest::pass (loc, "ASSERT_STR_CONTAINS"); + pass (loc, "ASSERT_STR_CONTAINS"); else - ::selftest::fail_formatted + fail_formatted (loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=\"%s\" needle=\"%s\"", desc_haystack, desc_needle, val_haystack, val_needle); } /* Constructor. Generate a name for the file. */ -selftest::named_temp_file::named_temp_file (const char *suffix) +named_temp_file::named_temp_file (const char *suffix) { m_filename = make_temp_file (suffix); ASSERT_NE (m_filename, NULL); @@ -130,7 +128,7 @@ selftest::named_temp_file::named_temp_file (const char *suffix) /* Destructor. Delete the tempfile. */ -selftest::named_temp_file::~named_temp_file () +named_temp_file::~named_temp_file () { unlink (m_filename); diagnostics_file_cache_forcibly_evict_file (m_filename); @@ -141,23 +139,20 @@ selftest::named_temp_file::~named_temp_file () it. Abort if anything goes wrong, using LOC as the effective location in the problem report. */ -selftest::temp_source_file::temp_source_file (const location &loc, - const char *suffix, - const char *content) +temp_source_file::temp_source_file (const location &loc, + const char *suffix, + const char *content) : named_temp_file (suffix) { FILE *out = fopen (get_filename (), "w"); if (!out) - ::selftest::fail_formatted (loc, "unable to open tempfile: %s", - get_filename ()); + fail_formatted (loc, "unable to open tempfile: %s", get_filename ()); fprintf (out, "%s", content); fclose (out); } /* Selftests for the selftest system itself. */ -namespace selftest { - /* Sanity-check the ASSERT_ macros with various passing cases. */ static void @@ -181,9 +176,8 @@ test_named_temp_file () named_temp_file t (".txt"); FILE *f = fopen (t.get_filename (), "w"); if (!f) - selftest::fail_formatted (SELFTEST_LOCATION, - "unable to open %s for writing", - t.get_filename ()); + fail_formatted (SELFTEST_LOCATION, + "unable to open %s for writing", t.get_filename ()); fclose (f); } -- 2.30.2