[C++ PATCH] c++/92271 - make __is_same alias for __is_same_as.

Marek Polacek polacek@redhat.com
Thu Dec 5 18:11:00 GMT 2019


Richard Smith proposed adding a synonym for __is_same_as, to accomodate the
convention of exposing std::SOME_TRAIT<A, B>::value as __SOME_TRAIT(A, B).

So add that alias, and also adjust the C++ printer.  I didn't bother changing
the RID_ identifier.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-12-05  Marek Polacek  <polacek@redhat.com>

	PR c++/92271 - make __is_same alias for __is_same_as.
	* c-common.c: Add __is_same, an alias for __is_same_as.

	* cxx-pretty-print.c (pp_cxx_trait_expression) <case CPTK_IS_SAME_AS>:
	Print "__is_same".

	* g++.dg/cpp0x/is_same.C: New test.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 2f389d2895a..8292d18621b 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -418,6 +418,7 @@ const struct c_common_resword c_common_reswords[] =
   { "__is_literal_type", RID_IS_LITERAL_TYPE, D_CXXONLY },
   { "__is_pod",		RID_IS_POD,	D_CXXONLY },
   { "__is_polymorphic",	RID_IS_POLYMORPHIC, D_CXXONLY },
+  { "__is_same",     RID_IS_SAME_AS, D_CXXONLY },
   { "__is_same_as",     RID_IS_SAME_AS, D_CXXONLY },
   { "__is_standard_layout", RID_IS_STD_LAYOUT, D_CXXONLY },
   { "__is_trivial",     RID_IS_TRIVIAL, D_CXXONLY },
diff --git gcc/cp/cxx-pretty-print.c gcc/cp/cxx-pretty-print.c
index 909b2a4ef1d..62805446ba9 100644
--- gcc/cp/cxx-pretty-print.c
+++ gcc/cp/cxx-pretty-print.c
@@ -2661,7 +2661,7 @@ pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
       pp_cxx_ws_string (pp, "__is_polymorphic");
       break;
     case CPTK_IS_SAME_AS:
-      pp_cxx_ws_string (pp, "__is_same_as");
+      pp_cxx_ws_string (pp, "__is_same");
       break;
     case CPTK_IS_STD_LAYOUT:
       pp_cxx_ws_string (pp, "__is_std_layout");
diff --git gcc/testsuite/g++.dg/cpp0x/is_same.C gcc/testsuite/g++.dg/cpp0x/is_same.C
new file mode 100644
index 00000000000..5e9079c5109
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/is_same.C
@@ -0,0 +1,5 @@
+// PR c++/92271 - make __is_same alias for __is_same_as.
+// { dg-do compile { target c++11 } }
+
+static_assert(__is_same(int, int) == __is_same_as(int, int), "");
+static_assert(__is_same(unsigned int, int) == __is_same_as(unsigned int, int), "");



More information about the Gcc-patches mailing list