On 11/3/2017 7:31 AM, Paolo Carlini wrote:
Hi,

On 02/11/2017 15:42, Jason Merrill wrote:

This is a good suggestion. I have attached the revised patch. Thanks.
OK, thanks!
Thanks Jason.

I was about to volunteer committing the patch but then noticed that the testcase includes quite a lot, eg, <inttypes.h> too, which we never include in the whole C++ testsuite. Can we have something simpler? Also, we don't need to include the whole <stdio.h> and <string.h> for a couple of declarations, we can simply provide by hand the declarations of sprintf and strcmp at the beginning of the file (plenty of examples in the testsuite). Mukesh, can you please work on that? Also, please watch out trailing blank lines.

I had included <inttypes.h> to get the definition of macro PRId64. I have now modified the test case to remove all includes. I have added the definition of the macro in the test case and also added declarations of functions sprintf() strcmp(). I have attached the revised patch. Thanks.

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,32 @@
+// PR c++/80955
+// { dg-do compile { target c++11 } }
+
+extern "C" int sprintf(char *__restrict s,
+                      const char *__restrict format, ...);
+extern "C" int strcmp(const char *s1, const char *s2);
+
+#  define __PRI64_PREFIX        "l"
+# define PRId64         __PRI64_PREFIX "d"
+
+using size_t = decltype(sizeof(0));
+#define _zero
+#define _ID _xx
+int operator""_zero(const char*, size_t) { return 0; }
+int operator""_ID(const char*, size_t) { return 0; }
+
+int main()
+{
+  int i64 = 123;
+  char buf[100];
+  sprintf(buf, "%"PRId64"abc", i64);  // { dg-warning "invalid suffix on 
literal" }
+  return strcmp(buf, "123abc")
+        + ""_zero
+        + "bob"_zero
+        + R"#(raw
+              string)#"_zero
+        + "xx"_ID
+        + ""_ID
+        + R"AA(another
+               raw
+               string)AA"_ID;
+}
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c        (revision 254048)
+++ libcpp/lex.c        (working copy)
@@ -1871,8 +1871,9 @@
       /* 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.
+        The macro name should not start with '_' for this warning. */
+      if ((*cur != '_') && is_macro (pfile, cur))
        {
          /* Raise a warning, but do not consume subsequent tokens.  */
          if (CPP_OPTION (pfile, warn_literal_suffix) && !pfile->state.skipping)
@@ -2001,8 +2002,9 @@
       /* 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.
+        The macro name should not start with '_' for this warning. */
+      if ((*cur != '_') && is_macro (pfile, cur))
        {
          /* Raise a warning, but do not consume subsequent tokens.  */
          if (CPP_OPTION (pfile, warn_literal_suffix) && !pfile->state.skipping)

Reply via email to