------- Comment #4 from manu at gcc dot gnu dot org 2007-11-09 02:09 ------- (In reply to comment #3) > Anyone know where in the preprocessor this should be done? I.e. which > function > in libcpp? > > If someone would let me know, I'll write a patch. >
This is the patch I was playing with before giving up. I don't know how to get the correct line numbers so I tried 3 possibilities. Index: libcpp/macro.c =================================================================== --- libcpp/macro.c (revision 129897) +++ libcpp/macro.c (working copy) @@ -681,9 +681,39 @@ collect_args (cpp_reader *pfile, const c } else { + unsigned int i; + /* A single empty argument is counted as no argument. */ if (argc == 1 && macro->paramc == 0 && args[0].count == 0) argc = 0; + + for (i = 0; i < argc; i++) + { + if (args[i].count == 0 + && CPP_OPTION (pfile, pedantic) + && CPP_OPTION (pfile, lang) == CLK_GNUC89) + { + if (pfile->context->prev && pfile->context->prev->macro) + cpp_error_with_line (pfile, CPP_DL_PEDWARN, + pfile->context->prev->macro->value.macro->line, 0, + "invoking macro \"%s\" " + "with empty arguments is undefined in ISO C90", + NODE_NAME (node)); + else if (pfile->context->prev || pfile->state.in_directive) + cpp_error_with_line (pfile, CPP_DL_PEDWARN, + node->value.macro->line, 0, + "invoking macro \"%s\" " + "with empty arguments is undefined in ISO C90", + NODE_NAME (node)); + else + cpp_error (pfile, CPP_DL_PEDWARN, + "invoking macro \"%s\" " + "with empty arguments is undefined in ISO C90", + NODE_NAME (node)); + + } + } + if (_cpp_arguments_ok (pfile, macro, node, argc)) { /* GCC has special semantics for , ## b where b is a varargs And this is the testcase I am using: /* { dg-do compile } */ /* { dg-options "-std=c90 -pedantic-errors" } */ #define f2(a,b,c) a; b; c; #define f(a,b) f2(a,,b) /* { dg-warning "macro "f2" with empty arguments } */ #define f3(a) a #define g() 0 void foo(void) { f(0,0); f2(0,,0); /* { dg-warning "macro "f2" with empty arguments } */ f3(); /* { dg-warning "macro "f3" with empty arguments } */ g(); } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33305