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

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)
/libcpp
2017-10-20  Mukesh Kapoor   <mukesh.kap...@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.kap...@oracle.com>

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

Reply via email to