gcc/libcpp
Joseph Myers 93313b94fe Handle :: tokens in C for C2x.
As part of adding [[]]-style attributes, C2x adds the token :: for use
in scoped attribute names.

This patch adds corresponding support for that token in C to GCC.  The
token is supported both for C2x and for older gnu* standards (on the
basis that extensions are normally supported in older gnu* versions;
people will expect to be able to use [[]] attributes, before C2x is
the default, without needing to use -std=gnu2x).

There are no cases in older C standards where the token : can be
followed by a token starting with : in syntactically valid sources;
the only cases the :: token could break in older standard C thus are
ones involving concatenation of pp-tokens where the result does not
end up as tokens (e.g., gets stringized).  In GNU C extensions, the
main case where :: might appear in existing sources is in asm
statements, and the C parser is thus made to handle it like two
consecutive : tokens, which the C++ parser already does.  A limited
test of various positionings of :: in asm statements is added to the
testsuite (in particular, to cover the syntax error when :: means too
many colons but a single : would be OK), but existing tests cover a
variety of styles there anyway.

Technically there are cases in Objective-C and OpenMP for which this
also changes how previously valid code is lexed: the objc-selector-arg
syntax allows multiple consecutive : tokens (although I don't think
they are particularly useful there), while OpenMP syntax includes
array section syntax such as [:] which, before :: was a token, could
also be written as [::> (there might be other OpenMP cases potentially
affected, I didn't check all the OpenMP syntax in detail).  I don't
think either of those cases affects the basis for supporting the ::
token in all -std=gnu* modes, or that there is any obvious need to
special-case handling of CPP_SCOPE tokens for those constructs the way
there is for asm statements.

cpp_avoid_paste, which determines when spaces need adding between
tokens in preprocessed output where there wouldn't otherwise be
whitespace between them (e.g. if stringized), already inserts space
between : and : unconditionally, rather than only for C++, so no
change is needed there (but a C2x test is added that such space is
indeed inserted).

Bootstrapped with no regressions on x86-64-pc-linux-gnu.

gcc/c:
	* c-parser.c (c_parser_asm_statement): Handle CPP_SCOPE like two
	CPP_COLON tokens.

gcc/testsuite:
	* gcc.dg/asm-scope-1.c, gcc.dg/cpp/c11-scope-1.c,
	gcc.dg/cpp/c17-scope-1.c, gcc.dg/cpp/c2x-scope-1.c,
	gcc.dg/cpp/c2x-scope-2.c, gcc.dg/cpp/c90-scope-1.c,
	gcc.dg/cpp/c94-scope-1.c, gcc.dg/cpp/c99-scope-1.c,
	gcc.dg/cpp/gnu11-scope-1.c, gcc.dg/cpp/gnu17-scope-1.c,
	gcc.dg/cpp/gnu89-scope-1.c, gcc.dg/cpp/gnu99-scope-1.c: New tests.

libcpp:
	* include/cpplib.h (struct cpp_options): Add member scope.
	* init.c (struct lang_flags, lang_defaults): Likewise.
	(cpp_set_lang): Set scope member of pfile.
	* lex.c (_cpp_lex_direct): Test CPP_OPTION (pfile, scope) not
	CPP_OPTION (pfile, cplusplus) for creating CPP_SCOPE tokens.

From-SVN: r276434
2019-10-02 01:08:40 +01:00
..
include Handle :: tokens in C for C2x. 2019-10-02 01:08:40 +01:00
po * zh_TW.po: Update. 2019-08-09 23:02:08 +01:00
ChangeLog Handle :: tokens in C for C2x. 2019-10-02 01:08:40 +01:00
ChangeLog.jit
Makefile.in Update copyright years. 2019-01-01 13:31:55 +01:00
aclocal.m4 Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
charset.c charset.c (UCS_LIMIT): New macro. 2019-09-26 21:43:51 +00:00
config.in Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
configure iconv.m4 (AM_ICONV_LINK): Don't overwrite CPPFLAGS. 2018-11-07 15:41:21 -07:00
configure.ac Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
directives-only.c [Preprocessor] small cleanups 2019-08-28 18:43:37 +00:00
directives.c [preprocessor] Popping "" file names 2019-09-06 12:54:19 +00:00
errors.c Update copyright years. 2019-01-01 13:31:55 +01:00
expr.c Remove Cell Broadband Engine SPU targets 2019-09-03 15:08:28 +00:00
files.c [preprocessor/91639] #includes at EOF 2019-09-05 11:23:48 +00:00
identifiers.c Update copyright years. 2019-01-01 13:31:55 +01:00
init.c Handle :: tokens in C for C2x. 2019-10-02 01:08:40 +01:00
internal.h Support extended characters in C/C++ identifiers (PR c/67224) 2019-09-19 20:56:11 +01:00
lex.c Handle :: tokens in C for C2x. 2019-10-02 01:08:40 +01:00
line-map.c [preprocessor/91639] #includes at EOF 2019-09-05 11:23:48 +00:00
location-example.txt PR preprocessor/83173: Enhance -fdump-internal-locations output 2018-11-27 16:04:31 +00:00
macro.c Update copyright years. 2019-01-01 13:31:55 +01:00
makeucnid.c Update copyright years. 2019-01-01 13:31:55 +01:00
mkdeps.c PR c++/61339 - add mismatch between struct and class [-Wmismatched-tags] to non-bugs 2019-07-09 12:32:49 -06:00
pch.c Update copyright years. 2019-01-01 13:31:55 +01:00
symtab.c Improve memory statistics report readability. 2019-02-26 17:27:52 +00:00
system.h Update copyright years. 2019-01-01 13:31:55 +01:00
traditional.c Update copyright years. 2019-01-01 13:31:55 +01:00
ucnid.h Update copyright years. 2019-01-01 13:31:55 +01:00
ucnid.tab Update copyright years. 2019-01-01 13:31:55 +01:00