public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896
@ 2022-07-11 18:57 gscfq@t-online.de
2022-07-11 19:23 ` [Bug c++/106259] [10/11/12/13 Regression] " mpolacek at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: gscfq@t-online.de @ 2022-07-11 18:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
Bug ID: 106259
Summary: ICE in diag_mismatched_tags, at cp/parser.cc:33896
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gscfq@t-online.de
Target Milestone: ---
Started with r10 and file g++.dg/template/dependent-name11.C :
$ gcc-13-20220710 -c dependent-name11.C -Wmismatched-tags
dependent-name11.C:15:1: internal compiler error: in diag_mismatched_tags, at
cp/parser.cc:33896
15 | }
| ^
0x904c4d class_decl_loc_t::diag_mismatched_tags(tree_node*)
../../gcc/cp/parser.cc:33896
0x90b465 class_decl_loc_t::diag_mismatched_tags()
../../gcc/cp/parser.cc:34018
0x9550cd c_parse_file()
../../gcc/cp/parser.cc:48482
0xae8181 c_common_parse_file()
../../gcc/c-family/c-opts.cc:1235
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11/12/13 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
@ 2022-07-11 19:23 ` mpolacek at gcc dot gnu.org
2022-07-11 19:29 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-11 19:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|ICE in |[10/11/12/13 Regression]
|diag_mismatched_tags, at |ICE in
|cp/parser.cc:33896 |diag_mismatched_tags, at
| |cp/parser.cc:33896
Target Milestone|--- |10.5
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
CC| |mpolacek at gcc dot gnu.org,
| |msebor at gcc dot gnu.org
Priority|P3 |P2
Last reconfirmed| |2022-07-11
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.
commit 04dd734b52de121853e1ea6b3c197a598b294e23
Author: Martin Sebor <msebor@gmail.com>
Date: Fri Mar 27 12:07:45 2020 -0400
c++: avoid -Wredundant-tags on a first declaration in use [PR 93824]
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11/12/13 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
2022-07-11 19:23 ` [Bug c++/106259] [10/11/12/13 Regression] " mpolacek at gcc dot gnu.org
@ 2022-07-11 19:29 ` mpolacek at gcc dot gnu.org
2023-02-28 20:43 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-11 19:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Looks like
struct A<int>::W<U>
isn't in the class2loc hash table so we crash here:
33894 tree spec = specialization_of (type);
33895 cdlguide = class2loc.get (spec);
33896 gcc_assert (cdlguide != NULL);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11/12/13 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
2022-07-11 19:23 ` [Bug c++/106259] [10/11/12/13 Regression] " mpolacek at gcc dot gnu.org
2022-07-11 19:29 ` mpolacek at gcc dot gnu.org
@ 2023-02-28 20:43 ` mpolacek at gcc dot gnu.org
2023-03-01 16:12 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-28 20:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
// PR c++/106259
// { dg-do compile { target c++11 } }
template<typename T> struct A {
template<typename U>
struct W { };
};
template<>
struct A<char> {
template<typename U>
class W { };
};
void
g ()
{
struct A<char>::W<int> w1; // warn
struct A<int>::W<int> w2; // dont warn
class A<char>::W<int> w3; // dont warn
class A<int>::W<int> w4; // warn
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11/12/13 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
` (2 preceding siblings ...)
2023-02-28 20:43 ` mpolacek at gcc dot gnu.org
@ 2023-03-01 16:12 ` mpolacek at gcc dot gnu.org
2023-03-01 17:05 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-01 16:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I know, in principle, how to fix it, but currently I'm struggling with getting
struct A<T>::W<U>
from
struct A<int>::W<U>
That we haven't found struct A<int>::W<U> in class2loc is actually OK, we don't
have a A<int> specialization, so we should see if W in the primary template A
was defined with class or struct.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11/12/13 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
` (3 preceding siblings ...)
2023-03-01 16:12 ` mpolacek at gcc dot gnu.org
@ 2023-03-01 17:05 ` mpolacek at gcc dot gnu.org
2023-03-02 16:02 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-01 17:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Ah, this does what I want:
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -34473,6 +34473,12 @@ class_decl_loc_t::diag_mismatched_tags (tree
type_decl)
be (and inevitably is) at index zero. */
tree spec = specialization_of (type);
cdlguide = class2loc.get (spec);
+ if (!cdlguide)
+ {
+ spec = most_general_template (spec);
+ spec = TYPE_MAIN_DECL (TREE_TYPE (spec));
+ cdlguide = class2loc.get (spec);
+ }
gcc_assert (cdlguide != NULL);
}
else
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11/12/13 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
` (4 preceding siblings ...)
2023-03-01 17:05 ` mpolacek at gcc dot gnu.org
@ 2023-03-02 16:02 ` cvs-commit at gcc dot gnu.org
2023-03-02 16:06 ` [Bug c++/106259] [10/11/12 " mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-02 16:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:71afd0628419c5d670701cb35bc9860380c7d9fb
commit r13-6417-g71afd0628419c5d670701cb35bc9860380c7d9fb
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Mar 1 14:28:46 2023 -0500
c++: ICE with -Wmismatched-tags and member template [PR106259]
-Wmismatched-tags warns about the (harmless) struct/class mismatch.
For, e.g.,
template<typename T> struct A { };
class A<int> a;
it works by adding A<T> to the class2loc hash table while parsing the
class-head and then, while parsing the elaborate type-specifier, we
add A<int>. At the end of c_parse_file we go through the table and
warn about the class-key mismatches. In this PR we crash though; we
have
template<typename T> struct A {
template<typename U> struct W { };
};
struct A<int>::W<int> w; // #1
where while parsing A and #1 we've stashed
A<T>
A<T>::W<U>
A<int>::W<int>
into class2loc. Then in class_decl_loc_t::diag_mismatched_tags TYPE
is A<int>::W<int>, and specialization_of gets us A<int>::W<U>, which
is not in class2loc, so we crash on gcc_assert (cdlguide). But it's
OK not to have found A<int>::W<U>, we should just look one "level" up,
that is, A<T>::W<U>.
It's important to handle class specializations, so e.g.
template<>
struct A<char> {
template<typename U>
class W { };
};
where W's class-key is different than in the primary template above,
so we should warn depending on whether we're looking into A<char>
or into a different instantiation.
PR c++/106259
gcc/cp/ChangeLog:
* parser.cc (class_decl_loc_t::diag_mismatched_tags): If the first
lookup of SPEC didn't find anything, try to look for
most_general_template.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wmismatched-tags-11.C: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11/12 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
` (5 preceding siblings ...)
2023-03-02 16:02 ` cvs-commit at gcc dot gnu.org
@ 2023-03-02 16:06 ` mpolacek at gcc dot gnu.org
2023-03-04 17:52 ` cvs-commit at gcc dot gnu.org
2023-03-04 18:16 ` [Bug c++/106259] [10/11 " mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-02 16:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[10/11/12/13 Regression] |[10/11/12 Regression] ICE
|ICE in |in diag_mismatched_tags, at
|diag_mismatched_tags, at |cp/parser.cc:33896
|cp/parser.cc:33896 |
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11/12 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
` (6 preceding siblings ...)
2023-03-02 16:06 ` [Bug c++/106259] [10/11/12 " mpolacek at gcc dot gnu.org
@ 2023-03-04 17:52 ` cvs-commit at gcc dot gnu.org
2023-03-04 18:16 ` [Bug c++/106259] [10/11 " mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-04 17:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:3a2310d4b229e707bbc5440150bf180e0499273a
commit r12-9217-g3a2310d4b229e707bbc5440150bf180e0499273a
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Mar 1 14:28:46 2023 -0500
c++: ICE with -Wmismatched-tags and member template [PR106259]
-Wmismatched-tags warns about the (harmless) struct/class mismatch.
For, e.g.,
template<typename T> struct A { };
class A<int> a;
it works by adding A<T> to the class2loc hash table while parsing the
class-head and then, while parsing the elaborate type-specifier, we
add A<int>. At the end of c_parse_file we go through the table and
warn about the class-key mismatches. In this PR we crash though; we
have
template<typename T> struct A {
template<typename U> struct W { };
};
struct A<int>::W<int> w; // #1
where while parsing A and #1 we've stashed
A<T>
A<T>::W<U>
A<int>::W<int>
into class2loc. Then in class_decl_loc_t::diag_mismatched_tags TYPE
is A<int>::W<int>, and specialization_of gets us A<int>::W<U>, which
is not in class2loc, so we crash on gcc_assert (cdlguide). But it's
OK not to have found A<int>::W<U>, we should just look one "level" up,
that is, A<T>::W<U>.
It's important to handle class specializations, so e.g.
template<>
struct A<char> {
template<typename U>
class W { };
};
where W's class-key is different than in the primary template above,
so we should warn depending on whether we're looking into A<char>
or into a different instantiation.
PR c++/106259
gcc/cp/ChangeLog:
* parser.cc (class_decl_loc_t::diag_mismatched_tags): If the first
lookup of SPEC didn't find anything, try to look for
most_general_template.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wmismatched-tags-11.C: New test.
(cherry picked from commit 71afd0628419c5d670701cb35bc9860380c7d9fb)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106259] [10/11 Regression] ICE in diag_mismatched_tags, at cp/parser.cc:33896
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
` (7 preceding siblings ...)
2023-03-04 17:52 ` cvs-commit at gcc dot gnu.org
@ 2023-03-04 18:16 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-04 18:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106259
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Summary|[10/11/12 Regression] ICE |[10/11 Regression] ICE in
|in diag_mismatched_tags, at |diag_mismatched_tags, at
|cp/parser.cc:33896 |cp/parser.cc:33896
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-03-04 18:16 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-11 18:57 [Bug c++/106259] New: ICE in diag_mismatched_tags, at cp/parser.cc:33896 gscfq@t-online.de
2022-07-11 19:23 ` [Bug c++/106259] [10/11/12/13 Regression] " mpolacek at gcc dot gnu.org
2022-07-11 19:29 ` mpolacek at gcc dot gnu.org
2023-02-28 20:43 ` mpolacek at gcc dot gnu.org
2023-03-01 16:12 ` mpolacek at gcc dot gnu.org
2023-03-01 17:05 ` mpolacek at gcc dot gnu.org
2023-03-02 16:02 ` cvs-commit at gcc dot gnu.org
2023-03-02 16:06 ` [Bug c++/106259] [10/11/12 " mpolacek at gcc dot gnu.org
2023-03-04 17:52 ` cvs-commit at gcc dot gnu.org
2023-03-04 18:16 ` [Bug c++/106259] [10/11 " mpolacek at gcc dot gnu.org
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).