c-family PATCH for c++/90953 - ICE with -Wmissing-format-attribute
Marek Polacek
polacek@redhat.com
Fri Jun 21 14:10:00 GMT 2019
These functions are using TREE_PURPOSE to get the attribute name,
which is breaking now that we preserve the C++11-style attribute
format past decl_attributes. So use get_attribute_name which can
handle both formats of attributes.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2019-06-21 Marek Polacek <polacek@redhat.com>
PR c++/90953 - ICE with -Wmissing-format-attribute.
* c-common.c (check_function_arguments_recurse): Use
get_attribute_name.
(check_missing_format_attribute): Likewise.
* g++.dg/warn/miss-format-7.C: New test.
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 4057be3aaed..f5627040067 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -5753,7 +5753,7 @@ check_function_arguments_recurse (void (*callback)
for (attrs = TYPE_ATTRIBUTES (type);
attrs;
attrs = TREE_CHAIN (attrs))
- if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs)))
+ if (is_attribute_p ("format_arg", get_attribute_name (attrs)))
{
tree inner_arg;
tree format_num_expr;
@@ -7601,13 +7601,13 @@ check_missing_format_attribute (tree ltype, tree rtype)
tree ra;
for (ra = TYPE_ATTRIBUTES (ttr); ra; ra = TREE_CHAIN (ra))
- if (is_attribute_p ("format", TREE_PURPOSE (ra)))
+ if (is_attribute_p ("format", get_attribute_name (ra)))
break;
if (ra)
{
tree la;
for (la = TYPE_ATTRIBUTES (ttl); la; la = TREE_CHAIN (la))
- if (is_attribute_p ("format", TREE_PURPOSE (la)))
+ if (is_attribute_p ("format", get_attribute_name (la)))
break;
return !la;
}
diff --git gcc/testsuite/g++.dg/warn/miss-format-7.C gcc/testsuite/g++.dg/warn/miss-format-7.C
new file mode 100644
index 00000000000..ac892dcec6d
--- /dev/null
+++ gcc/testsuite/g++.dg/warn/miss-format-7.C
@@ -0,0 +1,29 @@
+// PR c++/90953 - ICE with -Wmissing-format-attribute.
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wmissing-format-attribute" }
+
+namespace std {
+union [[gnu::may_alias]] _Any_data{};
+enum _Manager_operation { __get_type_info };
+template <typename> class A;
+class B {
+ typedef bool (*_Manager_type)(_Any_data, const _Any_data &,
+ _Manager_operation);
+public:
+ _Any_data _M_functor;
+ _Manager_type _M_manager;
+};
+
+struct type_info { } t;
+
+template <typename _Res, typename... _ArgTypes>
+class A<_Res(_ArgTypes...)> : B {
+ const type_info &target_type() const noexcept;
+};
+template <typename _Res, typename... _ArgTypes>
+const type_info &A<_Res(_ArgTypes...)>::target_type() const noexcept {
+ _Any_data __typeinfo_result;
+ _M_manager(__typeinfo_result, _M_functor, __get_type_info);
+ return t;
+}
+} // namespace std
More information about the Gcc-patches
mailing list