PR c++/83434 - typeinfo for noexcept function lacks noexcept information
authorKamlesh Kumar <kamleshbhalui@gmail.com>
Mon, 21 Oct 2019 20:19:28 +0000 (20:19 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 21 Oct 2019 20:19:28 +0000 (16:19 -0400)
2019-10-21  Kamlesh Kumar  <kamleshbhalui@gmail.com>

        * rtti.c (get_tinfo_decl_dynamic): Do not call
        TYPE_MAIN_VARIANT for function.
        (get_typeid): Likewise.

        * g++.dg/rtti/pr83534.C: New Test.

Reviewed-by: Jason Merrill <jason@redhat.com>
Co-Authored-By: Jason Merrill <jason@redhat.com>
From-SVN: r277270

gcc/cp/ChangeLog
gcc/cp/rtti.c
gcc/testsuite/g++.dg/rtti/pr83534.C [new file with mode: 0644]

index 19a687a4b795b760a610c2b2f0448715c5131af0..4218901b854175fc82f9f155478a34e87a57d5b7 100644 (file)
@@ -1,3 +1,11 @@
+2019-10-21  Kamlesh Kumar  <kamleshbhalui@gmail.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/83434 - typeinfo of noexcept function
+       * rtti.c (get_tinfo_decl_dynamic): Do not call
+       TYPE_MAIN_VARIANT for function.
+       (get_typeid): Likewise.
+
 2019-10-21  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * parser.c (cp_parser_class_head): Improve error recovery upon
index eb1b062a49b04df23b30f4536bd81260b4510a66..c905799481ea3ee1f28a068e866e8cd421fb29ad 100644 (file)
@@ -272,11 +272,11 @@ get_tinfo_decl_dynamic (tree exp, tsubst_flags_t complain)
 
   exp = resolve_nondeduced_context (exp, complain);
 
-  /* peel back references, so they match.  */
+  /* Peel back references, so they match.  */
   type = non_reference (unlowered_expr_type (exp));
 
   /* Peel off cv qualifiers.  */
-  type = TYPE_MAIN_VARIANT (type);
+  type = cv_unqualified (type);
 
   /* For UNKNOWN_TYPEs call complete_type_or_else to get diagnostics.  */
   if (CLASS_TYPE_P (type) || type == unknown_type_node
@@ -300,7 +300,7 @@ get_tinfo_decl_dynamic (tree exp, tsubst_flags_t complain)
     }
   else
     /* Otherwise return the type_info for the static type of the expr.  */
-    t = get_tinfo_ptr (TYPE_MAIN_VARIANT (type));
+    t = get_tinfo_ptr (type);
 
   return cp_build_fold_indirect_ref (t);
 }
@@ -518,7 +518,7 @@ get_typeid (tree type, tsubst_flags_t complain)
 
   /* The top-level cv-qualifiers of the lvalue expression or the type-id
      that is the operand of typeid are always ignored.  */
-  type = TYPE_MAIN_VARIANT (type);
+  type = cv_unqualified (type);
 
   /* For UNKNOWN_TYPEs call complete_type_or_else to get diagnostics.  */
   if (CLASS_TYPE_P (type) || type == unknown_type_node
diff --git a/gcc/testsuite/g++.dg/rtti/pr83534.C b/gcc/testsuite/g++.dg/rtti/pr83534.C
new file mode 100644 (file)
index 0000000..af5f02e
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-options "-std=c++17" }
+// { dg-do run }
+
+#include <typeinfo>
+
+void f1();
+void f2() noexcept;
+int main() {
+  if((typeid(void()) == typeid(void ()noexcept))
+     || (typeid(&f1) == typeid(&f2))
+     || (typeid(f1) == typeid(f2)))
+    __builtin_abort();
+}