]> granicus.if.org Git - clang/commitdiff
Minor improvements to some C99 variadic-macro-related diagnostics.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 22 Jun 2012 23:59:08 +0000 (23:59 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 22 Jun 2012 23:59:08 +0000 (23:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159054 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticLexKinds.td
lib/Lex/PPMacroExpansion.cpp
lib/Lex/TokenLexer.cpp
test/Misc/warning-flags.c
test/Preprocessor/macro_fn.c
test/SemaCXX/cxx98-compat-pedantic.cpp

index 3bad7b90121cb329a4b710c8d6f9ab571467e586..2e8e9c5005a011f722ce799acd800847dfc4a7f1 100644 (file)
@@ -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<VariadicMacros>;
 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<DiagGroup<"embedded-directive">>;
 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<GNU>;
 def ext_empty_fnmacro_arg : Extension<
-  "empty macro arguments were standardized in C99">;
+  "empty macro arguments are a C99 feature">, InGroup<C99>;
 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<CXX98CompatPedantic>, 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<GNU>;
 def err_unterm_macro_invoc : Error<
   "unterminated function-like macro invocation">;
 def err_too_many_args_in_macro_invoc : Error<
index a5337867b1b3dffa78b00cb18b90c6fe2b25fb5f..c6aabde03e0a657bb34c63edb493111510de7969 100644 (file)
@@ -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:
index 81c9d0ab7ae297fb39d98a345366afb35360e00c..0f1004f2b2f766ddee5a97aabe078c57875433e6 100644 (file)
@@ -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) &&
index 035dd34fb36629a4a4bd231ad34eade6ab4d2338..3e2140f36fde273aff075e39ca66e8b30a67bbde 100644 (file)
@@ -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
index 85733b4af0689fee3a41ee3a56207bd95545240b..f93d52c7eda7b9c3697782110e711950cb5964ab 100644 (file)
@@ -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. */
index 00532d5ac0731b56e377cdd78bcd8f2ff7c4135e..c07f64e614d25f4c17b32a244f605674c46db255 100644 (file)
@@ -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}}