public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 80955 (Macros expanded in definition of user-defined literals)
@ 2017-10-20 17:03 Mukesh Kapoor
  2017-10-20 18:00 ` Nathan Sidwell
  0 siblings, 1 reply; 17+ messages in thread
From: Mukesh Kapoor @ 2017-10-20 17:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: Nathan Sidwell, jason

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Hi,

This patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80955.
Handle user-defined literals correctly in lex_string(). An empty string 
followed by an identifier is
a valid user-defined literal. Don't issue a warning for this case.

Bootstrapped and tested with 'make check' on x86_64-linux. New test case 
added. Ok for trunk?

Mukesh


[-- Attachment #2: patch_80955 --]
[-- Type: text/plain, Size: 1355 bytes --]

Index: gcc/testsuite/g++.dg/cpp0x/udlit-macros.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-macros.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-macros.C	(working copy)
@@ -0,0 +1,7 @@
+// PR c++/80955
+// { dg-do compile { target c++11 } }
+
+using size_t = decltype(sizeof(0));
+#define _zero
+int operator""_zero(const char*, size_t) { return 0; }
+int main() { return ""_zero; }
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 253775)
+++ libcpp/lex.c	(working copy)
@@ -2001,8 +2001,11 @@
       /* If a string format macro, say from inttypes.h, is placed touching
 	 a string literal it could be parsed as a C++11 user-defined string
 	 literal thus breaking the program.
-	 Try to identify macros with is_macro. A warning is issued. */
-      if (is_macro (pfile, cur))
+	 Try to identify macros with is_macro. A warning is issued.
+	 Don't do this for a user-defined literal, i.e. an
+	 empty string followed by an identifier.
+	 For an empty string "", (cur-base)==2. Bug 80955 */
+      if (is_macro (pfile, cur) && ((cur-base) != 2))
 	{
 	  /* Raise a warning, but do not consume subsequent tokens.  */
 	  if (CPP_OPTION (pfile, warn_literal_suffix) && !pfile->state.skipping)

[-- Attachment #3: CL_80955 --]
[-- Type: text/plain, Size: 347 bytes --]

/libcpp
2017-10-20  Mukesh Kapoor   <mukesh.kapoor@oracle.com>

	PR c++/80955
	* lex.c (lex_string): An empty string followed by an identifier is
	a valid user-defined literal. Don't issue a warning for this case.

/testsuite
2017-10-20  Mukesh Kapoor   <mukesh.kapoor@oracle.com>

	PR c++/80955
	* g++.dg/cpp0x/udlit-macros.C: New.


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-11-06 10:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-20 17:03 [C++ Patch] PR 80955 (Macros expanded in definition of user-defined literals) Mukesh Kapoor
2017-10-20 18:00 ` Nathan Sidwell
2017-10-20 18:19   ` Mukesh Kapoor
2017-10-20 20:56     ` Mukesh Kapoor
2017-10-24 14:07       ` Jason Merrill
2017-10-25  5:48         ` Mukesh Kapoor
2017-10-25 11:26           ` Nathan Sidwell
2017-10-25 16:13             ` Jason Merrill
2017-10-25 16:14               ` Mukesh Kapoor
2017-10-26  3:30             ` Mukesh Kapoor
2017-10-31 16:26               ` Mukesh Kapoor
2017-11-01 20:02                 ` Jason Merrill
2017-11-01 20:44                   ` Mukesh Kapoor
2017-11-02 14:42                     ` Jason Merrill
2017-11-03 14:31                       ` Paolo Carlini
2017-11-04 22:38                         ` Mukesh Kapoor
2017-11-06 10:30                           ` Paolo Carlini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).