public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Check for class type before assuming a type is one [PR103703]
@ 2021-12-14 22:28 Martin Sebor
  2021-12-15 22:04 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Sebor @ 2021-12-14 22:28 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 282 bytes --]

The attached patch avoids an ICE when using
the CLASSTYPE_IMPLICIT_INSTANTIATION() macro with an argument
that is not a class type but rather a typename_type.

The test case should trigger a warning but doesn't because
the code doesn't fully handle explicit instantiations.

Martin

[-- Attachment #2: gcc-103703.diff --]
[-- Type: text/x-patch, Size: 1665 bytes --]

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):

gcc/testsuite/ChangeLog:

	PR c++/103703
	* g++.dg/warn/Wmismatched-tags-9.C: New test.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 52225d46d4e..d21e1d9de6d 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -33536,7 +33536,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>;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Check for class type before assuming a type is one [PR103703]
  2021-12-14 22:28 [PATCH] Check for class type before assuming a type is one [PR103703] Martin Sebor
@ 2021-12-15 22:04 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-12-15 22:04 UTC (permalink / raw)
  To: Martin Sebor, gcc-patches

On 12/14/21 17:28, Martin Sebor wrote:
> The attached patch avoids an ICE when using
> the CLASSTYPE_IMPLICIT_INSTANTIATION() macro with an argument
> that is not a class type but rather a typename_type.
> 
> The test case should trigger a warning but doesn't because
> the code doesn't fully handle explicit instantiations.

OK, thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-15 22:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 22:28 [PATCH] Check for class type before assuming a type is one [PR103703] Martin Sebor
2021-12-15 22:04 ` Jason Merrill

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).