Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-27 Thread Ollie Wild
On Thu, Apr 26, 2012 at 8:35 AM, Tom Tromey tro...@redhat.com wrote:

 This is ok with this change.

Thanks.  Updated and submitted to trunk.

Ollie


Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-26 Thread Tom Tromey
 Ollie == Ollie Wild a...@google.com writes:

Ollie 2012-04-22   Ollie Wild  a...@google.com
Ollie  * gcc/c-family/c-common.c:
Ollie  * gcc/c-family/c-opts.c (c_common_handle_option):
Ollie  * gcc/c-family/c.opt:
Ollie  * gcc/doc/invoke.texi (struct A):
Ollie  * gcc/testsuite/g++.dg/cpp0x/Wreserved-user-defined-literal.C (test):
Ollie  (main):
Ollie  * libcpp/include/cpplib.h (struct cpp_options):
Ollie  * libcpp/init.c (cpp_create_reader):
Ollie  * libcpp/lex.c (lex_raw_string):
Ollie  (lex_string):

One little nit.

Ollie +  if (ISALPHA(*cur))

Space before open paren.

Ollie +  if (ISALPHA(*cur))

And here.

This is ok with this change.

thanks,
Tom


Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-26 Thread Paolo Bonzini
Il 23/04/2012 14:53, Gabriel Dos Reis ha scritto:
  I chose -Wreserved-user-defined-literal because that's the name used
  by Clang.  It seemed better to maintain consistency between front ends
  than to invent a new, concise option name.
 
  Do you still want me to shorten in?
 yes.
 

Why, out of curiosity?

Paolo


Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-25 Thread Ollie Wild
On Mon, Apr 23, 2012 at 8:28 AM, Gabriel Dos Reis
g...@integrable-solutions.net wrote:

 Thanks.  Tom, I am satisfied with the diagnostic part.
 I think the CPP part makes sense but it is your call.

Hi, Tom, just a quick checkin to see if you've had a chance to review this, yet.

Thanks,
Ollie


Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-23 Thread Gabriel Dos Reis
On Sun, Apr 22, 2012 at 10:59 PM, Ollie Wild a...@google.com wrote:
 Add new option, -Wreserved-user-defined-literal.

Just shorten it to -Wliteral-suffix.


 This option, which is enabled by default, causes the preprocessor to warn
 when a string or character literal is followed by a ud-suffix which does
 not begin with an underscore.  According to [lex.ext]p10, this is
 ill-formed.

the non-CPP part is OK with the above change.
You would need Tom's approval for the CPP part.


 Also modifies the preprocessor to treat such ill-formed suffixes as separate
 preprocessing tokens.  This is consistent with the Clang front end (see
 http://llvm.org/viewvc/llvm-project?view=revrevision=152287), and enables
 backwards compatibility with code that uses formatting macros from
 inttypes.h, as in the following code block:

  int main() {
    int64_t i64 = 123;
    printf(My int64: %PRId64\n, i64);
  }

 Tested via bootstrap + test.

 Okay for trunk?

 Thanks,
 Ollie


 2012-04-22   Ollie Wild  a...@google.com

        * gcc/c-family/c-common.c:
        * gcc/c-family/c-opts.c (c_common_handle_option):
        * gcc/c-family/c.opt:
        * gcc/doc/invoke.texi (struct A):
        * gcc/testsuite/g++.dg/cpp0x/Wreserved-user-defined-literal.C (test):
        (main):
        * libcpp/include/cpplib.h (struct cpp_options):
        * libcpp/init.c (cpp_create_reader):
        * libcpp/lex.c (lex_raw_string):
        (lex_string):

 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
 index 4eacd19..f79020c 100644
 --- a/gcc/c-family/c-common.c
 +++ b/gcc/c-family/c-common.c
 @@ -8820,6 +8820,7 @@ static const struct reason_option_codes_t 
 option_codes[] = {
   {CPP_W_NORMALIZE,                    OPT_Wnormalized_},
   {CPP_W_INVALID_PCH,                  OPT_Winvalid_pch},
   {CPP_W_WARNING_DIRECTIVE,            OPT_Wcpp},
 +  {CPP_W_RESERVED_USER_LITERALS,       OPT_Wreserved_user_defined_literal},
   {CPP_W_NONE,                         0}
  };

 diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
 index 17e1958..a812762 100644
 --- a/gcc/c-family/c-opts.c
 +++ b/gcc/c-family/c-opts.c
 @@ -510,6 +510,10 @@ c_common_handle_option (size_t scode, const char *arg, 
 int value,
          break;
        }

 +    case OPT_Wreserved_user_defined_literal:
 +      cpp_opts-warn_reserved_user_literals = value;
 +      break;
 +
     case OPT_Wreturn_type:
       warn_return_type = value;
       break;
 diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
 index d8c944d..c8a0c84 100644
 --- a/gcc/c-family/c.opt
 +++ b/gcc/c-family/c.opt
 @@ -593,6 +593,10 @@ Wreorder
  C++ ObjC++ Var(warn_reorder) Warning
  Warn when the compiler reorders code

 +Wreserved-user-defined-literal
 +C++ ObjC++ Warning
 +Warn when a string or character literal is followed by a ud-suffix which 
 does not begin with an underscore.
 +
  Wreturn-type
  C ObjC C++ ObjC++ Var(warn_return_type) Warning
  Warn whenever a function's return type defaults to \int\ (C), or about 
 inconsistent return types (C++)
 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
 index 8ca2f4e..ddf0fc6 100644
 --- a/gcc/doc/invoke.texi
 +++ b/gcc/doc/invoke.texi
 @@ -199,7 +199,7 @@ in the following sections.
  -fvisibility-ms-compat @gol
  -Wabi  -Wconversion-null  -Wctor-dtor-privacy @gol
  -Wdelete-non-virtual-dtor -Wnarrowing -Wnoexcept @gol
 --Wnon-virtual-dtor  -Wreorder @gol
 +-Wnon-virtual-dtor  -Wreorder -Wreserved-user-defined-literal @gol
  -Weffc++  -Wstrict-null-sentinel @gol
  -Wno-non-template-friend  -Wold-style-cast @gol
  -Woverloaded-virtual  -Wno-pmf-conversions @gol
 @@ -2478,6 +2478,30 @@ struct A @{
  The compiler rearranges the member initializers for @samp{i}
  and @samp{j} to match the declaration order of the members, emitting
  a warning to that effect.  This warning is enabled by @option{-Wall}.
 +
 +@item -Wreserved-user-defined-literal @r{(C++ and Objective-C++ only)}
 +@opindex Wreserved-user-defined-literal
 +@opindex Wno-reserved-user-defined-literal
 +Warn when a string or character literal is followed by a ud-suffix which does
 +not begin with an underscore.  As a conforming extension, GCC treats such
 +suffixes as separate preprocessing tokens in order to maintain backwards
 +compatibility with code that uses formatting macros from @code{inttypes.h}.
 +For example:
 +
 +@smallexample
 +#define __STDC_FORMAT_MACROS
 +#include inttypes.h
 +#include stdio.h
 +
 +int main() @{
 +  int64_t i64 = 123;
 +  printf(My int64: %PRId64\n, i64);
 +@}
 +@end smallexample
 +
 +In this case, @code{PRId64} is treated as a separate preprocessing token.
 +
 +This warning is enabled by default.
  @end table

  The following @option{-W@dots{}} options are not affected by @option{-Wall}.
 diff --git a/gcc/testsuite/g++.dg/cpp0x/Wreserved-user-defined-literal.C 
 b/gcc/testsuite/g++.dg/cpp0x/Wreserved-user-defined-literal.C
 new file mode 100644
 index 000..66de5c0
 --- /dev/null
 +++ 

Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-23 Thread Ollie Wild
On Mon, Apr 23, 2012 at 7:10 AM, Gabriel Dos Reis
g...@integrable-solutions.net wrote:
 On Sun, Apr 22, 2012 at 10:59 PM, Ollie Wild a...@google.com wrote:
 Add new option, -Wreserved-user-defined-literal.

 Just shorten it to -Wliteral-suffix.

I chose -Wreserved-user-defined-literal because that's the name used
by Clang.  It seemed better to maintain consistency between front ends
than to invent a new, concise option name.

Do you still want me to shorten in?

 the non-CPP part is OK with the above change.
 You would need Tom's approval for the CPP part.

Thanks.  Added Tom to the address list.

Ollie


Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-23 Thread Gabriel Dos Reis
On Mon, Apr 23, 2012 at 7:30 AM, Ollie Wild a...@google.com wrote:
 On Mon, Apr 23, 2012 at 7:10 AM, Gabriel Dos Reis
 g...@integrable-solutions.net wrote:
 On Sun, Apr 22, 2012 at 10:59 PM, Ollie Wild a...@google.com wrote:
 Add new option, -Wreserved-user-defined-literal.

 Just shorten it to -Wliteral-suffix.

 I chose -Wreserved-user-defined-literal because that's the name used
 by Clang.  It seemed better to maintain consistency between front ends
 than to invent a new, concise option name.

 Do you still want me to shorten in?

yes.


 the non-CPP part is OK with the above change.
 You would need Tom's approval for the CPP part.

 Thanks.  Added Tom to the address list.

 Ollie

-- Gaby


Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-23 Thread Ollie Wild
On Mon, Apr 23, 2012 at 7:53 AM, Gabriel Dos Reis
g...@integrable-solutions.net wrote:
 On Mon, Apr 23, 2012 at 7:30 AM, Ollie Wild a...@google.com wrote:

 Do you still want me to shorten in?

 yes.

Done.  Updated patch attached.

Ollie
commit 3f53671fb7fc7811277f047e7914f78e127031a6
Author: Ollie Wild a...@google.com
Date:   Sun Apr 22 21:37:08 2012 -0500

Add new option, -Wreserved-user-defined-literal.

This option, which is enabled by default, causes the preprocessor to warn
when a string or character literal is followed by a ud-suffix which does
not begin with an underscore.  According to [lex.ext]p10, this is
ill-formed.

Also modifies the preprocessor to treat such ill-formed suffixes as separate
preprocessing tokens.  This is consistent with the Clang front end (see
http://llvm.org/viewvc/llvm-project?view=revrevision=152287), and enables
backwards compatibility with code that uses formatting macros from
inttypes.h, as in the following code block:

  int main() {
int64_t i64 = 123;
printf(My int64: %PRId64\n, i64);
  }

Google ref b/6377711.

2012-04-22   Ollie Wild  a...@google.com

* gcc/c-family/c-common.c: Add CPP_W_LITERAL_SUFFIX mapping.
* gcc/c-family/c-opts.c (c_common_handle_option): Handle
OPT_Wliteral_suffix.
* gcc/c-family/c.opt: Add Wliteral-suffix.
* gcc/doc/invoke.texi (Wliteral-suffix): Document new option.
* gcc/testsuite/g++.dg/cpp0x/Wliteral-suffix.c: New test.
* libcpp/include/cpplib.h (struct cpp_options): Add new field,
warn_literal_suffix.
(CPP_W_LITERAL_SUFFIX): New enum.
* libcpp/init.c (cpp_create_reader): Default initialization of
warn_literal_suffix.
* libcpp/lex.c (lex_raw_string): Treat user-defined literals which
don't begin with '_' as separate tokens and produce a warning.
(lex_string): Ditto.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 4eacd19..bf5b034 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -8820,6 +8820,7 @@ static const struct reason_option_codes_t option_codes[] 
= {
   {CPP_W_NORMALIZE,OPT_Wnormalized_},
   {CPP_W_INVALID_PCH,  OPT_Winvalid_pch},
   {CPP_W_WARNING_DIRECTIVE,OPT_Wcpp},
+  {CPP_W_LITERAL_SUFFIX,   OPT_Wliteral_suffix},
   {CPP_W_NONE, 0}
 };
 
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 17e1958..2510747 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -476,6 +476,10 @@ c_common_handle_option (size_t scode, const char *arg, int 
value,
   cpp_opts-warn_invalid_pch = value;
   break;
 
+case OPT_Wliteral_suffix:
+  cpp_opts-warn_literal_suffix = value;
+  break;
+
 case OPT_Wlong_long:
   cpp_opts-cpp_warn_long_long = value;
   break;
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index d8c944d..db8ca81 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -449,6 +449,10 @@ Wjump-misses-init
 C ObjC Var(warn_jump_misses_init) Init(-1) Warning
 Warn when a jump misses a variable initialization
 
+Wliteral-suffix
+C++ ObjC++ Warning
+Warn when a string or character literal is followed by a ud-suffix which does 
not begin with an underscore.
+
 Wlogical-op
 C ObjC C++ ObjC++ Var(warn_logical_op) Init(0) Warning 
 Warn when a logical operator is suspiciously always evaluating to true or false
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 8ca2f4e..3c9588a 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -198,8 +198,8 @@ in the following sections.
 -fno-default-inline  -fvisibility-inlines-hidden @gol
 -fvisibility-ms-compat @gol
 -Wabi  -Wconversion-null  -Wctor-dtor-privacy @gol
--Wdelete-non-virtual-dtor -Wnarrowing -Wnoexcept @gol
--Wnon-virtual-dtor  -Wreorder @gol
+-Wdelete-non-virtual-dtor -Wliteral-suffix -Wnarrowing @gol
+-Wnoexcept -Wnon-virtual-dtor  -Wreorder @gol
 -Weffc++  -Wstrict-null-sentinel @gol
 -Wno-non-template-friend  -Wold-style-cast @gol
 -Woverloaded-virtual  -Wno-pmf-conversions @gol
@@ -2425,6 +2425,30 @@ an instance of a derived class through a pointer to a 
base class if the
 base class does not have a virtual destructor.  This warning is enabled
 by @option{-Wall}.
 
+@item -Wliteral-suffix @r{(C++ and Objective-C++ only)}
+@opindex Wliteral-suffix
+@opindex Wno-literal-suffix
+Warn when a string or character literal is followed by a ud-suffix which does
+not begin with an underscore.  As a conforming extension, GCC treats such
+suffixes as separate preprocessing tokens in order to maintain backwards
+compatibility with code that uses formatting macros from @code{inttypes.h}.
+For example:
+
+@smallexample
+#define __STDC_FORMAT_MACROS
+#include inttypes.h
+#include stdio.h
+
+int main() @{
+  int64_t i64 = 123;
+  printf(My int64: %PRId64\n, i64);
+@}
+@end smallexample

Re: PR c++/52538 Extend C++11 UDLs to be compatible with inttypes.h macros (issue6109043)

2012-04-23 Thread Gabriel Dos Reis
On Mon, Apr 23, 2012 at 8:26 AM, Ollie Wild a...@google.com wrote:
 On Mon, Apr 23, 2012 at 7:53 AM, Gabriel Dos Reis
 g...@integrable-solutions.net wrote:
 On Mon, Apr 23, 2012 at 7:30 AM, Ollie Wild a...@google.com wrote:

 Do you still want me to shorten in?

 yes.

 Done.  Updated patch attached.

 Ollie

Thanks.  Tom, I am satisfied with the diagnostic part.
I think the CPP part makes sense but it is your call.

-- Gaby