On 10/4/19 8:17 AM, kamlesh kumar wrote:
bootstrapped and regtested on x86_64.
ChangeLog:
2019-10-04 Kamlesh Kumar <kamleshbha...@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.
Thanks! Word wrap from gmail mangled your patch a bit, so next time
please attach it instead, or see
https://git-scm.com/docs/git-format-patch#_mua_specific_hints
It looks like you don't have a copyright assignment on file; this patch
is small enough not to need one, but larger patches will. The form for
starting this process can be found at
http://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/Copyright/request-assign.future
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index eb1b062a49b..8467e77f7ac 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -276,7 +276,9 @@ get_tinfo_decl_dynamic (tree exp, tsubst_flags_t
complain)
type = non_reference (unlowered_expr_type (exp));
/* Peel off cv qualifiers. */
- type = TYPE_MAIN_VARIANT (type);
+ if (TREE_CODE (type) != FUNCTION_TYPE
+ || cxx_dialect < cxx17)
+ type = TYPE_MAIN_VARIANT (type);
Since what we're trying to do is strip cv-qualifiers, we might as well
use the cv_unqualified function.
/* For UNKNOWN_TYPEs call complete_type_or_else to get diagnostics. */
if (CLASS_TYPE_P (type) || type == unknown_type_node
@@ -298,6 +300,8 @@ get_tinfo_decl_dynamic (tree exp, tsubst_flags_t
complain)
t = build_vtbl_ref (exp, index);
t = convert (type_info_ptr_type, t);
}
+ else if(TREE_CODE (type) == FUNCTION_TYPE)
+ t = get_tinfo_ptr (type);
else
/* Otherwise return the type_info for the static type of the expr. */
t = get_tinfo_ptr (TYPE_MAIN_VARIANT (type));
And the TYPE_MAIN_VARIANT here was redundant, so we can just drop it.
diff --git a/gcc/testsuite/g++.dg/rtti/pr83534.C
b/gcc/testsuite/g++.dg/rtti/pr83534.C
new file mode 100644
index 00000000000..405ea5c2af4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/pr83534.C
@@ -0,0 +1,14 @@
+// { 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)))
+ abort();
This failed for me due to using abort without #include <stdlib.h>
Here's what I'm committing:
commit dd14a7b9d1397cf365153ebbe48802873480464e
Author: kamlesh kumar <kamleshbha...@gmail.com>
Date: Fri Oct 4 17:47:28 2019 +0530
PR c++/83434 - typeinfo for noexcept function lacks noexcept information
2019-10-21 Kamlesh Kumar <kamleshbha...@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 <ja...@redhat.com>
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index eb1b062a49b..c905799481e 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -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
index 00000000000..af5f02ebb92
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/pr83534.C
@@ -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();
+}