diff mbox

[C++] PR 51397

Message ID 4EFF0557.6010308@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Dec. 31, 2011, 12:51 p.m. UTC
Hi,

this issue, reported by Dave (and Jon), is about the error message 
printed for a static_assert like:

     static_assert('X' != '\130', "'X' has the wrong value");

where, due to the use of %E, we go through pp_c_string_literal and thus 
pp_c_char, and we escape the single quotes around X. Dave also 
recommends not using *any* quotes around the string.

Thus, just using %s on the TREE_STRING_POINTER seems a straightforward 
fix to me (but in fact %qs also passes the testsuite).

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
/cp
2011-12-31  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51397
	* semantics.c (finish_static_assert): Use %s instead of %E for
	the error message.

/testsuite
2011-12-31  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51397
	* g++.dg/cpp0x/static_assert6.C: New.

Comments

Jason Merrill Dec. 31, 2011, 5:16 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/cpp0x/static_assert6.C
===================================================================
--- testsuite/g++.dg/cpp0x/static_assert6.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/static_assert6.C	(revision 0)
@@ -0,0 +1,4 @@ 
+// PR c++/51397
+// { dg-options "-std=c++0x" }
+
+static_assert('X' != '\130', "'X' has the wrong value"); // { dg-error "'X' has the wrong value" }
Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 182754)
+++ cp/semantics.c	(working copy)
@@ -5127,7 +5127,7 @@  finish_static_assert (tree condition, tree message
       if (TREE_CODE (condition) == INTEGER_CST 
           && integer_zerop (condition))
         /* Report the error. */
-        error ("static assertion failed: %E", message);
+        error ("static assertion failed: %s", TREE_STRING_POINTER (message));
       else if (condition && condition != error_mark_node)
 	{
 	  error ("non-constant condition for static assertion");