-Wmissing-attributes: check that we avoid duplicates and false positives
The initial patch for PR 81824 fixed various possibilities of -Wmissing-attributes reporting duplicates and false positives. The test that avoided them was a little obscure, though, so this patch rewrites it into a more self-evident form. The patch also adds a testcase that already passed, but that explicitly covers some of the possibilities of reporting duplicates and false positives that preexisting tests did not cover. for gcc/ChangeLog PR middle-end/81824 * attribs.c (decls_mismatched_attributes): Simplify the logic that avoids duplicates and false positives. for gcc/testsuite/ChangeLog PR middle-end/81824 * g++.dg/Wmissing-attributes-1.C: New. Some of its fragments are from Martin Sebor. From-SVN: r273563
This commit is contained in:
parent
8ea3c020a2
commit
dea7843167
@ -1,3 +1,9 @@
|
|||||||
|
2019-07-17 Alexandre Oliva <oliva@adacore.com>
|
||||||
|
|
||||||
|
PR middle-end/81824
|
||||||
|
* attribs.c (decls_mismatched_attributes): Simplify the logic
|
||||||
|
that avoids duplicates and false positives.
|
||||||
|
|
||||||
2019-07-17 John David Anglin <danglin@gcc.gnu.org>
|
2019-07-17 John David Anglin <danglin@gcc.gnu.org>
|
||||||
|
|
||||||
* config/pa/pa.c (pa_som_asm_init_sections): Don't force all constant
|
* config/pa/pa.c (pa_som_asm_init_sections): Don't force all constant
|
||||||
|
@ -1931,15 +1931,19 @@ decls_mismatched_attributes (tree tmpl, tree decl, tree attrlist,
|
|||||||
if (!has_attribute (tmpls[j], tmpl_attrs[j], blacklist[i]))
|
if (!has_attribute (tmpls[j], tmpl_attrs[j], blacklist[i]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
unsigned kmax = 1 + !!decl_attrs[1];
|
unsigned kmax = 1 + !!decl_attrs[1];
|
||||||
for (unsigned k = 0; k != kmax; ++k)
|
for (unsigned k = 0; k != kmax; ++k)
|
||||||
{
|
{
|
||||||
if (has_attribute (decls[k], decl_attrs[k], blacklist[i]))
|
if (has_attribute (decls[k], decl_attrs[k], blacklist[i]))
|
||||||
break;
|
{
|
||||||
|
found = true;
|
||||||
if (!k && kmax > 1)
|
break;
|
||||||
continue;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
if (nattrs)
|
if (nattrs)
|
||||||
pp_string (attrstr, ", ");
|
pp_string (attrstr, ", ");
|
||||||
pp_begin_quote (attrstr, pp_show_color (global_dc->printer));
|
pp_begin_quote (attrstr, pp_show_color (global_dc->printer));
|
||||||
@ -1947,6 +1951,8 @@ decls_mismatched_attributes (tree tmpl, tree decl, tree attrlist,
|
|||||||
pp_end_quote (attrstr, pp_show_color (global_dc->printer));
|
pp_end_quote (attrstr, pp_show_color (global_dc->printer));
|
||||||
++nattrs;
|
++nattrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
2019-07-17 Alexandre Oliva <oliva@adacore.com>
|
||||||
|
|
||||||
|
PR middle-end/81824
|
||||||
|
* g++.dg/Wmissing-attributes-1.C: New. Some of its fragments
|
||||||
|
are from Martin Sebor.
|
||||||
|
|
||||||
2019-07-17 Marek Polacek <polacek@redhat.com>
|
2019-07-17 Marek Polacek <polacek@redhat.com>
|
||||||
|
|
||||||
PR c++/90455
|
PR c++/90455
|
||||||
|
66
gcc/testsuite/g++.dg/Wmissing-attributes-1.C
Normal file
66
gcc/testsuite/g++.dg/Wmissing-attributes-1.C
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// { dg-do compile }
|
||||||
|
// { dg-options "-Wmissing-attributes" }
|
||||||
|
|
||||||
|
#define ATTR(list) __attribute__ (list)
|
||||||
|
|
||||||
|
/* Type attributes are normally absent in template functions, and the
|
||||||
|
mere presence of any such attribute used to cause the
|
||||||
|
-Wmissing-attributes checks, that checked for attributes typically
|
||||||
|
associated with functions rather than types, to report any missing
|
||||||
|
attributes twice: once for the specialization attribute list, once
|
||||||
|
for its type attribute list.
|
||||||
|
|
||||||
|
This test uses both decl and type attributes to exercise the code
|
||||||
|
that avoids reporting duplicates, in ways that failed in the past
|
||||||
|
but that were not covered in other tests. */
|
||||||
|
typedef void* ATTR ((alloc_size (1))) f_type (int);
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
f_type
|
||||||
|
ATTR ((malloc))
|
||||||
|
missing_malloc; // { dg-message "missing primary template attribute .malloc." }
|
||||||
|
|
||||||
|
template <>
|
||||||
|
f_type
|
||||||
|
missing_malloc<char>; // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" }
|
||||||
|
|
||||||
|
|
||||||
|
/* Check that even an attribute that appears in both lists (decl and
|
||||||
|
type) in a template declaration is reported as missing only
|
||||||
|
once. */
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
f_type
|
||||||
|
ATTR ((alloc_size (1))) // In both attr lists, decl's and type's.
|
||||||
|
missing_alloc_size; // { dg-message "missing primary template attribute .alloc_size." }
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void *
|
||||||
|
missing_alloc_size<char>(int); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" }
|
||||||
|
|
||||||
|
|
||||||
|
/* Check that even an attribute that appears in both lists (decl and
|
||||||
|
type) is not reported as missing if it's present only in the type
|
||||||
|
list. */
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
f_type
|
||||||
|
ATTR ((alloc_size (1))) // In both attr lists, decl's and type's.
|
||||||
|
missing_nothing;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
f_type
|
||||||
|
missing_nothing<char>;
|
||||||
|
|
||||||
|
|
||||||
|
/* For completeness, check that a type attribute is matched by a decl
|
||||||
|
attribute in the specialization. */
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
f_type
|
||||||
|
missing_nothing2;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void *
|
||||||
|
ATTR ((alloc_size (1)))
|
||||||
|
missing_nothing2<char>(int);
|
Loading…
Reference in New Issue
Block a user