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

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