===================================================================
@@ -6411,8 +6411,10 @@
The form with asm-goto-operands is valid if and only if the
asm-qualifier-list contains goto, and is the only allowed form in that case.
- Duplicate asm-qualifiers are not allowed. */
+ Duplicate asm-qualifiers are not allowed.
+ The :: token is considered equivalent to two consecutive : tokens. */
+
static tree
c_parser_asm_statement (c_parser *parser)
{
@@ -6509,11 +6511,21 @@
nsections = 3 + is_goto;
for (section = 0; section < nsections; ++section)
{
- if (!c_parser_require (parser, CPP_COLON,
- is_goto
- ? G_("expected %<:%>")
- : G_("expected %<:%> or %<)%>"),
- UNKNOWN_LOCATION, is_goto))
+ if (c_parser_next_token_is (parser, CPP_SCOPE))
+ {
+ ++section;
+ if (section == nsections)
+ {
+ c_parser_error (parser, "expected %<)%>");
+ goto error_close_paren;
+ }
+ c_parser_consume_token (parser);
+ }
+ else if (!c_parser_require (parser, CPP_COLON,
+ is_goto
+ ? G_("expected %<:%>")
+ : G_("expected %<:%> or %<)%>"),
+ UNKNOWN_LOCATION, is_goto))
goto error_close_paren;
/* Once past any colon, we're no longer a simple asm. */
@@ -6520,6 +6532,7 @@
simple = false;
if ((!c_parser_next_token_is (parser, CPP_COLON)
+ && !c_parser_next_token_is (parser, CPP_SCOPE)
&& !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|| section == 3)
switch (section)
===================================================================
@@ -0,0 +1,27 @@
+/* Test :: token handling in asm. */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu2x" } */
+
+void
+f (void)
+{
+ asm ("");
+ asm ("" : );
+ asm ("" : :);
+ asm ("" ::);
+ asm ("" : : :);
+ asm ("" :: :);
+ asm ("" : ::);
+ asm goto ("" : : : : lab);
+ asm goto ("" :: : : lab);
+ asm goto ("" : :: : lab);
+ asm goto ("" : : :: lab);
+ asm goto ("" :: :: lab);
+ lab: ;
+ /* Test errors when :: is at the end of asm and only one : allowed. */
+ asm ("" : : ::); /* { dg-error "expected" } */
+ asm ("" :: ::); /* { dg-error "expected" } */
+ asm goto ("" : : : :: lab); /* { dg-error "expected" } */
+ asm goto ("" :: : :: lab); /* { dg-error "expected" } */
+ asm goto ("" : :: :: lab); /* { dg-error "expected" } */
+}
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :) /* { dg-error "does not give a valid preprocessing token" } */
+CONCAT (::, >)
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token not in C17. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c17 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :) /* { dg-error "does not give a valid preprocessing token" } */
+CONCAT (::, >)
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token in C2x. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :)
+CONCAT (::, >) /* { dg-error "does not give a valid preprocessing token" } */
===================================================================
@@ -0,0 +1,11 @@
+/* Test :: token in C2x: preprocessed output. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c2x -pedantic-errors -P" } */
+
+#define COLON() :
+#define TEST() ABC
+
+/* This must have a space inserted between the two ':' tokens in
+ preprocessed output. */
+TEST()COLON()COLON()TEST()
+/* { dg-final { scan-file c2x-scope-2.i "ABC: :ABC" } } */
===================================================================
@@ -0,0 +1,7 @@
+/* Test :: token not in C90. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c90 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :) /* { dg-error "does not give a valid preprocessing token" } */
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token not in C94. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=iso9899:199409 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :) /* { dg-error "does not give a valid preprocessing token" } */
+CONCAT (::, >)
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token not in C99. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :) /* { dg-error "does not give a valid preprocessing token" } */
+CONCAT (::, >)
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token in gnu11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu11 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :)
+CONCAT (::, >) /* { dg-error "does not give a valid preprocessing token" } */
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token in gnu17. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu17 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :)
+CONCAT (::, >) /* { dg-error "does not give a valid preprocessing token" } */
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token in gnu89. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu89 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :)
+CONCAT (::, >) /* { dg-error "does not give a valid preprocessing token" } */
===================================================================
@@ -0,0 +1,8 @@
+/* Test :: token in gnu99. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
+
+#define CONCAT(x, y) x ## y
+
+CONCAT (:, :)
+CONCAT (::, >) /* { dg-error "does not give a valid preprocessing token" } */
===================================================================
@@ -483,6 +483,9 @@
/* Nonzero for C++2a __VA_OPT__ feature. */
unsigned char va_opt;
+ /* Nonzero for the '::' token. */
+ unsigned char scope;
+
/* Holds the name of the target (execution) character set. */
const char *narrow_charset;
===================================================================
@@ -92,32 +92,33 @@
char trigraphs;
char utf8_char_literals;
char va_opt;
+ char scope;
};
static const struct lang_flags lang_defaults[] =
-{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt */
- /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0,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XX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0 },
- /* GNUCXX2A */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1 },
- /* CXX2A */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 },
- /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope*/
+ /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
+ /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1 },
+ /* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1 },
+ /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1 },
+ /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1 },
+ /* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
+ /* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
+ /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
+ /* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
+ /* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
+ /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1 },
+ /* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
+ /* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1 },
+ /* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1 },
+ /* CXX11 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1 },
+ /* GNUCXX14 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 },
+ /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1 },
+ /* GNUCXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 },
+ /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 },
+ /* GNUCXX2A */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 },
+ /* CXX2A */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 },
+ /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
/* Sets internal flags correctly for a given language. */
@@ -143,6 +144,7 @@
CPP_OPTION (pfile, trigraphs) = l->trigraphs;
CPP_OPTION (pfile, utf8_char_literals) = l->utf8_char_literals;
CPP_OPTION (pfile, va_opt) = l->va_opt;
+ CPP_OPTION (pfile, scope) = l->scope;
}
/* Initialize library global state. */
===================================================================
@@ -3104,7 +3104,7 @@
case ':':
result->type = CPP_COLON;
- if (*buffer->cur == ':' && CPP_OPTION (pfile, cplusplus))
+ if (*buffer->cur == ':' && CPP_OPTION (pfile, scope))
buffer->cur++, result->type = CPP_SCOPE;
else if (*buffer->cur == '>' && CPP_OPTION (pfile, digraphs))
{