diff mbox

[C++] PR 58155 - -Wliteral-suffix warns about tokens which are skipped

Message ID 53BAAC9B.70305@verizon.net
State New
Headers show

Commit Message

Ed Smith-Rowland July 7, 2014, 2:20 p.m. UTC
This patch addresses an old issue of warning about macro touching string 
literal even if the code is skipped:

#define BAZ "baz"
#if 0
"bar"BAZ
#endif

Just skip the warning Wliteral-suffix if the preprocessor is skipping.

Built and tested on x86_64-linux.

OK?

And for 4.9?

Thanks,

Ed Smith-Rowland
libcpp/

2014-07-07  Edward Smith-Rowland  <3dw4rd@verizon.net>

	PR c++/58155 - -Wliteral-suffix warns about tokens which are skipped
	by preprocessor
	* lex.c (lex_raw_string ()): Do not warn about invalid suffix
	if skipping. (lex_string ()): Ditto.


gcc/testsuite/

2014-07-07  Edward Smith-Rowland  <3dw4rd@verizon.net>

	PR c++/58155 - -Wliteral-suffix warns about tokens which are skipped
	g++.dg/cpp0x/pr58155.C: New.

Comments

Jason Merrill July 8, 2014, 10:41 p.m. UTC | #1
On 07/07/2014 07:20 AM, Ed Smith-Rowland wrote:
> OK?
>
> And for 4.9?

Yes.

Jason
diff mbox

Patch

Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 212209)
+++ libcpp/lex.c	(working copy)
@@ -1646,7 +1646,7 @@ 
       if (is_macro (pfile, cur))
 	{
 	  /* Raise a warning, but do not consume subsequent tokens.  */
-	  if (CPP_OPTION (pfile, warn_literal_suffix))
+	  if (CPP_OPTION (pfile, warn_literal_suffix) && !pfile->state.skipping)
 	    cpp_warning_with_line (pfile, CPP_W_LITERAL_SUFFIX,
 				   token->src_loc, 0,
 				   "invalid suffix on literal; C++11 requires "
@@ -1775,7 +1775,7 @@ 
       if (is_macro (pfile, cur))
 	{
 	  /* Raise a warning, but do not consume subsequent tokens.  */
-	  if (CPP_OPTION (pfile, warn_literal_suffix))
+	  if (CPP_OPTION (pfile, warn_literal_suffix) && !pfile->state.skipping)
 	    cpp_warning_with_line (pfile, CPP_W_LITERAL_SUFFIX,
 				   token->src_loc, 0,
 				   "invalid suffix on literal; C++11 requires "
Index: gcc/testsuite/g++.dg/cpp0x/pr58155.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/pr58155.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/pr58155.C	(revision 0)
@@ -0,0 +1,13 @@ 
+// { dg-do compile { target c++11 } }
+
+#define BAZ "baz"
+
+#if 0
+
+"bar"BAZ
+
+R"(
+  bar
+)"BAZ
+
+#endif