public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52538] New: Extend C++11 UDLs to be compatible with inttypes.h macros
@ 2012-03-09  9:00 jyasskin at gcc dot gnu.org
  2012-03-09  9:07 ` [Bug c++/52538] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jyasskin at gcc dot gnu.org @ 2012-03-09  9:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52538

             Bug #: 52538
           Summary: Extend C++11 UDLs to be compatible with inttypes.h
                    macros
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jyasskin@gcc.gnu.org


C++11 defines user-defined literals in a way that breaks compatibility with
some code that uses the formatting macros from <inttypes.h>:

$ cat test.cc
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h>

int main() {
  int64_t i64 = 123;
  printf("My int64: %"PRId64"\n", i64);
}
$ install_gcc46/bin/g++ -Wall test.cc -o test && ./test
My int64: 123
$ install_gcc46/bin/g++ -std=c++0x -Wall test.cc -o test && ./test
My int64: 123
$ install_gcc47/bin/g++-4.7pre -Wall test.cc -o test && ./test
My int64: 123
$ install_gcc47/bin/g++-4.7pre -Wall -Wc++11-compat test.cc -o test && ./test
My int64: 123
$ install_gcc47/bin/g++-4.7pre -std=c++0x -Wall test.cc -o test && ./test
test.cc: In function ‘int main()’:
test.cc:7:29: error: unable to find string literal operator ‘operator"" PRId64’


Clang is working around this by interpreting literal suffixes that don't start
with underscores as separate tokens, which allows them to expand as macros:
http://llvm.org/viewvc/llvm-project?view=rev&revision=152287

According to [lex.ext]p10 and [usrlit.suffix], these suffixes are ill-formed,
no diagnostic required, so allowing them to expand as macros is a conforming
extension.

It would also be possible to fix the code by inserting a space between the "
and the macro name, but in Google's codebase, this cleanup would be 3-4x as
large as the narrowing conversion cleanup, which you have already made
optional.


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

* [Bug c++/52538] Extend C++11 UDLs to be compatible with inttypes.h macros
  2012-03-09  9:00 [Bug c++/52538] New: Extend C++11 UDLs to be compatible with inttypes.h macros jyasskin at gcc dot gnu.org
@ 2012-03-09  9:07 ` pinskia at gcc dot gnu.org
  2012-03-09  9:52 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-03-09  9:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52538

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-03-09 09:07:10 UTC ---
If you want to use C++11, then you have to write C++11 code.  That is the way
forward I think we have discussed this before.


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

* [Bug c++/52538] Extend C++11 UDLs to be compatible with inttypes.h macros
  2012-03-09  9:00 [Bug c++/52538] New: Extend C++11 UDLs to be compatible with inttypes.h macros jyasskin at gcc dot gnu.org
  2012-03-09  9:07 ` [Bug c++/52538] " pinskia at gcc dot gnu.org
@ 2012-03-09  9:52 ` redi at gcc dot gnu.org
  2012-04-27 14:29 ` aaw at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-09  9:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52538

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-09 09:51:34 UTC ---
(In reply to comment #1)
> If you want to use C++11, then you have to write C++11 code.  That is the way
> forward I think we have discussed this before.

Yes, in PR 52485, and see also PR 51282 and PR 50917 - this is affecting a lot
of large codebases. The committee are discussing whether this is a defect worth
addressing in the standard, as the scope of the problems is larger than
previously realised.

(In reply to comment #0)
> It would also be possible to fix the code by inserting a space between the "
> and the macro name, but in Google's codebase, this cleanup would be 3-4x as
> large as the narrowing conversion cleanup, which you have already made
> optional.

Ack. When UDL support was added to G++ I also found more problems due to
"PRId64" than I had found when narrowing errors where added (in a much smaller
codebase, obviously.)


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

* [Bug c++/52538] Extend C++11 UDLs to be compatible with inttypes.h macros
  2012-03-09  9:00 [Bug c++/52538] New: Extend C++11 UDLs to be compatible with inttypes.h macros jyasskin at gcc dot gnu.org
  2012-03-09  9:07 ` [Bug c++/52538] " pinskia at gcc dot gnu.org
  2012-03-09  9:52 ` redi at gcc dot gnu.org
@ 2012-04-27 14:29 ` aaw at gcc dot gnu.org
  2012-04-27 17:48 ` jyasskin at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: aaw at gcc dot gnu.org @ 2012-04-27 14:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52538

--- Comment #3 from Ollie Wild <aaw at gcc dot gnu.org> 2012-04-27 14:29:39 UTC ---
Author: aaw
Date: Fri Apr 27 14:29:32 2012
New Revision: 186909

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186909
Log:
Add new option, -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.

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=rev&revision=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-27   Ollie Wild  <aaw@google.com>

    PR c++/52538
    * 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.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/Wliteral-suffix.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/c-family/c-opts.c
    trunk/gcc/c-family/c.opt
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog
    trunk/libcpp/ChangeLog
    trunk/libcpp/include/cpplib.h
    trunk/libcpp/init.c
    trunk/libcpp/lex.c


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

* [Bug c++/52538] Extend C++11 UDLs to be compatible with inttypes.h macros
  2012-03-09  9:00 [Bug c++/52538] New: Extend C++11 UDLs to be compatible with inttypes.h macros jyasskin at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-04-27 14:29 ` aaw at gcc dot gnu.org
@ 2012-04-27 17:48 ` jyasskin at gcc dot gnu.org
  2012-05-01 10:38 ` redi at gcc dot gnu.org
  2012-11-12 14:57 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: jyasskin at gcc dot gnu.org @ 2012-04-27 17:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52538

--- Comment #4 from Jeffrey Yasskin <jyasskin at gcc dot gnu.org> 2012-04-27 17:47:30 UTC ---
Is this ok for gcc-4_7-branch too? The other bug reports Jonathan mentioned
won't be helped by a fix that skips 4.7.


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

* [Bug c++/52538] Extend C++11 UDLs to be compatible with inttypes.h macros
  2012-03-09  9:00 [Bug c++/52538] New: Extend C++11 UDLs to be compatible with inttypes.h macros jyasskin at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-04-27 17:48 ` jyasskin at gcc dot gnu.org
@ 2012-05-01 10:38 ` redi at gcc dot gnu.org
  2012-11-12 14:57 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-01 10:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52538

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-05-01
     Ever Confirmed|0                           |1

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-01 10:37:59 UTC ---
let's confirm this :)


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

* [Bug c++/52538] Extend C++11 UDLs to be compatible with inttypes.h macros
  2012-03-09  9:00 [Bug c++/52538] New: Extend C++11 UDLs to be compatible with inttypes.h macros jyasskin at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2012-05-01 10:38 ` redi at gcc dot gnu.org
@ 2012-11-12 14:57 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-12 14:57 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52538

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.8.0

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-12 14:57:22 UTC ---
Fixed for 4.8.0.


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

end of thread, other threads:[~2012-11-12 14:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-09  9:00 [Bug c++/52538] New: Extend C++11 UDLs to be compatible with inttypes.h macros jyasskin at gcc dot gnu.org
2012-03-09  9:07 ` [Bug c++/52538] " pinskia at gcc dot gnu.org
2012-03-09  9:52 ` redi at gcc dot gnu.org
2012-04-27 14:29 ` aaw at gcc dot gnu.org
2012-04-27 17:48 ` jyasskin at gcc dot gnu.org
2012-05-01 10:38 ` redi at gcc dot gnu.org
2012-11-12 14:57 ` paolo.carlini at oracle dot com

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).