Currently there's no way to disable the warning about literal suffix
identifiers that use reserved names. This patch from Eric makes it
depend on the existing -Wliteral-suffix option. Currently that
controls warnings when encountering string literals concatenated with
macros, such as "%"PRIu32, which isn't the same problem, but I think
it's OK to reuse the warning option for this as well.

Tested powerpc64le-linux. OK for trunk now, or should it wait for
Stage 1?



gcc:

2017-02-17  Jonathan Wakely  <jwak...@redhat.com>

        PR c++/69523
        * doc/invoke.texi (C++ Dialect Options) [-Wliteral-suffix]: Update
        description.

gcc/cp:

2017-02-17  Eric Fiselier  <e...@efcs.ca>
            Jonathan Wakely  <jwak...@redhat.com>

        PR c++/69523
        * parser.c (cp_parser_unqualified_id): Use OPT_Wliteral_suffix to
        control warning about literal suffix identifiers without a leading
        underscore.

gcc/testsuite:

2017-02-17  Eric Fiselier  <e...@efcs.ca>
            Jonathan Wakely  <jwak...@redhat.com>

        PR c++/69523
        * g++.dg/cpp0x/Wliteral-suffix2.C: New test.


commit 4d04ba1c1d19973d2b7e845a2f92cdd292054756
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Fri Feb 17 10:50:20 2017 +0000

    PR c++/69523 make -Wliteral-suffix control warning
    
    gcc:
    
    2017-02-17  Jonathan Wakely  <jwak...@redhat.com>
    
        PR c++/69523
        * doc/invoke.texi (C++ Dialect Options) [-Wliteral-suffix]: Update
        description.
    
    gcc/cp:
    
    2017-02-17  Eric Fiselier  <e...@efcs.ca>
            Jonathan Wakely  <jwak...@redhat.com>
    
        PR c++/69523
        * parser.c (cp_parser_unqualified_id): Use OPT_Wliteral_suffix to
        control warning about literal suffix identifiers without a leading
        underscore.
    
    gcc/testsuite:
    
    2017-02-17  Eric Fiselier  <e...@efcs.ca>
            Jonathan Wakely  <jwak...@redhat.com>
    
        PR c++/69523
        * g++.dg/cpp0x/Wliteral-suffix2.C: New test.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 060962d..06f2beb 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -5812,8 +5812,9 @@ cp_parser_unqualified_id (cp_parser* parser,
              const char *name = UDLIT_OP_SUFFIX (id);
              if (name[0] != '_' && !in_system_header_at (input_location)
                  && declarator_p)
-               warning (0, "literal operator suffixes not preceded by %<_%>"
-                           " are reserved for future standardization");
+               warning (OPT_Wliteral_suffix,
+                        "literal operator suffixes not preceded by %<_%>"
+                        " are reserved for future standardization");
            }
 
          return id;
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 72038a1..0154e3d 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2851,6 +2851,11 @@ int main() @{
 
 In this case, @code{PRId64} is treated as a separate preprocessing token.
 
+Additionally, warn when a user-defined literal operator is declared with
+a literal suffix identifier that doesn't begin with an underscore. Literal
+suffix identifiers that don't begin with an underscore are reserved for
+future standardization.
+
 This warning is enabled by default.
 
 @item -Wlto-type-mismatch
diff --git a/gcc/testsuite/g++.dg/cpp0x/Wliteral-suffix2.C 
b/gcc/testsuite/g++.dg/cpp0x/Wliteral-suffix2.C
new file mode 100644
index 0000000..129947d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/Wliteral-suffix2.C
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wno-literal-suffix" }
+
+// Test user-defined literals.
+// Test "-Wno-literal-suffix" suppresses warnings on declaration without
+// leading underscore.
+
+long double operator"" nounder(long double); // { dg-bogus "" }
+
+template<char...>
+  int operator"" nounder(); // { dg-bogus "" }

Reply via email to