aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-04-17 23:48:11 -0400
committerMarek Polacek <polacek@redhat.com>2020-05-07 14:11:31 -0400
commit21968d4ae067e3fa1c1728c8db26478e8ac8ad0b (patch)
tree7088aed2bf14766d3337f2b58622dcd8a793e059 /gcc/testsuite
parenta5cac223dff2f83b83318ecf4dedc98a98649e2a (diff)
downloadgcc-21968d4ae067e3fa1c1728c8db26478e8ac8ad0b.zip
gcc-21968d4ae067e3fa1c1728c8db26478e8ac8ad0b.tar.gz
gcc-21968d4ae067e3fa1c1728c8db26478e8ac8ad0b.tar.bz2
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.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/template/spec41.C17
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d14d534..bed2d90 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2020-05-07 Marek Polacek <polacek@redhat.com>
+ PR c++/94255
+ * g++.dg/template/spec41.C: New test.
+
+2020-05-07 Marek Polacek <polacek@redhat.com>
+
P1957R2
* g++.dg/cpp0x/initlist92.C: Don't expect an error in C++20 only.
diff --git a/gcc/testsuite/g++.dg/template/spec41.C b/gcc/testsuite/g++.dg/template/spec41.C
new file mode 100644
index 0000000..249fde7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/spec41.C
@@ -0,0 +1,17 @@
+// PR c++/94255 - crash with template spec in different namespace.
+// { dg-do compile { target c++11 } }
+
+namespace N {
+ class S {
+ template <typename> struct foo;
+ };
+ namespace M {
+ using S = ::N::S;
+ }
+}
+
+namespace N {
+ namespace M {
+ template <> struct S::foo<int> {}; // { dg-error "specialization of" }
+ }
+}