On 2/28/20 12:45 PM, Martin Sebor wrote:
On 2/28/20 9:58 AM, Jason Merrill wrote:
On 2/24/20 6:58 PM, Martin Sebor wrote:
-Wredundant-tags doesn't consider type declarations that are also
the first uses of the type, such as in 'void f (struct S);' and
issues false positives for those.  According to the reported that's
making it harder to use the warning to clean up LibreOffice.

The attached patch extends -Wredundant-tags to avoid these false
positives by relying on the same class_decl_loc_t::class2loc mapping
as -Wmismatched-tags.  The patch also somewhat improves the detection
of both issues in template declarations (though more work is still
needed there).

+         a new entry for it and return unless it's a declaration
+         involving a template that may need to be diagnosed by
+         -Wredundant-tags.  */
       *rdl = class_decl_loc_t (class_key, false, def_p);
-      return;
+      if (TREE_CODE (decl) != TEMPLATE_DECL)
+        return;

How can the first appearance of a class template be redundant?

I'm not sure I correctly understand the question.  The comment says
"involving a template" (i.e., not one of the first declaration of
a template).  The test case that corresponds to this test is:

   template <class> struct S7 { };
   struct S7<void> s7v;  // { dg-warning "\\\[-Wredundant-tags" }

where DECL is the TEPLATE_DECL of S7<void>.

As I mentioned, more work is still needed to handle templates right
because some redundant tags are still not diagnosed.  For example:

   template <class> struct S7 { };
   template <class T>
   using U = struct S7<T>;   // missing warning

When we get here for an instance of a template, it doesn't make sense to treat it as a new type.

If decl is a template and type_decl is an instance of that template, do we want to (before the lookup) change type_decl to the template or the corresponding generic TYPE_DECL, which should already be in the table?

Jason

Reply via email to