From 786bf3ad556b412cc664a268d81a0885a88b6aee Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 13 Nov 2017 15:32:34 +0000 Subject: [Diagnostic Patch] don't print column zero https://gcc.gnu.org/ml/gcc-patches/2017-10/msg01911.html * diagnostic.c (maybe_line_and_column): New. (diagnostic_get_location_text): Use it. (diagnostic_report_current_module): Likewise. (test_diagnostic_get_location_text): Add tests. * lib/gcc-dg.exp (process-message): Use -: for no column. * c-c++-common/cilk-plus/CK/cilk_for_grain_errors.c: Mark elided column messages. * c-c++-common/cpp/pr58844-1.c: Likewise. * c-c++-common/cpp/pr58844-2.c: Likewise. * c-c++-common/cpp/warning-zero-location.c: Likewise. * g++.dg/diagnostic/pr77949.C: Likewise. * g++.dg/gomp/macro-4.C: Likewise. * gcc.dg/Wunknownprag.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/Wunknown-pragmas-1.c: Likewise. * gcc.dg/cpp/Wunused.c: Likewise. * gcc.dg/cpp/misspelled-directive-1.c: Likewise. * gcc.dg/cpp/redef2.c: Likewise. * gcc.dg/cpp/redef3.c: Likewise. * gcc.dg/cpp/redef4.c: Likewise. * gcc.dg/cpp/trad/Wunused.c: Likewise. * gcc.dg/cpp/trad/argcount.c: Likewise. * gcc.dg/cpp/trad/comment-3.c: Likewise. * gcc.dg/cpp/trad/comment.c: Likewise. * gcc.dg/cpp/trad/defined.c: Likewise. * gcc.dg/cpp/trad/directive.c: Likewise. * gcc.dg/cpp/trad/funlike-3.c: Likewise. * gcc.dg/cpp/trad/funlike.c: Likewise. * gcc.dg/cpp/trad/literals-2.c: Likewise. * gcc.dg/cpp/trad/macro.c: Likewise. * gcc.dg/cpp/trad/pr65238-4.c: Likewise. * gcc.dg/cpp/trad/recurse-1.c: Likewise. * gcc.dg/cpp/trad/recurse-2.c: Likewise. * gcc.dg/cpp/trad/redef2.c: Likewise. * gcc.dg/cpp/ucnid-11.c: Likewise. * gcc.dg/cpp/unc1.c: Likewise. * gcc.dg/cpp/unc2.c: Likewise. * gcc.dg/cpp/unc3.c: Likewise. * gcc.dg/cpp/unc4.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/empty-source-2.c: Likewise. * gcc.dg/empty-source-3.c: Likewise. * gcc.dg/gomp/macro-4.c: Likewise. * gcc.dg/noncompile/pr35447-1.c: Likewise. * gcc.dg/plugin/location-overflow-test-1.c: Likewise. * gcc.dg/pr20245-1.c: Likewise. * gcc.dg/pr28419.c: Likewise. * gcc.dg/rtl/truncated-rtl-file.c: Likewise. * gcc.dg/unclosed-init.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254691 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/c-c++-common/cpp/pr58844-1.c | 4 ++-- gcc/testsuite/c-c++-common/cpp/pr58844-2.c | 4 ++-- gcc/testsuite/c-c++-common/cpp/warning-zero-location.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'gcc/testsuite/c-c++-common/cpp') diff --git a/gcc/testsuite/c-c++-common/cpp/pr58844-1.c b/gcc/testsuite/c-c++-common/cpp/pr58844-1.c index 3abf8a76803..2a2e277b0fc 100644 --- a/gcc/testsuite/c-c++-common/cpp/pr58844-1.c +++ b/gcc/testsuite/c-c++-common/cpp/pr58844-1.c @@ -4,5 +4,5 @@ #define A x######x int A = 1; -#define A x######x /* { dg-message "previous definition" } */ -#define A x##x /* { dg-warning "redefined" } */ +#define A x######x /* { dg-message "-:previous definition" } */ +#define A x##x /* { dg-warning "-:redefined" } */ diff --git a/gcc/testsuite/c-c++-common/cpp/pr58844-2.c b/gcc/testsuite/c-c++-common/cpp/pr58844-2.c index 1e219152fc5..52993b314be 100644 --- a/gcc/testsuite/c-c++-common/cpp/pr58844-2.c +++ b/gcc/testsuite/c-c++-common/cpp/pr58844-2.c @@ -4,5 +4,5 @@ #define A x######x int A = 1; -#define A x######x /* { dg-message "previous definition" } */ -#define A x##x /* { dg-warning "redefined" } */ +#define A x######x /* { dg-message "-:previous definition" } */ +#define A x##x /* { dg-warning "-:redefined" } */ diff --git a/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c b/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c index 2b9c9a95217..57544b6aff1 100644 --- a/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c +++ b/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c @@ -3,6 +3,6 @@ { dg-do compile } */ -#define _GNU_SOURCE /* { dg-warning "redefined" } */ +#define _GNU_SOURCE /* { dg-warning "-:redefined" } */ /* { dg-message "" "#define _GNU_SOURCE" {target *-*-* } 0 } */ -- cgit v1.2.1 From 86136db8efde2401b066fee95c546365b75dce2e Mon Sep 17 00:00:00 2001 From: tromey Date: Mon, 13 Nov 2017 20:17:42 +0000 Subject: Implement __VA_OPT__ This implements __VA_OPT__, a new preprocessor feature added in C++2A. The paper can be found here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0306r4.html gcc/ChangeLog * doc/cpp.texi (Variadic Macros): Document __VA_OPT__. gcc/testsuite/ChangeLog * c-c++-common/cpp/va-opt-pedantic.c: New file. * c-c++-common/cpp/va-opt.c: New file. * c-c++-common/cpp/va-opt-error.c: New file. libcpp/ChangeLog * pch.c (cpp_read_state): Set n__VA_OPT__. * macro.c (vaopt_state): New class. (_cpp_arguments_ok): Check va_opt flag. (replace_args, create_iso_definition): Use vaopt_state. * lex.c (lex_identifier_intern): Possibly issue errors for __VA_OPT__. (lex_identifier): Likewise. (maybe_va_opt_error): New function. * internal.h (struct lexer_state) : Update comment. (struct spec_nodes) : New field. * init.c (struct lang_flags) : New field. (lang_defaults): Add entries for C++2A. Update all entries for va_opt. (cpp_set_lang): Initialize va_opt. * include/cpplib.h (struct cpp_options) : New field. * identifiers.c (_cpp_init_hashtable): Initialize n__VA_OPT__. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254707 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/c-c++-common/cpp/va-opt-error.c | 28 ++++++++++++++++ gcc/testsuite/c-c++-common/cpp/va-opt-pedantic.c | 5 +++ gcc/testsuite/c-c++-common/cpp/va-opt.c | 42 ++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/cpp/va-opt-error.c create mode 100644 gcc/testsuite/c-c++-common/cpp/va-opt-pedantic.c create mode 100644 gcc/testsuite/c-c++-common/cpp/va-opt.c (limited to 'gcc/testsuite/c-c++-common/cpp') diff --git a/gcc/testsuite/c-c++-common/cpp/va-opt-error.c b/gcc/testsuite/c-c++-common/cpp/va-opt-error.c new file mode 100644 index 00000000000..f32f0551723 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/va-opt-error.c @@ -0,0 +1,28 @@ +/* { dg-do preprocess }*/ +/* { dg-options "-std=gnu99" { target c } } */ +/* { dg-options "-std=c++2a" { target c++ } } */ + +#define ERR1(x) __VA_OPT__ /* { dg-warning "__VA_OPT__ can only appear" } */ +#define ERR2(x) __VA_OPT__( /* { dg-warning "can only appear" } */ +#define ERR3(x) __VA_OPT__() /* { dg-warning "can only appear" } */ + +#define ERR4(x,...) __VA_OPT__ /* { dg-error "unterminated __VA_OPT__" } */ +#define ERR5(x,...) __VA_OPT__( /* { dg-error "unterminated" } */ +#define ERR6(x,...) __VA_OPT__(() /* { dg-error "unterminated" } */ + +#define ERR7(x,...) __VA_OPT__(__VA_OPT__) /* { dg-error "may not appear" } */ +#define ERR7(x,...) __VA_OPT__(__VA_OPT__()) /* { dg-error "may not appear" } */ + +#define ERR8(x, y,...) x __VA_OPT__(##) y /* { dg-error "either end" } */ +#define ERR9(x, y,...) x __VA_OPT__(x ##) y /* { dg-error "either end" } */ +#define ERRA(x, y,...) x x __VA_OPT__(## y) /* { dg-error "either end" } */ + +#define ERRB __VA_OPT__ /* { dg-warning "can only appear" } */ +#define ERRC(__VA_OPT__) x /* { dg-warning "can only appear" } */ + +__VA_OPT__ /* { dg-warning "can only appear" } */ + +#define ERRD(x) +ERRD(__VA_OPT__) /* { dg-warning "can only appear" } */ + +#define __VA_OPT__ /* { dg-warning "can only appear" } */ diff --git a/gcc/testsuite/c-c++-common/cpp/va-opt-pedantic.c b/gcc/testsuite/c-c++-common/cpp/va-opt-pedantic.c new file mode 100644 index 00000000000..5887bf5a484 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/va-opt-pedantic.c @@ -0,0 +1,5 @@ +/* { dg-do preprocess }*/ +/* { dg-options "-std=c11 -pedantic-errors" { target c } } */ +/* { dg-options "-std=c++17 -pedantic-errors" { target c++ } } */ + +#define CALL(F, ...) F (7 __VA_OPT__(,) __VA_ARGS__) /* { dg-error "__VA_OPT__ is not available" } */ diff --git a/gcc/testsuite/c-c++-common/cpp/va-opt.c b/gcc/testsuite/c-c++-common/cpp/va-opt.c new file mode 100644 index 00000000000..243d33b2cf1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/va-opt.c @@ -0,0 +1,42 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" { target c } } */ +/* { dg-options "-std=c++2a" { target c++ } } */ + +extern void f0 (void); +extern void f1 (int); +extern void f2 (int, int); +extern void f3 (int, int, int); +extern void f4 (int, int, int, int); +extern int s (const char *); + +#define CALL(F, ...) F (7 __VA_OPT__(,) __VA_ARGS__) +#define CP(F, X, Y, ...) F (__VA_OPT__(X ## Y,) __VA_ARGS__) +#define CS(F, ...) F(__VA_OPT__(s(# __VA_ARGS__))) +#define D(F, ...) F(__VA_OPT__(__VA_ARGS__) __VA_OPT__(,) __VA_ARGS__) +#define CALL0(...) __VA_OPT__(f2)(0 __VA_OPT__(,)__VA_ARGS__) + +void t (void) +{ + CALL (f1); + CALL (f1, ); + CALL (f2, 1); + CALL (f3, 1, 2); + + int one = 1; + int two = 2; + int onetwo = 23; + + CP (f0, one, two); + CP (f0, one, two, ); + CP (f2, one, two, 3); + + CS (f0); + CS (f1, 1, 2, 3, 4); + + D (f0); + D (f2, 1); + D (f4, 1, 2); + + CALL0 (); + CALL0 (23); +} -- cgit v1.2.1