My recently committed patch for c++/60760 triggered test suite
failures in ILP32 mode due to a couple of problems:

1) The test assumed that (void*)1 will appear in GCC diagnostics
   as 1ul, which is correct in LP64 but not in ILP32.
2) GCC is inconsistent in how it spells "constant expression."
   Some errors in the C++ front end hyphenate the words while
   others don't.  Depending on which one happens to get triggered
   a test that assumes one or the other will fail.  Some test work
   around this inconsistency by using the regex period expression
   instead of the space but they aren't consistent about it either.

The attached patch corrects (1), and partially also (2) for errors
emitted from cp/constexpr.c.  There are still more places in the
C++ front end that use the hyphenation that should be adjusted
but I leave that for a follow-on patch.  I chose the spelling
without the hyphen because it's the dominant form in GCC (32 vs
26 diagnostics) and also for consistency with the C front end
and with other C++ compilers.

While fixing (2) I spent quite a bit of time wrestling with the
overflow-warn-1.C tests that started failing after the removal
of the hyphen for no apparent reason.  For some reason I don't
fully understand, the following test fails in the g++.dg/warn/ directory but passes when the order of the dg-error directives
is reversed.  My guess is that it has something to do with
the second one being a strict subset of the first and so maybe
when DejaGnu processes the first one it removes the errors
matching the second as well and then fails on the second
directive.

I mention it because it seems like a gotcha worth knowing about
when writing these types of multi-diagnostic directives.

void f ()
{
  switch (0)
    case 1 / 0: ;   // { dg-warning "division by zero" }
}

// { dg-error "not a constant" "#1" { target *-*-*-* } 4 }
// { dg-error "division by zero is not a constant.expression" "#2" { target c++11 } 4 }

Martin
gcc/cp/ChangeLog:
2016-08-02  Martin Sebor  <mse...@redhat.com>

	* constexpr.c (cxx_eval_store_expression): Remove hyphen from
	the spelling of "constant-expression" in diagnostic messages
	for consistency.
	(cxx_eval_constant_expression): Same.
	(cxx_eval_outermost_constant_expr): Same.
	(potential_constant_expression_1): Same.

gcc/testsuite/ChangeLog:
2016-08-02  Martin Sebor  <mse...@redhat.com>

	* g++.dg/cpp0x/constexpr-cast.C: Avoid assuming (void*)1 is spelled
	1ul in diagnostics.  Remove hyphen from "constant-expression."
	* g++.dg/cpp0x/constexpr-50060.C: Adjust.
	* g++.dg/cpp0x/static_assert3.C: Same.
	* g++.dg/cpp1y/constexpr-throw.C: Same.
	* g++.dg/template/nontype3.C: Same.
	* g++.dg/warn/overflow-warn-1.C: Same.
	* g++.dg/warn/overflow-warn-3.C: Same.
	* g++.dg/warn/overflow-warn-4.C: Same.

Index: gcc/cp/constexpr.c
===================================================================
--- gcc/cp/constexpr.c	(revision 238989)
+++ gcc/cp/constexpr.c	(working copy)
@@ -3170,7 +3170,7 @@ cxx_eval_store_expression (const constex
       /* A constant-expression cannot modify objects from outside the
 	 constant-expression.  */
       if (!ctx->quiet)
-	error ("modification of %qE is not a constant-expression", object);
+	error ("modification of %qE is not a constant expression", object);
       *non_constant_p = true;
       return t;
     }
@@ -4097,7 +4097,7 @@ cxx_eval_constant_expression (const cons
 	      {
 		if (!ctx->quiet)
 		  error_at (EXPR_LOC_OR_LOC (t, input_location),
-			    "a reinterpret_cast is not a constant-expression");
+			    "a reinterpret_cast is not a constant expression");
 		*non_constant_p = true;
 		return t;
 	      }
@@ -4139,7 +4139,7 @@ cxx_eval_constant_expression (const cons
 		if (!ctx->quiet)
 		  error_at (EXPR_LOC_OR_LOC (t, input_location),
 			    "%<reinterpret_cast<%T>(%E)%> is not "
-			    "a constant-expression",
+			    "a constant expression",
 			    type, op);
 		*non_constant_p = true;
 		return t;
@@ -4201,7 +4201,7 @@ cxx_eval_constant_expression (const cons
     case OFFSET_REF:
       if (!ctx->quiet)
         error_at (EXPR_LOC_OR_LOC (t, input_location),
-		  "expression %qE is not a constant-expression", t);
+		  "expression %qE is not a constant expression", t);
       *non_constant_p = true;
       break;
 
@@ -4282,7 +4282,7 @@ cxx_eval_constant_expression (const cons
 	     so for now just fail.  */
 	  if (!ctx->quiet)
 	    error_at (EXPR_LOCATION (t),
-		      "statement is not a constant-expression");
+		      "statement is not a constant expression");
 	}
       else
 	internal_error ("unexpected expression %qE of kind %s", t,
@@ -4369,7 +4369,7 @@ cxx_eval_outermost_constant_expr (tree t
     {
       if (!allow_non_constant)
 	error ("conversion from pointer type %qT "
-	       "to arithmetic type %qT in a constant-expression",
+	       "to arithmetic type %qT in a constant expression",
 	       TREE_TYPE (TREE_OPERAND (r, 0)), TREE_TYPE (r));
       non_constant_p = true;
     }
@@ -5067,7 +5067,7 @@ potential_constant_expression_1 (tree t,
     case AT_ENCODE_EXPR:
     fail:
       if (flags & tf_error)
-        error ("expression %qE is not a constant-expression", t);
+        error ("expression %qE is not a constant expression", t);
       return false;
 
     case TYPEID_EXPR:
@@ -5228,7 +5228,7 @@ potential_constant_expression_1 (tree t,
 	if (integer_zerop (denom))
 	  {
 	    if (flags & tf_error)
-	      error ("division by zero is not a constant-expression");
+	      error ("division by zero is not a constant expression");
 	    return false;
 	  }
 	else
@@ -5333,7 +5333,7 @@ potential_constant_expression_1 (tree t,
 	{
 	  if (flags & tf_error)
 	    error_at (location_of (t),
-		      "%<delete[]%> is not a constant-expression");
+		      "%<delete[]%> is not a constant expression");
 	  return false;
 	}
       /* Fall through.  */
@@ -5356,7 +5356,7 @@ potential_constant_expression_1 (tree t,
 					     want_rval, strict, tf_none))
 	  return true;
       if (flags & tf_error)
-        error ("expression %qE is not a constant-expression", t);
+        error ("expression %qE is not a constant expression", t);
       return false;
 
     case VEC_INIT_EXPR:
@@ -5384,7 +5384,7 @@ potential_constant_expression_1 (tree t,
 	if (breaks (target) || continues (target))
 	  return true;
 	if (flags & tf_error)
-	  error ("%<goto%> is not a constant-expression");
+	  error ("%<goto%> is not a constant expression");
 	return false;
       }
 
Index: gcc/testsuite/g++.dg/cpp0x/constexpr-50060.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/constexpr-50060.C	(revision 238989)
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-50060.C	(working copy)
@@ -12,7 +12,7 @@ struct S
 
 struct T
 {
-  constexpr T (double a) : y {}, x ((y = 1, 0.8125)) {}	// { dg-error "is not a constant-expression" "T" { target { ! c++14 } } }
+  constexpr T (double a) : y {}, x ((y = 1, 0.8125)) {}	// { dg-error "is not a constant expression" "T" { target { ! c++14 } } }
   double x;
   int y;
 };
Index: gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C	(revision 238989)
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C	(working copy)
@@ -8,7 +8,7 @@ int i;
 constexpr void *q = reinterpret_cast<void*>(&i);    // { dg-error "" "bug c++/49171" { xfail *-*-*-* } }
 
 constexpr void *r0 = reinterpret_cast<void*>(1);    // { dg-error "not a constant expression" }
-constexpr void *r1 = reinterpret_cast<void*>(sizeof 'x');  // { dg-error ".reinterpret_cast<void\\*>\\(1ul\\). is not a constant-expression" }
+constexpr void *r1 = reinterpret_cast<void*>(sizeof 'x');  // { dg-error ".reinterpret_cast<void\\*>\\(1\[ul\]\*\\). is not a constant expression" }
 
 template <class T>
 constexpr bool f ()
Index: gcc/testsuite/g++.dg/cpp0x/static_assert3.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/static_assert3.C	(revision 238989)
+++ gcc/testsuite/g++.dg/cpp0x/static_assert3.C	(working copy)
@@ -1,4 +1,4 @@
 // { dg-do compile { target c++11 } }
 static_assert(7 / 0, "X"); // { dg-error "non-constant condition" "non-constant" }
 // { dg-warning "division by zero" "zero" { target *-*-* } 2 }
-// { dg-error "division by zero is not a constant-expression" "not a constant" { target *-*-* } 2 }
+// { dg-error "division by zero is not a constant expression" "not a constant" { target *-*-* } 2 }
Index: gcc/testsuite/g++.dg/cpp1y/constexpr-throw.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/constexpr-throw.C	(revision 238989)
+++ gcc/testsuite/g++.dg/cpp1y/constexpr-throw.C	(working copy)
@@ -8,25 +8,25 @@ constexpr void f1() {
 constexpr void f2() {
   if (true)
     throw;
-} // { dg-error "not a constant-expression" }
+} // { dg-error "not a constant expression" }
 
 constexpr void f3() {
   if (false)
     ;
   else
     throw;
-}// { dg-error "not a constant-expression" }
+}// { dg-error "not a constant expression" }
 
 constexpr void f4() {
   throw;
-}// { dg-error "not a constant-expression" }
+}// { dg-error "not a constant expression" }
 
 constexpr int fun(int n) {
   switch (n) {
   case 0:
     return 1;
   default:
-    throw; // { dg-error "not a constant-expression" }
+    throw; // { dg-error "not a constant expression" }
   }
 }
 
Index: gcc/testsuite/g++.dg/template/nontype3.C
===================================================================
--- gcc/testsuite/g++.dg/template/nontype3.C	(revision 238989)
+++ gcc/testsuite/g++.dg/template/nontype3.C	(working copy)
@@ -31,8 +31,8 @@ template <int PI[1]>
 void dep10(foo< PI[0] > *); // { dg-error "" "integral or enumeration" }
 
 template <int I>
-void dep11(foo< *&I > *); // { dg-error "" "constant-expression" }
+void dep11(foo< *&I > *); // { dg-error "" "constant expression" }
 
 template <int I>
-void dep12(foo< (&I)[4] > *); // { dg-error "" "constant-expression" }
+void dep12(foo< (&I)[4] > *); // { dg-error "" "constant expression" }
 
Index: gcc/testsuite/g++.dg/warn/overflow-warn-1.C
===================================================================
--- gcc/testsuite/g++.dg/warn/overflow-warn-1.C	(revision 238989)
+++ gcc/testsuite/g++.dg/warn/overflow-warn-1.C	(working copy)
@@ -130,7 +130,7 @@ h2i (int x)
 /* { dg-error "division by zero is not a constant.expression" "division" { target c++11 } 32 } */
 /* { dg-warning "invalid conversion from" "convert" { target *-*-* } 56 } */
 /* { dg-warning "invalid conversion from" "convert" { target c++11 } 58 } */
+/* { dg-error "division by zero is not a constant expression" "division" { target c++11 } 65 } */
 /* { dg-error "is not a constant expression" "const" { target *-*-* } 65 } */
-/* { dg-error "division by zero is not a constant.expression" "division" { target c++11 } 65 } */
 /* { dg-error "width not an integer constant" "bit.field" { target c++ } 32 } */
 /* { dg-error "is not a constant expression" "division" { target c++ } 32 } */
Index: gcc/testsuite/g++.dg/warn/overflow-warn-3.C
===================================================================
--- gcc/testsuite/g++.dg/warn/overflow-warn-3.C	(revision 238989)
+++ gcc/testsuite/g++.dg/warn/overflow-warn-3.C	(working copy)
@@ -65,7 +65,7 @@ g (int i)
   switch (i)
     {
     case 0 * (1/0): /* { dg-warning "division by zero" } */
-      ;  /* { dg-error "is not a constant expression" "const" { target *-*-* } 67 }  */
+      ;  /* { dg-error "division by zero is not a constant expression" "division" { target c++11 } 67 }  */
     case 1 + 0 * (INT_MAX + 1): /* { dg-warning "integer overflow in expression" } */
       /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 69 } */
       ;
@@ -131,6 +131,6 @@ h2i (int x)
 /* { dg-error "division by zero is not a constant.expression" "division" { target c++11 } 19 } */
 /* { dg-error "division by zero is not a constant.expression" "division" { target c++11 } 32 } */
 /* { dg-warning "invalid conversion from" "convert" { target c++11 } 60 } */
-/* { dg-error "division by zero is not a constant.expression" "division" { target c++11 } 67 } */
+/* { dg-error "not a constant expression" "constant" { target *-*-*-* } 67 } */
 /* { dg-error "width not an integer constant" "bit.field" { target c++ } 32 } */
 /* { dg-error "is not a constant expression" "division" { target c++ } 32 } */
Index: gcc/testsuite/g++.dg/warn/overflow-warn-4.C
===================================================================
--- gcc/testsuite/g++.dg/warn/overflow-warn-4.C	(revision 238989)
+++ gcc/testsuite/g++.dg/warn/overflow-warn-4.C	(working copy)
@@ -68,7 +68,7 @@ g (int i)
   switch (i)
     {
     case 0 * (1/0): /* { dg-warning "division by zero" } */
-      ;  /* { dg-error "is not a constant expression" "const" { target *-*-* } 70 } */
+      ;  /* { dg-error "division by zero is not a constant expression" "division" { target c++11 } 70 } */
     case 1 + 0 * (INT_MAX + 1): /* { dg-warning "integer overflow in expression" } */
       /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 72 } */
       ;
@@ -134,6 +134,6 @@ h2i (int x)
 /* { dg-error "division by zero is not a constant.expression" "division" { target c++11 } 19 } */
 /* { dg-error "invalid conversion from" "convert" { target c++11 } 63 } */
 /* { dg-error "division by zero is not a constant.expression" "division" { target c++11 } 34 } */
-/* { dg-error "division by zero is not a constant.expression" "division" { target c++11 } 70 } */
+/* { dg-error "is not a constant expression" "const" { target *-*-*-* } 70 } */
 /* { dg-error "width not an integer constant" "bit.field" { target c++ } 34 } */
 /* { dg-error "is not a constant expression" "division" { target c++ } 34 } */

Reply via email to