From: Richard Smith Date: Fri, 22 Jun 2012 23:59:08 +0000 (+0000) Subject: Minor improvements to some C99 variadic-macro-related diagnostics. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f728cd37476c6588b06d241fa778d2df6e277da;p=clang Minor improvements to some C99 variadic-macro-related diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159054 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 3bad7b9012..2e8e9c5005 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -252,7 +252,7 @@ def ext_pp_comma_expr : Extension<"comma operator in operand of #if">; def ext_pp_bad_vaargs_use : Extension< "__VA_ARGS__ can only appear in the expansion of a C99 variadic macro">; def ext_pp_macro_redef : ExtWarn<"%0 macro redefined">; -def ext_variadic_macro : Extension<"variadic macros were introduced in C99">, +def ext_variadic_macro : Extension<"variadic macros are a C99 feature">, InGroup; def warn_cxx98_compat_variadic_macro : Warning< "variadic macros are incompatible with C++98">, @@ -265,12 +265,14 @@ def ext_embedded_directive : Extension< "embedding a directive within macro arguments has undefined behavior">, InGroup>; def ext_missing_varargs_arg : Extension< - "varargs argument missing, but tolerated as an extension">; + "must specify at least one argument for '...' parameter of variadic macro">, + InGroup; def ext_empty_fnmacro_arg : Extension< - "empty macro arguments were standardized in C99">; + "empty macro arguments are a C99 feature">, InGroup; def warn_cxx98_compat_empty_fnmacro_arg : Warning< - "empty macro argument list is incompatible with C++98">, + "empty macro arguments are incompatible with C++98">, InGroup, DefaultIgnore; +def note_macro_here : Note<"macro %0 defined here">; def err_pp_invalid_directive : Error<"invalid preprocessing directive">; def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal; @@ -395,7 +397,7 @@ def err_paste_at_start : Error< "'##' cannot appear at start of macro expansion">; def err_paste_at_end : Error<"'##' cannot appear at end of macro expansion">; def ext_paste_comma : Extension< - "Use of comma pasting extension is non-portable">; + "token pasting of ',' and __VA_ARGS__ is a GNU extension">, InGroup; def err_unterm_macro_invoc : Error< "unterminated function-like macro invocation">; def err_too_many_args_in_macro_invoc : Error< diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index a5337867b1..c6aabde03e 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -487,10 +487,12 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName, } else if (MI->isVariadic() && (NumActuals+1 == MinArgsExpected || // A(x, ...) -> A(X) (NumActuals == 0 && MinArgsExpected == 2))) {// A(x,...) -> A() - // Varargs where the named vararg parameter is missing: ok as extension. - // #define A(x, ...) - // A("blah") + // Varargs where the named vararg parameter is missing: OK as extension. + // #define A(x, ...) + // A("blah") Diag(Tok, diag::ext_missing_varargs_arg); + Diag(MI->getDefinitionLoc(), diag::note_macro_here) + << MacroName.getIdentifierInfo(); // Remember this occurred, allowing us to elide the comma when used for // cases like: diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp index 81c9d0ab7a..0f1004f2b2 100644 --- a/lib/Lex/TokenLexer.cpp +++ b/lib/Lex/TokenLexer.cpp @@ -252,9 +252,9 @@ void TokenLexer::ExpandFunctionArguments() { const Token *ArgToks = ActualArgs->getUnexpArgument(ArgNo); unsigned NumToks = MacroArgs::getArgLength(ArgToks); if (NumToks) { // Not an empty argument? - // If this is the GNU ", ## __VA_ARG__" extension, and we just learned - // that __VA_ARG__ expands to multiple tokens, avoid a pasting error when - // the expander trys to paste ',' with the first token of the __VA_ARG__ + // If this is the GNU ", ## __VA_ARGS__" extension, and we just learned + // that __VA_ARGS__ expands to multiple tokens, avoid a pasting error when + // the expander trys to paste ',' with the first token of the __VA_ARGS__ // expansion. if (PasteBefore && ResultToks.size() >= 2 && ResultToks[ResultToks.size()-2].is(tok::comma) && diff --git a/test/Misc/warning-flags.c b/test/Misc/warning-flags.c index 035dd34fb3..3e2140f36f 100644 --- a/test/Misc/warning-flags.c +++ b/test/Misc/warning-flags.c @@ -17,7 +17,7 @@ This test serves two purposes: The list of warnings below should NEVER grow. It should gradually shrink to 0. -CHECK: Warnings without flags (241): +CHECK: Warnings without flags (238): CHECK-NEXT: ext_anonymous_struct_union_qualified CHECK-NEXT: ext_binary_literal CHECK-NEXT: ext_cast_fn_obj @@ -25,7 +25,6 @@ CHECK-NEXT: ext_delete_void_ptr_operand CHECK-NEXT: ext_designated_init CHECK-NEXT: ext_duplicate_declspec CHECK-NEXT: ext_ellipsis_exception_spec -CHECK-NEXT: ext_empty_fnmacro_arg CHECK-NEXT: ext_enum_friend CHECK-NEXT: ext_enum_value_not_int CHECK-NEXT: ext_enumerator_list_comma @@ -44,12 +43,10 @@ CHECK-NEXT: ext_integer_complex CHECK-NEXT: ext_integer_increment_complex CHECK-NEXT: ext_invalid_sign_spec CHECK-NEXT: ext_missing_declspec -CHECK-NEXT: ext_missing_varargs_arg CHECK-NEXT: ext_missing_whitespace_after_macro_name CHECK-NEXT: ext_new_paren_array_nonconst CHECK-NEXT: ext_nonstandard_escape CHECK-NEXT: ext_param_not_declared -CHECK-NEXT: ext_paste_comma CHECK-NEXT: ext_plain_complex CHECK-NEXT: ext_pp_bad_vaargs_use CHECK-NEXT: ext_pp_comma_expr diff --git a/test/Preprocessor/macro_fn.c b/test/Preprocessor/macro_fn.c index 85733b4af0..f93d52c7ed 100644 --- a/test/Preprocessor/macro_fn.c +++ b/test/Preprocessor/macro_fn.c @@ -4,8 +4,8 @@ #define zero() 0 #define one(x) 0 #define two(x, y) 0 -#define zero_dot(...) 0 /* expected-warning {{variadic macros were introduced in C99}} */ -#define one_dot(x, ...) 0 /* expected-warning {{variadic macros were introduced in C99}} */ +#define zero_dot(...) 0 /* expected-warning {{variadic macros are a C99 feature}} */ +#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} expected-note 2{{macro 'one_dot' defined here}} */ zero() zero(1); /* expected-error {{too many arguments provided to function-like macro invocation}} */ @@ -19,25 +19,25 @@ one(a, b) /* expected-error {{too many arguments provided to function-li two() /* expected-error {{too few arguments provided to function-like macro invocation}} */ two(a) /* expected-error {{too few arguments provided to function-like macro invocation}} */ two(a,b) -two(a, ) /* expected-warning {{empty macro arguments were standardized in C99}} */ +two(a, ) /* expected-warning {{empty macro arguments are a C99 feature}} */ two(a,b,c) /* expected-error {{too many arguments provided to function-like macro invocation}} */ two( - , /* expected-warning {{empty macro arguments were standardized in C99}} */ - , /* expected-warning {{empty macro arguments were standardized in C99}} \ + , /* expected-warning {{empty macro arguments are a C99 feature}} */ + , /* expected-warning {{empty macro arguments are a C99 feature}} \ expected-error {{too many arguments provided to function-like macro invocation}} */ ) -two(,) /* expected-warning 2 {{empty macro arguments were standardized in C99}} */ +two(,) /* expected-warning 2 {{empty macro arguments are a C99 feature}} */ /* PR4006 & rdar://6807000 */ -#define e(...) __VA_ARGS__ /* expected-warning {{variadic macros were introduced in C99}} */ +#define e(...) __VA_ARGS__ /* expected-warning {{variadic macros are a C99 feature}} */ e(x) e() zero_dot() -one_dot(x) /* empty ... argument: expected-warning {{varargs argument missing, but tolerated as an extension}} */ -one_dot() /* empty first argument, elided ...: expected-warning {{varargs argument missing, but tolerated as an extension}} */ +one_dot(x) /* empty ... argument: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */ +one_dot() /* empty first argument, elided ...: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */ /* rdar://6816766 - Crash with function-like macro test at end of directive. */ diff --git a/test/SemaCXX/cxx98-compat-pedantic.cpp b/test/SemaCXX/cxx98-compat-pedantic.cpp index 00532d5ac0..c07f64e614 100644 --- a/test/SemaCXX/cxx98-compat-pedantic.cpp +++ b/test/SemaCXX/cxx98-compat-pedantic.cpp @@ -9,7 +9,7 @@ #line 32768 // expected-warning {{#line number greater than 32767 is incompatible with C++98}} #define VA_MACRO(x, ...) x // expected-warning {{variadic macros are incompatible with C++98}} -VA_MACRO(,x) // expected-warning {{empty macro argument list is incompatible with C++98}} +VA_MACRO(,x) // expected-warning {{empty macro arguments are incompatible with C++98}} ; // expected-warning {{extra ';' outside of a function is incompatible with C++98}}