c++: Fix ICE with -Wmismatched-tags [PR105725]
authorMarek Polacek <polacek@redhat.com>
Fri, 27 May 2022 14:51:30 +0000 (10:51 -0400)
committerMarek Polacek <polacek@redhat.com>
Fri, 27 May 2022 16:07:35 +0000 (12:07 -0400)
commit2c11a9a380e7af333e19d6e576a889646d699b2a
treea5751b403fa6be45c9919332d5ca945db734ff89
parent57fdcaf17d4b5b9dc4bb72840f882d2e7e6294ef
c++: Fix ICE with -Wmismatched-tags [PR105725]

Here we ICE with -Wmismatched-tags on something like

  template <class T>
  bool B<T, enable_if_t<is_class_v<class T::foo>>>;

Specifically, the "class T::foo" bit.  There, class_decl_loc_t::add gets
a TYPENAME_TYPE as TYPE, rather than a class/union type, so checking
TYPE_BEING_DEFINED will crash.  I think it's OK to allow a TYPENAME_TYPE to
slip into that function; we just shouldn't consider the 'class' tag redundant
(which works as a 'typename').  In fact, every other compiler *requires* it.

PR c++/105725

gcc/cp/ChangeLog:

* parser.cc (class_decl_loc_t::add): Check CLASS_TYPE_P.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wmismatched-tags-10.C: New test.

(cherry picked from commit d822f4bbd714c6595f70cc68888dcebecfb6662d)
gcc/cp/parser.cc
gcc/testsuite/g++.dg/warn/Wmismatched-tags-10.C [new file with mode: 0644]