This test ICEs since the addition of the assert in pp_string which ensures that
we aren't trying to print an empty string.  But that's what happens here, the
location is actually UNKNOWN_LOCATION, so LOCATION_FILE on that yields null.
Fixed byt not trying to print the filename of UNKNOWN_LOCATION.

This isn't really related to the bogus -Wreturn-type warning as I initially
thought.  (With -Wreturn-type we say that F is missing a return statement,
which obviously isn't correct -- I'll open a separate PR for that.)
We might ICE anytime we call print_instantiation_full_context with location
that is in fact UNKNOWN_LOCATION.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-03-30  Marek Polacek  <pola...@redhat.com>

        PR c++/70449
        * error.c (print_instantiation_full_context): Don't print the filename
        for UNKNOWN_LOCATIONs.

        * g++.dg/cpp0x/constexpr-70449.C: New test.

diff --git gcc/cp/error.c gcc/cp/error.c
index aa5fd41..159a9e0 100644
--- gcc/cp/error.c
+++ gcc/cp/error.c
@@ -3312,12 +3312,19 @@ print_instantiation_full_context (diagnostic_context 
*context)
 
   if (p)
     {
-      pp_verbatim (context->printer,
-                  TREE_CODE (p->decl) == TREE_LIST
-                  ? _("%s: In substitution of %qS:\n")
-                  : _("%s: In instantiation of %q#D:\n"),
-                  LOCATION_FILE (location),
-                  p->decl);
+      if (location != UNKNOWN_LOCATION)
+       pp_verbatim (context->printer,
+                    TREE_CODE (p->decl) == TREE_LIST
+                    ? _("%s: In substitution of %qS:\n")
+                    : _("%s: In instantiation of %q#D:\n"),
+                    LOCATION_FILE (location),
+                    p->decl);
+      else
+       pp_verbatim (context->printer,
+                    TREE_CODE (p->decl) == TREE_LIST
+                    ? _("In substitution of %qS:\n")
+                    : _("In instantiation of %q#D:\n"),
+                    p->decl);
 
       location = p->locus;
       p = p->next;
diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-70449.C 
gcc/testsuite/g++.dg/cpp0x/constexpr-70449.C
index e69de29..bc5dd71 100644
--- gcc/testsuite/g++.dg/cpp0x/constexpr-70449.C
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-70449.C
@@ -0,0 +1,12 @@
+// PR c++/70449
+// { dg-do compile { target c++11 } }
+
+template <int>
+constexpr
+int f (void)
+{
+  enum E { a = f<0> () };
+  return 0;
+}
+
+// { dg-error "body of constexpr function" "" { target { ! c++14 } } 0 }

        Marek

Reply via email to