public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94255] New: template specialization in different namespace causes crash
@ 2020-03-21 23:50 vince.a.bridgers at gmail dot com
2020-03-22 0:10 ` [Bug c++/94255] " vince.a.bridgers at gmail dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: vince.a.bridgers at gmail dot com @ 2020-03-21 23:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
Bug ID: 94255
Summary: template specialization in different namespace causes
crash
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vince.a.bridgers at gmail dot com
Target Milestone: ---
I encountered this issue using gcc/g++ 6.2.0, then 8.2.0, the tried trunk that
I built on rhel7. g++ crashes when trying to compile code with template
specialization in different namespace. I know this is incorrect code, but I
wouldn't expect g++ to crash. For reference, clang 8.0.0 compiles this and
gives an error.
----
Last git hash in log
commit 9def91e9f2a7051c9c146f16c1a10d1b25d33b47
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Mar 19 22:56:20 2020 +0100
---
Configure step for custom, trunk build ...
../gcc/configure --enable-languages=c,c++ --disable-multilib
--prefix=<home>/gcc-install
----
$ g++ --version
g++ (GCC) 10.0.1 20200319 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----
$ g++ gcc-test.cpp
gcc-test.cpp:15:38: error: specialization of ‘template<class T, class EnablerT>
struct clang::DynTypedNode::BaseConverter’ in different namespace
[-fpermissive]
15 | template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
| ^~~~~~~~~~~~~~~~~~~~~~~~
gcc-test.cpp:5:60: note: from definition of ‘template<class T, class
EnablerT> struct clang::DynTypedNode::BaseConverter’
5 | template <typename T, typename EnablerT = void> struct
BaseConverter;
|
^~~~~~~~~~~~~
g++: internal compiler error: Segmentation fault signal terminated program
cc1plus
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
----
cat test.cpp ...
namespace clang {
class DynTypedNode {
private:
template <typename T, typename EnablerT = void> struct BaseConverter;
template <typename T> struct ValueConverter {};
};
namespace ast_type_traits {
using DynTypedNode = ::clang::DynTypedNode;
}; // end namespace ast_type_traits
}; // end namespace clang
namespace clang {
namespace ast_type_traits {
template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
}; // end namespace ast_type_traits
}; // end namespace clang
int main(void) {
return 0;
}
---
cat gcc-test.ii ...
# 1 "gcc-test.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "gcc-test.cpp"
namespace clang {
class DynTypedNode {
private:
template <typename T, typename EnablerT = void> struct BaseConverter;
template <typename T> struct ValueConverter {};
};
namespace ast_type_traits {
using DynTypedNode = ::clang::DynTypedNode;
};
};
namespace clang {
namespace ast_type_traits {
template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
};
};
int main(void) {
return 0;
}
----
$ clang --version
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /app/vbuild/RHEL7-x86_64/clang/8.0.0/bin
$ clang test.cpp
gcc-test.cpp:15:38: error: class template specialization of 'BaseConverter' not
in class 'DynTypedNode' or an enclosing namespace
template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
^
gcc-test.cpp:5:60: note: explicitly specialized declaration is here
template <typename T, typename EnablerT = void> struct BaseConverter;
^
1 error generated.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94255] template specialization in different namespace causes crash
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
@ 2020-03-22 0:10 ` vince.a.bridgers at gmail dot com
2020-03-22 4:15 ` xerofoify at gmail dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: vince.a.bridgers at gmail dot com @ 2020-03-22 0:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
--- Comment #1 from Vince Bridgers <vince.a.bridgers at gmail dot com> ---
The corrected code successfully compiles. Basically, making sure the template
specialization is in the correct namespace.
namespace clang {
class DynTypedNode {
private:
template <typename T, typename EnablerT = void> struct BaseConverter;
template <typename T> struct ValueConverter {};
};
namespace ast_type_traits {
using DynTypedNode = ::clang::DynTypedNode;
}; // end namespace ast_type_traits
}; // end namespace clang
namespace clang {
//namespace ast_type_traits {
template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
//}; // end namespace ast_type_traits
}; // end namespace clang
int main(void) {
return 0;
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94255] template specialization in different namespace causes crash
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
2020-03-22 0:10 ` [Bug c++/94255] " vince.a.bridgers at gmail dot com
@ 2020-03-22 4:15 ` xerofoify at gmail dot com
2020-03-22 4:15 ` xerofoify at gmail dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: xerofoify at gmail dot com @ 2020-03-22 4:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
Nicholas Krause <xerofoify at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at redhat dot com,
| |xerofoify at gmail dot com
--- Comment #2 from Nicholas Krause <xerofoify at gmail dot com> ---
I've managed to track this down to what appears to me to be a issue in:
tree
push_inner_scope (tree inner)
{
tree outer = current_scope ();
if (!outer)
outer = current_namespace;
push_inner_scope_r (outer, inner);
return outer;
}
I'm not certain if we should just check against NULL_TREE for outer or do we
need to also check against DECL_NAMESPACE as well. CCing Jason Merrill to take
a look at this with his comments.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94255] template specialization in different namespace causes crash
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
2020-03-22 0:10 ` [Bug c++/94255] " vince.a.bridgers at gmail dot com
2020-03-22 4:15 ` xerofoify at gmail dot com
@ 2020-03-22 4:15 ` xerofoify at gmail dot com
2020-03-27 19:47 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: xerofoify at gmail dot com @ 2020-03-22 4:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
--- Comment #3 from Nicholas Krause <xerofoify at gmail dot com> ---
I've managed to track this down to what appears to me to be a issue in:
tree
push_inner_scope (tree inner)
{
tree outer = current_scope ();
if (!outer)
outer = current_namespace;
push_inner_scope_r (outer, inner);
return outer;
}
I'm not certain if we should just check against NULL_TREE for outer or do we
need to also check against DECL_NAMESPACE as well. CCing Jason Merrill to take
a look at this with his comments.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94255] template specialization in different namespace causes crash
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
` (2 preceding siblings ...)
2020-03-22 4:15 ` xerofoify at gmail dot com
@ 2020-03-27 19:47 ` mpolacek at gcc dot gnu.org
2020-04-18 3:48 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-03-27 19:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2020-03-27
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed, started with r0-113135-g28704289327e4295928663b5bab7953718f71bc1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94255] template specialization in different namespace causes crash
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
` (3 preceding siblings ...)
2020-03-27 19:47 ` mpolacek at gcc dot gnu.org
@ 2020-04-18 3:48 ` mpolacek at gcc dot gnu.org
2020-04-20 19:26 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-18 3:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
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> ---
Testing a patch.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94255] template specialization in different namespace causes crash
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
` (4 preceding siblings ...)
2020-04-18 3:48 ` mpolacek at gcc dot gnu.org
@ 2020-04-20 19:26 ` mpolacek at gcc dot gnu.org
2020-05-07 18:12 ` cvs-commit at gcc dot gnu.org
2020-05-07 18:12 ` mpolacek at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-20 19:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch approved for GCC 11:
https://gcc.gnu.org/pipermail/gcc-patches/2020-April/544081.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94255] template specialization in different namespace causes crash
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
` (5 preceding siblings ...)
2020-04-20 19:26 ` mpolacek at gcc dot gnu.org
@ 2020-05-07 18:12 ` cvs-commit at gcc dot gnu.org
2020-05-07 18:12 ` mpolacek at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-07 18:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:21968d4ae067e3fa1c1728c8db26478e8ac8ad0b
commit r11-175-g21968d4ae067e3fa1c1728c8db26478e8ac8ad0b
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Apr 17 23:48:11 2020 -0400
c++: Fix crash with template spec in different namespace [PR94255]
This is an ICE on invalid, because we're specializing S::foo in the
wrong namespace. cp_parser_class_specifier_1 parses S::foo in M
and then it tries to push the nested-name-specifier of foo, which is
S. By that, we're breaking the assumption of push_inner_scope that
the pushed scope must be a scope nested inside current scope: current
scope is M, but the namespace context of S is N, and N is not nested
in M, so we fell into an infinite loop in push_inner_scope_r.
(cp_parser_class_head called check_specialization_namespace which already
gave a permerror.)
PR c++/94255
* parser.c (cp_parser_class_specifier_1): Check that the scope is
nested inside current scope before pushing it.
* g++.dg/template/spec41.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94255] template specialization in different namespace causes crash
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
` (6 preceding siblings ...)
2020-05-07 18:12 ` cvs-commit at gcc dot gnu.org
@ 2020-05-07 18:12 ` mpolacek at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-07 18:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94255
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 11.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-05-07 18:12 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-21 23:50 [Bug c++/94255] New: template specialization in different namespace causes crash vince.a.bridgers at gmail dot com
2020-03-22 0:10 ` [Bug c++/94255] " vince.a.bridgers at gmail dot com
2020-03-22 4:15 ` xerofoify at gmail dot com
2020-03-22 4:15 ` xerofoify at gmail dot com
2020-03-27 19:47 ` mpolacek at gcc dot gnu.org
2020-04-18 3:48 ` mpolacek at gcc dot gnu.org
2020-04-20 19:26 ` mpolacek at gcc dot gnu.org
2020-05-07 18:12 ` cvs-commit at gcc dot gnu.org
2020-05-07 18:12 ` 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).