Commit 3976796b by Edward Smith-Rowland Committed by Edward Smith-Rowland

re PR preprocessor/61389 (libcpp diagnostics shouldn't talk about ISO C99 for C++ input files)

2014-07-10  Edward Smith-Rowland  <3dw4rd@verizon.net>
	    Jonathan Wakely  <jwakely@redhat.com>

	PR CPP/61389
	* macro.c (_cpp_arguments_ok, parse_params, create_iso_definition):
	Warning messages mention C++11 in c++ mode and C99 in c mode.
	* lex.c (lex_identifier_intern, lex_identifier): Ditto


Co-Authored-By: Jonathan Wakely <jwakely@redhat.com>

From-SVN: r212441
parent a25b76d8
2014-07-10 Edward Smith-Rowland <3dw4rd@verizon.net>
Jonathan Wakely <jwakely@redhat.com>
PR CPP/61389
* macro.c (_cpp_arguments_ok, parse_params, create_iso_definition):
Warning messages mention C++11 in c++ mode and C99 in c mode.
* lex.c (lex_identifier_intern, lex_identifier): Ditto
2014-07-09 Edward Smith-Rowland <3dw4rd@verizon.net> 2014-07-09 Edward Smith-Rowland <3dw4rd@verizon.net>
PR c++/58155 - -Wliteral-suffix warns about tokens which are skipped PR c++/58155 - -Wliteral-suffix warns about tokens which are skipped
......
...@@ -1175,9 +1175,16 @@ lex_identifier_intern (cpp_reader *pfile, const uchar *base) ...@@ -1175,9 +1175,16 @@ lex_identifier_intern (cpp_reader *pfile, const uchar *base)
replacement list of a variadic macro. */ replacement list of a variadic macro. */
if (result == pfile->spec_nodes.n__VA_ARGS__ if (result == pfile->spec_nodes.n__VA_ARGS__
&& !pfile->state.va_args_ok) && !pfile->state.va_args_ok)
{
if (CPP_OPTION (pfile, cplusplus))
cpp_error (pfile, CPP_DL_PEDWARN,
"__VA_ARGS__ can only appear in the expansion"
" of a C++11 variadic macro");
else
cpp_error (pfile, CPP_DL_PEDWARN, cpp_error (pfile, CPP_DL_PEDWARN,
"__VA_ARGS__ can only appear in the expansion" "__VA_ARGS__ can only appear in the expansion"
" of a C99 variadic macro"); " of a C99 variadic macro");
}
/* For -Wc++-compat, warn about use of C++ named operators. */ /* For -Wc++-compat, warn about use of C++ named operators. */
if (result->flags & NODE_WARN_OPERATOR) if (result->flags & NODE_WARN_OPERATOR)
...@@ -1255,9 +1262,16 @@ lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn, ...@@ -1255,9 +1262,16 @@ lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn,
replacement list of a variadic macro. */ replacement list of a variadic macro. */
if (result == pfile->spec_nodes.n__VA_ARGS__ if (result == pfile->spec_nodes.n__VA_ARGS__
&& !pfile->state.va_args_ok) && !pfile->state.va_args_ok)
{
if (CPP_OPTION (pfile, cplusplus))
cpp_error (pfile, CPP_DL_PEDWARN,
"__VA_ARGS__ can only appear in the expansion"
" of a C++11 variadic macro");
else
cpp_error (pfile, CPP_DL_PEDWARN, cpp_error (pfile, CPP_DL_PEDWARN,
"__VA_ARGS__ can only appear in the expansion" "__VA_ARGS__ can only appear in the expansion"
" of a C99 variadic macro"); " of a C99 variadic macro");
}
/* For -Wc++-compat, warn about use of C++ named operators. */ /* For -Wc++-compat, warn about use of C++ named operators. */
if (result->flags & NODE_WARN_OPERATOR) if (result->flags & NODE_WARN_OPERATOR)
......
...@@ -713,19 +713,27 @@ _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node ...@@ -713,19 +713,27 @@ _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node
if (argc < macro->paramc) if (argc < macro->paramc)
{ {
/* As an extension, a rest argument is allowed to not appear in /* As an extension, variadic arguments are allowed to not appear in
the invocation at all. the invocation at all.
e.g. #define debug(format, args...) something e.g. #define debug(format, args...) something
debug("string"); debug("string");
This is exactly the same as if there had been an empty rest This is exactly the same as if an empty variadic list had been
argument - debug("string", ). */ supplied - debug("string", ). */
if (argc + 1 == macro->paramc && macro->variadic) if (argc + 1 == macro->paramc && macro->variadic)
{ {
if (CPP_PEDANTIC (pfile) && ! macro->syshdr) if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
{
if (CPP_OPTION (pfile, cplusplus))
cpp_error (pfile, CPP_DL_PEDWARN,
"ISO C++11 requires at least one argument "
"for the \"...\" in a variadic macro");
else
cpp_error (pfile, CPP_DL_PEDWARN, cpp_error (pfile, CPP_DL_PEDWARN,
"ISO C99 requires rest arguments to be used"); "ISO C99 requires at least one argument "
"for the \"...\" in a variadic macro");
}
return true; return true;
} }
...@@ -1748,10 +1756,18 @@ replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, ...@@ -1748,10 +1756,18 @@ replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
&& ! CPP_OPTION (pfile, c99) && ! CPP_OPTION (pfile, c99)
&& ! cpp_in_system_header (pfile)) && ! cpp_in_system_header (pfile))
{ {
if (CPP_OPTION (pfile, cplusplus))
cpp_error (pfile, CPP_DL_PEDWARN,
"invoking macro %s argument %d: "
"empty macro arguments are undefined"
" in ISO C++98",
NODE_NAME (node),
src->val.macro_arg.arg_no);
else
cpp_error (pfile, CPP_DL_PEDWARN, cpp_error (pfile, CPP_DL_PEDWARN,
"invoking macro %s argument %d: " "invoking macro %s argument %d: "
"empty macro arguments are undefined" "empty macro arguments are undefined"
" in ISO C90 and ISO C++98", " in ISO C90",
NODE_NAME (node), NODE_NAME (node),
src->val.macro_arg.arg_no); src->val.macro_arg.arg_no);
} }
...@@ -2798,14 +2814,27 @@ parse_params (cpp_reader *pfile, cpp_macro *macro) ...@@ -2798,14 +2814,27 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
if (! CPP_OPTION (pfile, c99) if (! CPP_OPTION (pfile, c99)
&& CPP_OPTION (pfile, cpp_pedantic) && CPP_OPTION (pfile, cpp_pedantic)
&& CPP_OPTION (pfile, warn_variadic_macros)) && CPP_OPTION (pfile, warn_variadic_macros))
{
if (CPP_OPTION (pfile, cplusplus))
cpp_pedwarning
(pfile, CPP_W_VARIADIC_MACROS,
"anonymous variadic macros were introduced in C++11");
else
cpp_pedwarning cpp_pedwarning
(pfile, CPP_W_VARIADIC_MACROS, (pfile, CPP_W_VARIADIC_MACROS,
"anonymous variadic macros were introduced in C99"); "anonymous variadic macros were introduced in C99");
} }
}
else if (CPP_OPTION (pfile, cpp_pedantic) else if (CPP_OPTION (pfile, cpp_pedantic)
&& CPP_OPTION (pfile, warn_variadic_macros)) && CPP_OPTION (pfile, warn_variadic_macros))
{
if (CPP_OPTION (pfile, cplusplus))
cpp_pedwarning (pfile, CPP_W_VARIADIC_MACROS,
"ISO C++ does not permit named variadic macros");
else
cpp_pedwarning (pfile, CPP_W_VARIADIC_MACROS, cpp_pedwarning (pfile, CPP_W_VARIADIC_MACROS,
"ISO C does not permit named variadic macros"); "ISO C does not permit named variadic macros");
}
/* We're at the end, and just expect a closing parenthesis. */ /* We're at the end, and just expect a closing parenthesis. */
token = _cpp_lex_token (pfile); token = _cpp_lex_token (pfile);
...@@ -2894,11 +2923,17 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro) ...@@ -2894,11 +2923,17 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE)) else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE))
{ {
/* While ISO C99 requires whitespace before replacement text /* While ISO C99 requires whitespace before replacement text
in a macro definition, ISO C90 with TC1 allows there characters in a macro definition, ISO C90 with TC1 allows characters
from the basic source character set. */ from the basic source character set there. */
if (CPP_OPTION (pfile, c99)) if (CPP_OPTION (pfile, c99))
{
if (CPP_OPTION (pfile, cplusplus))
cpp_error (pfile, CPP_DL_PEDWARN,
"ISO C++11 requires whitespace after the macro name");
else
cpp_error (pfile, CPP_DL_PEDWARN, cpp_error (pfile, CPP_DL_PEDWARN,
"ISO C99 requires whitespace after the macro name"); "ISO C99 requires whitespace after the macro name");
}
else else
{ {
int warntype = CPP_DL_WARNING; int warntype = CPP_DL_WARNING;
...@@ -3134,8 +3169,8 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) ...@@ -3134,8 +3169,8 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
&& ustrcmp (NODE_NAME (node), (const uchar *) "__STDC_FORMAT_MACROS") && ustrcmp (NODE_NAME (node), (const uchar *) "__STDC_FORMAT_MACROS")
/* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS are mentioned /* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS are mentioned
in the C standard, as something that one must use in C++. in the C standard, as something that one must use in C++.
However DR#593 indicates that these aren't actually mentioned However DR#593 and C++11 indicate that they play no role in C++.
in the C++ standard. We special-case them anyway. */ We special-case them anyway. */
&& ustrcmp (NODE_NAME (node), (const uchar *) "__STDC_LIMIT_MACROS") && ustrcmp (NODE_NAME (node), (const uchar *) "__STDC_LIMIT_MACROS")
&& ustrcmp (NODE_NAME (node), (const uchar *) "__STDC_CONSTANT_MACROS")) && ustrcmp (NODE_NAME (node), (const uchar *) "__STDC_CONSTANT_MACROS"))
node->flags |= NODE_WARN; node->flags |= NODE_WARN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment