public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Sebor <msebor@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6024] Check for class type before assuming a type is one [PR103703].
Date: Thu, 16 Dec 2021 22:13:47 +0000 (GMT)	[thread overview]
Message-ID: <20211216221347.40A673858D28@sourceware.org> (raw)

https://gcc.gnu.org/g:93faac7e32e4f9503c559f2a3e5a4732f5e9ea09

commit r12-6024-g93faac7e32e4f9503c559f2a3e5a4732f5e9ea09
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu Dec 16 15:11:45 2021 -0700

    Check for class type before assuming a type is one [PR103703].
    
    Resolves:
    PR c++/103703 - ICE with -Wmismatched-tags with friends and templates
    
    gcc/cp/ChangeLog:
    
            PR c++/103703
            * parser.c (class_decl_loc_t::diag_mismatched_tags): Check for class
            type before assuming a type is one.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/103703
            * g++.dg/warn/Wmismatched-tags-9.C: New test.

Diff:
---
 gcc/cp/parser.c                                |  2 +-
 gcc/testsuite/g++.dg/warn/Wmismatched-tags-9.C | 32 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 5d72201f87c..9cf74357ac9 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -33527,7 +33527,7 @@ class_decl_loc_t::diag_mismatched_tags (tree type_decl)
   class_decl_loc_t *cdlguide = this;
 
   tree type = TREE_TYPE (type_decl);
-  if (CLASSTYPE_IMPLICIT_INSTANTIATION (type))
+  if (CLASS_TYPE_P (type) && CLASSTYPE_IMPLICIT_INSTANTIATION (type))
     {
       /* For implicit instantiations of a primary template look up
 	 the primary or partial specialization and use it as
diff --git a/gcc/testsuite/g++.dg/warn/Wmismatched-tags-9.C b/gcc/testsuite/g++.dg/warn/Wmismatched-tags-9.C
new file mode 100644
index 00000000000..2712c4de1f6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wmismatched-tags-9.C
@@ -0,0 +1,32 @@
+/* PR c++/103703 - ICE with -Wmismatched-tags with friends and templates
+   { dg-do compile }
+   { dg-options "-Wall -Wmismatched-tags" } */
+
+template <typename T>
+struct A
+{
+  struct B { };
+};
+
+template <typename T>
+struct C
+{
+  friend class A<C>::B;       // { dg-warning "-Wmismatched-tags" "pr102036" { xfail *-*-* } }
+};
+
+template struct C<int>;
+
+
+template <typename T>
+struct D
+{
+  friend class A<D>::B;       // okay, specialized as class below
+};
+
+template <>
+struct A<long>
+{
+  class B { };
+};
+
+template struct D<long>;


                 reply	other threads:[~2021-12-16 22:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211216221347.40A673858D28@sourceware.org \
    --to=msebor@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).