Skip to content

Commit

Permalink
/libcpp
Browse files Browse the repository at this point in the history
2017-11-06  Mukesh Kapoor  <[email protected]>

	PR c++/80955
	* lex.c (lex_string): When checking for a valid macro for the
	warning related to -Wliteral-suffix (CPP_W_LITERAL_SUFFIX),
	check that the macro name does not start with an underscore
	before calling is_macro().

/gcc/testsuite
2017-11-06  Mukesh Kapoor  <[email protected]>

	PR c++/80955
	* g++.dg/cpp0x/udlit-macros.C: New.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254443 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
paolo committed Nov 6, 2017
1 parent baf9f85 commit 3f6f41d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
5 changes: 5 additions & 0 deletions gcc/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-11-06 Mukesh Kapoor <[email protected]>

PR c++/80955
* g++.dg/cpp0x/udlit-macros.C: New.

2017-11-06 Paul Thomas <[email protected]>

PR fortran/69739
Expand Down
31 changes: 31 additions & 0 deletions gcc/testsuite/g++.dg/cpp0x/udlit-macros.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// PR c++/80955
// { dg-do run { target c++11 } }

extern "C" int sprintf (char *s, const char *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()
{
long 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;
}
8 changes: 8 additions & 0 deletions libcpp/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2017-11-06 Mukesh Kapoor <[email protected]>

PR c++/80955
* lex.c (lex_string): When checking for a valid macro for the
warning related to -Wliteral-suffix (CPP_W_LITERAL_SUFFIX),
check that the macro name does not start with an underscore
before calling is_macro().

2017-11-05 Tom de Vries <[email protected]>

PR other/82784
Expand Down
10 changes: 6 additions & 4 deletions libcpp/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1871,8 +1871,9 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base,
/* 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)
Expand Down Expand Up @@ -2001,8 +2002,9 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base)
/* 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)
Expand Down

0 comments on commit 3f6f41d

Please sign in to comment.