c++: Fix ICE with -Wmismatched-tags [PR93869]
authorMarek Polacek <polacek@redhat.com>
Fri, 21 Feb 2020 17:58:04 +0000 (12:58 -0500)
committerMarek Polacek <polacek@redhat.com>
Mon, 24 Feb 2020 15:48:31 +0000 (10:48 -0500)
commitcae5ff6036a21c9bbe521d615d88e283b80fe695
treee0b5eb1f69f35f2c5d6d4dee1e71c45ed053ab9a
parent27bf39a8035445ffc71b551619d7c1a232498054
c++: Fix ICE with -Wmismatched-tags [PR93869]

This is a crash in cp_parser_check_class_key:
  tree type_decl = TYPE_MAIN_DECL (type);
  tree name = DECL_NAME (type_decl); // HERE
because TYPE_MAIN_DECL of type was null as it's not a class type.
Instead of checking CLASS_TYPE_P we should simply check class_key
a bit earlier (in this case it was typename_type).

2020-02-24  Marek Polacek  <polacek@redhat.com>

PR c++/93869 - ICE with -Wmismatched-tags.
* parser.c (cp_parser_check_class_key): Check class_key earlier.

* g++.dg/warn/Wmismatched-tags-2.C: New test.
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wmismatched-tags-2.C [new file with mode: 0644]