re PR c++/79420 (ICE on invalid C++ code on x86_64-linux-gnu: in tsubst_copy, at...
authorMarek Polacek <polacek@redhat.com>
Tue, 14 Feb 2017 17:33:21 +0000 (17:33 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 14 Feb 2017 17:33:21 +0000 (17:33 +0000)
PR c++/79420
PR c++/79463
* parser.c (cp_parser_postfix_dot_deref_expression): Avoid
clobbering if the postfix expression isn't an EXPR_P.

* g++.dg/cpp1y/pr79463.C: New.
* g++.dg/template/incomplete10.C: New.
* g++.dg/template/incomplete9.C: New.

From-SVN: r245440

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/pr79463.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/incomplete10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/incomplete9.C [new file with mode: 0644]

index 3d840c5..7b94d3b 100644 (file)
@@ -1,3 +1,10 @@
+2017-02-14  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/79420
+       PR c++/79463
+       * parser.c (cp_parser_postfix_dot_deref_expression): Avoid
+       clobbering if the postfix expression isn't an EXPR_P.
+
 2017-02-13  Jason Merrill  <jason@redhat.com>
 
        PR c++/79461 - ICE with lambda in constexpr constructor
index ce45bba..ccafefd 100644 (file)
@@ -7331,7 +7331,9 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser,
                   (scope, current_class_type))))
        {
          scope = complete_type (scope);
-         if (!COMPLETE_TYPE_P (scope))
+         if (!COMPLETE_TYPE_P (scope)
+             /* Avoid clobbering e.g. OVERLOADs or DECLs.  */
+             && EXPR_P (postfix_expression))
            {
              /* In a template, be permissive by treating an object expression
                 of incomplete type as dependent (after a pedwarn).  */
index 071f38f..be1ea5c 100644 (file)
@@ -1,3 +1,11 @@
+2017-02-14  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/79420
+       PR c++/79463
+       * g++.dg/cpp1y/pr79463.C: New.
+       * g++.dg/template/incomplete10.C: New.
+       * g++.dg/template/incomplete9.C: New.
+
 2017-02-14  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/79498
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr79463.C b/gcc/testsuite/g++.dg/cpp1y/pr79463.C
new file mode 100644 (file)
index 0000000..fdf668b
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/79463
+// { dg-options "-g" }
+// { dg-do compile { target c++14 } }
+
+struct A;
+extern A a; // { dg-error "'a' has incomplete type" }
+template < int > int f = a.x;
diff --git a/gcc/testsuite/g++.dg/template/incomplete10.C b/gcc/testsuite/g++.dg/template/incomplete10.C
new file mode 100644 (file)
index 0000000..f0b406d
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/79420
+
+struct S;
+extern S s; // { dg-error "'s' has incomplete type" }
+template<int> int f ()
+{
+  return s.x;
+}
+
+void g ()
+{
+  f<0> ();
+}
diff --git a/gcc/testsuite/g++.dg/template/incomplete9.C b/gcc/testsuite/g++.dg/template/incomplete9.C
new file mode 100644 (file)
index 0000000..9e03232
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/79420
+
+template<int> int f ()
+{
+  return f.x; // { dg-error "overloaded function with no contextual type information" }
+}
+
+void g ()
+{
+  f<0> ();
+}