commit 882a90dbfdd776ce33749ae4a44dc89588417a63 Author: Jason Merrill Date: Fri Mar 27 09:56:13 2020 -0400 set def_p and idxguide based on cdlguide diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2f539570aae..3ca8eb9baf8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -31024,6 +31024,12 @@ private: return locvec[i].class_key; } + /* True if a definition for the class has been seen. */ + bool def_p () const + { + return idxdef < locvec.length (); + } + /* The location of a single mention of a class type with the given class-key. */ struct class_key_loc_t @@ -31273,11 +31279,6 @@ class_decl_loc_t::diag_mismatched_tags (tree type_decl) /* Number of uses of the class. */ const unsigned ndecls = locvec.length (); - if (ndecls < 2) - return; - - /* Set if a definition for the class has been seen. */ - const bool def_p = idxdef < ndecls; /* The class (or template) declaration guiding the decisions about the diagnostic. For ordinary classes it's the same as THIS. For @@ -31305,17 +31306,13 @@ class_decl_loc_t::diag_mismatched_tags (tree type_decl) return; } + /* Set if a definition for the class has been seen. */ + const bool def_p = cdlguide->def_p (); + /* The index of the declaration whose class-key this declaration is expected to match. It's either the class-key of the class definition if one exists or the first declaration otherwise. */ - const unsigned idxguide = def_p ? idxdef : 0; - unsigned idx = 0; - /* Advance IDX to the first declaration that either is not - a definition or that doesn't match the first declaration - if no definition is provided. */ - while (class_key (idx) == cdlguide->class_key (idxguide)) - if (++idx == ndecls) - return; + const unsigned idxguide = def_p ? cdlguide->idxdef : 0; /* The class-key the class is expected to be declared with: it's either the key used in its definition or the first declaration @@ -31323,10 +31320,15 @@ class_decl_loc_t::diag_mismatched_tags (tree type_decl) For implicit instantiations of a primary template it's the class-key used to declare the primary with. The primary must be at index zero. */ - const tag_types xpect_key - = cdlguide->class_key (cdlguide == this ? idxguide : 0); - if (cdlguide != this && xpect_key == class_key (idx)) - return; + const tag_types xpect_key = cdlguide->class_key (idxguide); + + unsigned idx = 0; + /* Advance IDX to the first declaration that either is not + a definition or that doesn't match the first declaration + if no definition is provided. */ + while (class_key (idx) == xpect_key) + if (++idx == ndecls) + return; /* Save the current function before changing it below. */ tree save_func = current_function_decl;