2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Written by Mark Mitchell <mark@codesourcery.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
25 #include "c-family/c-common.h"
27 #include "stringpool.h"
29 #include "print-tree.h"
31 #include "trans-mem.h"
34 #include "c-family/c-objc.h"
36 #include "tree-pretty-print.h"
38 #include "gomp-constants.h"
39 #include "omp-general.h"
40 #include "omp-offload.h"
41 #include "c-family/c-indentation.h"
43 #include "cp-cilkplus.h"
44 #include "gcc-rich-location.h"
45 #include "tree-iterator.h"
50 /* The cp_lexer_* routines mediate between the lexer proper (in libcpp
51 and c-lex.c) and the C++ parser. */
53 static cp_token eof_token
=
55 CPP_EOF
, RID_MAX
, 0, false, false, false, 0, { NULL
}
58 /* The various kinds of non integral constant we encounter. */
59 enum non_integral_constant
{
61 /* floating-point literal */
65 /* %<__FUNCTION__%> */
67 /* %<__PRETTY_FUNCTION__%> */
75 /* %<typeid%> operator */
77 /* non-constant compound literals */
85 /* an array reference */
91 /* the address of a label */
105 /* calls to overloaded operators */
109 /* a comma operator */
111 /* a call to a constructor */
113 /* a transaction expression */
117 /* The various kinds of errors about name-lookup failing. */
118 enum name_lookup_error
{
123 /* is not a class or namespace */
125 /* is not a class, namespace, or enumeration */
129 /* The various kinds of required token */
130 enum required_token
{
132 RT_SEMICOLON
, /* ';' */
133 RT_OPEN_PAREN
, /* '(' */
134 RT_CLOSE_BRACE
, /* '}' */
135 RT_OPEN_BRACE
, /* '{' */
136 RT_CLOSE_SQUARE
, /* ']' */
137 RT_OPEN_SQUARE
, /* '[' */
141 RT_GREATER
, /* '>' */
143 RT_ELLIPSIS
, /* '...' */
147 RT_COLON_SCOPE
, /* ':' or '::' */
148 RT_CLOSE_PAREN
, /* ')' */
149 RT_COMMA_CLOSE_PAREN
, /* ',' or ')' */
150 RT_PRAGMA_EOL
, /* end of line */
151 RT_NAME
, /* identifier */
153 /* The type is CPP_KEYWORD */
155 RT_DELETE
, /* delete */
156 RT_RETURN
, /* return */
157 RT_WHILE
, /* while */
158 RT_EXTERN
, /* extern */
159 RT_STATIC_ASSERT
, /* static_assert */
160 RT_DECLTYPE
, /* decltype */
161 RT_OPERATOR
, /* operator */
162 RT_CLASS
, /* class */
163 RT_TEMPLATE
, /* template */
164 RT_NAMESPACE
, /* namespace */
165 RT_USING
, /* using */
168 RT_CATCH
, /* catch */
169 RT_THROW
, /* throw */
170 RT_LABEL
, /* __label__ */
171 RT_AT_TRY
, /* @try */
172 RT_AT_SYNCHRONIZED
, /* @synchronized */
173 RT_AT_THROW
, /* @throw */
175 RT_SELECT
, /* selection-statement */
176 RT_ITERATION
, /* iteration-statement */
177 RT_JUMP
, /* jump-statement */
178 RT_CLASS_KEY
, /* class-key */
179 RT_CLASS_TYPENAME_TEMPLATE
, /* class, typename, or template */
180 RT_TRANSACTION_ATOMIC
, /* __transaction_atomic */
181 RT_TRANSACTION_RELAXED
, /* __transaction_relaxed */
182 RT_TRANSACTION_CANCEL
/* __transaction_cancel */
185 /* RAII wrapper for parser->in_type_id_in_expr_p, setting it on creation and
186 reverting it on destruction. */
188 class type_id_in_expr_sentinel
193 type_id_in_expr_sentinel (cp_parser
*parser
, bool set
= true)
195 saved (parser
->in_type_id_in_expr_p
)
196 { parser
->in_type_id_in_expr_p
= set
; }
197 ~type_id_in_expr_sentinel ()
198 { parser
->in_type_id_in_expr_p
= saved
; }
203 static cp_lexer
*cp_lexer_new_main
205 static cp_lexer
*cp_lexer_new_from_tokens
206 (cp_token_cache
*tokens
);
207 static void cp_lexer_destroy
209 static int cp_lexer_saving_tokens
211 static cp_token
*cp_lexer_token_at
212 (cp_lexer
*, cp_token_position
);
213 static void cp_lexer_get_preprocessor_token
214 (cp_lexer
*, cp_token
*);
215 static inline cp_token
*cp_lexer_peek_token
217 static cp_token
*cp_lexer_peek_nth_token
218 (cp_lexer
*, size_t);
219 static inline bool cp_lexer_next_token_is
220 (cp_lexer
*, enum cpp_ttype
);
221 static bool cp_lexer_next_token_is_not
222 (cp_lexer
*, enum cpp_ttype
);
223 static bool cp_lexer_next_token_is_keyword
224 (cp_lexer
*, enum rid
);
225 static cp_token
*cp_lexer_consume_token
227 static void cp_lexer_purge_token
229 static void cp_lexer_purge_tokens_after
230 (cp_lexer
*, cp_token_position
);
231 static void cp_lexer_save_tokens
233 static void cp_lexer_commit_tokens
235 static void cp_lexer_rollback_tokens
237 static void cp_lexer_print_token
238 (FILE *, cp_token
*);
239 static inline bool cp_lexer_debugging_p
241 static void cp_lexer_start_debugging
242 (cp_lexer
*) ATTRIBUTE_UNUSED
;
243 static void cp_lexer_stop_debugging
244 (cp_lexer
*) ATTRIBUTE_UNUSED
;
246 static cp_token_cache
*cp_token_cache_new
247 (cp_token
*, cp_token
*);
249 static void cp_parser_initial_pragma
252 static void cp_parser_cilk_simd
253 (cp_parser
*, cp_token
*, bool *);
254 static tree cp_parser_cilk_for
255 (cp_parser
*, tree
, bool *);
256 static bool cp_parser_omp_declare_reduction_exprs
258 static tree cp_parser_cilk_simd_vectorlength
259 (cp_parser
*, tree
, bool);
260 static void cp_finalize_oacc_routine
261 (cp_parser
*, tree
, bool);
263 /* Manifest constants. */
264 #define CP_LEXER_BUFFER_SIZE ((256 * 1024) / sizeof (cp_token))
265 #define CP_SAVED_TOKEN_STACK 5
269 /* The stream to which debugging output should be written. */
270 static FILE *cp_lexer_debug_stream
;
272 /* Nonzero if we are parsing an unevaluated operand: an operand to
273 sizeof, typeof, or alignof. */
274 int cp_unevaluated_operand
;
276 /* Dump up to NUM tokens in BUFFER to FILE starting with token
277 START_TOKEN. If START_TOKEN is NULL, the dump starts with the
278 first token in BUFFER. If NUM is 0, dump all the tokens. If
279 CURR_TOKEN is set and it is one of the tokens in BUFFER, it will be
280 highlighted by surrounding it in [[ ]]. */
283 cp_lexer_dump_tokens (FILE *file
, vec
<cp_token
, va_gc
> *buffer
,
284 cp_token
*start_token
, unsigned num
,
285 cp_token
*curr_token
)
287 unsigned i
, nprinted
;
291 fprintf (file
, "%u tokens\n", vec_safe_length (buffer
));
297 num
= buffer
->length ();
299 if (start_token
== NULL
)
300 start_token
= buffer
->address ();
302 if (start_token
> buffer
->address ())
304 cp_lexer_print_token (file
, &(*buffer
)[0]);
305 fprintf (file
, " ... ");
310 for (i
= 0; buffer
->iterate (i
, &token
) && nprinted
< num
; i
++)
312 if (token
== start_token
)
319 if (token
== curr_token
)
320 fprintf (file
, "[[");
322 cp_lexer_print_token (file
, token
);
324 if (token
== curr_token
)
325 fprintf (file
, "]]");
331 case CPP_CLOSE_BRACE
:
341 if (i
== num
&& i
< buffer
->length ())
343 fprintf (file
, " ... ");
344 cp_lexer_print_token (file
, &buffer
->last ());
347 fprintf (file
, "\n");
351 /* Dump all tokens in BUFFER to stderr. */
354 cp_lexer_debug_tokens (vec
<cp_token
, va_gc
> *buffer
)
356 cp_lexer_dump_tokens (stderr
, buffer
, NULL
, 0, NULL
);
360 debug (vec
<cp_token
, va_gc
> &ref
)
362 cp_lexer_dump_tokens (stderr
, &ref
, NULL
, 0, NULL
);
366 debug (vec
<cp_token
, va_gc
> *ptr
)
371 fprintf (stderr
, "<nil>\n");
375 /* Dump the cp_parser tree field T to FILE if T is non-NULL. DESC is the
376 description for T. */
379 cp_debug_print_tree_if_set (FILE *file
, const char *desc
, tree t
)
383 fprintf (file
, "%s: ", desc
);
384 print_node_brief (file
, "", t
, 0);
389 /* Dump parser context C to FILE. */
392 cp_debug_print_context (FILE *file
, cp_parser_context
*c
)
394 const char *status_s
[] = { "OK", "ERROR", "COMMITTED" };
395 fprintf (file
, "{ status = %s, scope = ", status_s
[c
->status
]);
396 print_node_brief (file
, "", c
->object_type
, 0);
397 fprintf (file
, "}\n");
401 /* Print the stack of parsing contexts to FILE starting with FIRST. */
404 cp_debug_print_context_stack (FILE *file
, cp_parser_context
*first
)
407 cp_parser_context
*c
;
409 fprintf (file
, "Parsing context stack:\n");
410 for (i
= 0, c
= first
; c
; c
= c
->next
, i
++)
412 fprintf (file
, "\t#%u: ", i
);
413 cp_debug_print_context (file
, c
);
418 /* Print the value of FLAG to FILE. DESC is a string describing the flag. */
421 cp_debug_print_flag (FILE *file
, const char *desc
, bool flag
)
424 fprintf (file
, "%s: true\n", desc
);
428 /* Print an unparsed function entry UF to FILE. */
431 cp_debug_print_unparsed_function (FILE *file
, cp_unparsed_functions_entry
*uf
)
434 cp_default_arg_entry
*default_arg_fn
;
437 fprintf (file
, "\tFunctions with default args:\n");
439 vec_safe_iterate (uf
->funs_with_default_args
, i
, &default_arg_fn
);
442 fprintf (file
, "\t\tClass type: ");
443 print_node_brief (file
, "", default_arg_fn
->class_type
, 0);
444 fprintf (file
, "\t\tDeclaration: ");
445 print_node_brief (file
, "", default_arg_fn
->decl
, 0);
446 fprintf (file
, "\n");
449 fprintf (file
, "\n\tFunctions with definitions that require "
450 "post-processing\n\t\t");
451 for (i
= 0; vec_safe_iterate (uf
->funs_with_definitions
, i
, &fn
); i
++)
453 print_node_brief (file
, "", fn
, 0);
456 fprintf (file
, "\n");
458 fprintf (file
, "\n\tNon-static data members with initializers that require "
459 "post-processing\n\t\t");
460 for (i
= 0; vec_safe_iterate (uf
->nsdmis
, i
, &fn
); i
++)
462 print_node_brief (file
, "", fn
, 0);
465 fprintf (file
, "\n");
469 /* Print the stack of unparsed member functions S to FILE. */
472 cp_debug_print_unparsed_queues (FILE *file
,
473 vec
<cp_unparsed_functions_entry
, va_gc
> *s
)
476 cp_unparsed_functions_entry
*uf
;
478 fprintf (file
, "Unparsed functions\n");
479 for (i
= 0; vec_safe_iterate (s
, i
, &uf
); i
++)
481 fprintf (file
, "#%u:\n", i
);
482 cp_debug_print_unparsed_function (file
, uf
);
487 /* Dump the tokens in a window of size WINDOW_SIZE around the next_token for
488 the given PARSER. If FILE is NULL, the output is printed on stderr. */
491 cp_debug_parser_tokens (FILE *file
, cp_parser
*parser
, int window_size
)
493 cp_token
*next_token
, *first_token
, *start_token
;
498 next_token
= parser
->lexer
->next_token
;
499 first_token
= parser
->lexer
->buffer
->address ();
500 start_token
= (next_token
> first_token
+ window_size
/ 2)
501 ? next_token
- window_size
/ 2
503 cp_lexer_dump_tokens (file
, parser
->lexer
->buffer
, start_token
, window_size
,
508 /* Dump debugging information for the given PARSER. If FILE is NULL,
509 the output is printed on stderr. */
512 cp_debug_parser (FILE *file
, cp_parser
*parser
)
514 const size_t window_size
= 20;
516 expanded_location eloc
;
521 fprintf (file
, "Parser state\n\n");
522 fprintf (file
, "Number of tokens: %u\n",
523 vec_safe_length (parser
->lexer
->buffer
));
524 cp_debug_print_tree_if_set (file
, "Lookup scope", parser
->scope
);
525 cp_debug_print_tree_if_set (file
, "Object scope",
526 parser
->object_scope
);
527 cp_debug_print_tree_if_set (file
, "Qualifying scope",
528 parser
->qualifying_scope
);
529 cp_debug_print_context_stack (file
, parser
->context
);
530 cp_debug_print_flag (file
, "Allow GNU extensions",
531 parser
->allow_gnu_extensions_p
);
532 cp_debug_print_flag (file
, "'>' token is greater-than",
533 parser
->greater_than_is_operator_p
);
534 cp_debug_print_flag (file
, "Default args allowed in current "
535 "parameter list", parser
->default_arg_ok_p
);
536 cp_debug_print_flag (file
, "Parsing integral constant-expression",
537 parser
->integral_constant_expression_p
);
538 cp_debug_print_flag (file
, "Allow non-constant expression in current "
539 "constant-expression",
540 parser
->allow_non_integral_constant_expression_p
);
541 cp_debug_print_flag (file
, "Seen non-constant expression",
542 parser
->non_integral_constant_expression_p
);
543 cp_debug_print_flag (file
, "Local names and 'this' forbidden in "
545 parser
->local_variables_forbidden_p
);
546 cp_debug_print_flag (file
, "In unbraced linkage specification",
547 parser
->in_unbraced_linkage_specification_p
);
548 cp_debug_print_flag (file
, "Parsing a declarator",
549 parser
->in_declarator_p
);
550 cp_debug_print_flag (file
, "In template argument list",
551 parser
->in_template_argument_list_p
);
552 cp_debug_print_flag (file
, "Parsing an iteration statement",
553 parser
->in_statement
& IN_ITERATION_STMT
);
554 cp_debug_print_flag (file
, "Parsing a switch statement",
555 parser
->in_statement
& IN_SWITCH_STMT
);
556 cp_debug_print_flag (file
, "Parsing a structured OpenMP block",
557 parser
->in_statement
& IN_OMP_BLOCK
);
558 cp_debug_print_flag (file
, "Parsing a Cilk Plus for loop",
559 parser
->in_statement
& IN_CILK_SIMD_FOR
);
560 cp_debug_print_flag (file
, "Parsing a an OpenMP loop",
561 parser
->in_statement
& IN_OMP_FOR
);
562 cp_debug_print_flag (file
, "Parsing an if statement",
563 parser
->in_statement
& IN_IF_STMT
);
564 cp_debug_print_flag (file
, "Parsing a type-id in an expression "
565 "context", parser
->in_type_id_in_expr_p
);
566 cp_debug_print_flag (file
, "Declarations are implicitly extern \"C\"",
567 parser
->implicit_extern_c
);
568 cp_debug_print_flag (file
, "String expressions should be translated "
569 "to execution character set",
570 parser
->translate_strings_p
);
571 cp_debug_print_flag (file
, "Parsing function body outside of a "
572 "local class", parser
->in_function_body
);
573 cp_debug_print_flag (file
, "Auto correct a colon to a scope operator",
574 parser
->colon_corrects_to_scope_p
);
575 cp_debug_print_flag (file
, "Colon doesn't start a class definition",
576 parser
->colon_doesnt_start_class_def_p
);
577 if (parser
->type_definition_forbidden_message
)
578 fprintf (file
, "Error message for forbidden type definitions: %s\n",
579 parser
->type_definition_forbidden_message
);
580 cp_debug_print_unparsed_queues (file
, parser
->unparsed_queues
);
581 fprintf (file
, "Number of class definitions in progress: %u\n",
582 parser
->num_classes_being_defined
);
583 fprintf (file
, "Number of template parameter lists for the current "
584 "declaration: %u\n", parser
->num_template_parameter_lists
);
585 cp_debug_parser_tokens (file
, parser
, window_size
);
586 token
= parser
->lexer
->next_token
;
587 fprintf (file
, "Next token to parse:\n");
588 fprintf (file
, "\tToken: ");
589 cp_lexer_print_token (file
, token
);
590 eloc
= expand_location (token
->location
);
591 fprintf (file
, "\n\tFile: %s\n", eloc
.file
);
592 fprintf (file
, "\tLine: %d\n", eloc
.line
);
593 fprintf (file
, "\tColumn: %d\n", eloc
.column
);
597 debug (cp_parser
&ref
)
599 cp_debug_parser (stderr
, &ref
);
603 debug (cp_parser
*ptr
)
608 fprintf (stderr
, "<nil>\n");
611 /* Allocate memory for a new lexer object and return it. */
614 cp_lexer_alloc (void)
618 c_common_no_more_pch ();
620 /* Allocate the memory. */
621 lexer
= ggc_cleared_alloc
<cp_lexer
> ();
623 /* Initially we are not debugging. */
624 lexer
->debugging_p
= false;
626 lexer
->saved_tokens
.create (CP_SAVED_TOKEN_STACK
);
628 /* Create the buffer. */
629 vec_alloc (lexer
->buffer
, CP_LEXER_BUFFER_SIZE
);
635 /* Create a new main C++ lexer, the lexer that gets tokens from the
639 cp_lexer_new_main (void)
644 /* It's possible that parsing the first pragma will load a PCH file,
645 which is a GC collection point. So we have to do that before
646 allocating any memory. */
647 cp_parser_initial_pragma (&token
);
649 lexer
= cp_lexer_alloc ();
651 /* Put the first token in the buffer. */
652 lexer
->buffer
->quick_push (token
);
654 /* Get the remaining tokens from the preprocessor. */
655 while (token
.type
!= CPP_EOF
)
657 cp_lexer_get_preprocessor_token (lexer
, &token
);
658 vec_safe_push (lexer
->buffer
, token
);
661 lexer
->last_token
= lexer
->buffer
->address ()
662 + lexer
->buffer
->length ()
664 lexer
->next_token
= lexer
->buffer
->length ()
665 ? lexer
->buffer
->address ()
668 /* Subsequent preprocessor diagnostics should use compiler
669 diagnostic functions to get the compiler source location. */
672 gcc_assert (!lexer
->next_token
->purged_p
);
676 /* Create a new lexer whose token stream is primed with the tokens in
677 CACHE. When these tokens are exhausted, no new tokens will be read. */
680 cp_lexer_new_from_tokens (cp_token_cache
*cache
)
682 cp_token
*first
= cache
->first
;
683 cp_token
*last
= cache
->last
;
684 cp_lexer
*lexer
= ggc_cleared_alloc
<cp_lexer
> ();
686 /* We do not own the buffer. */
687 lexer
->buffer
= NULL
;
688 lexer
->next_token
= first
== last
? &eof_token
: first
;
689 lexer
->last_token
= last
;
691 lexer
->saved_tokens
.create (CP_SAVED_TOKEN_STACK
);
693 /* Initially we are not debugging. */
694 lexer
->debugging_p
= false;
696 gcc_assert (!lexer
->next_token
->purged_p
);
700 /* Frees all resources associated with LEXER. */
703 cp_lexer_destroy (cp_lexer
*lexer
)
705 vec_free (lexer
->buffer
);
706 lexer
->saved_tokens
.release ();
710 /* This needs to be set to TRUE before the lexer-debugging infrastructure can
711 be used. The point of this flag is to help the compiler to fold away calls
712 to cp_lexer_debugging_p within this source file at compile time, when the
713 lexer is not being debugged. */
715 #define LEXER_DEBUGGING_ENABLED_P false
717 /* Returns nonzero if debugging information should be output. */
720 cp_lexer_debugging_p (cp_lexer
*lexer
)
722 if (!LEXER_DEBUGGING_ENABLED_P
)
725 return lexer
->debugging_p
;
729 static inline cp_token_position
730 cp_lexer_token_position (cp_lexer
*lexer
, bool previous_p
)
732 gcc_assert (!previous_p
|| lexer
->next_token
!= &eof_token
);
734 return lexer
->next_token
- previous_p
;
737 static inline cp_token
*
738 cp_lexer_token_at (cp_lexer
* /*lexer*/, cp_token_position pos
)
744 cp_lexer_set_token_position (cp_lexer
*lexer
, cp_token_position pos
)
746 lexer
->next_token
= cp_lexer_token_at (lexer
, pos
);
749 static inline cp_token_position
750 cp_lexer_previous_token_position (cp_lexer
*lexer
)
752 if (lexer
->next_token
== &eof_token
)
753 return lexer
->last_token
- 1;
755 return cp_lexer_token_position (lexer
, true);
758 static inline cp_token
*
759 cp_lexer_previous_token (cp_lexer
*lexer
)
761 cp_token_position tp
= cp_lexer_previous_token_position (lexer
);
763 /* Skip past purged tokens. */
766 gcc_assert (tp
!= vec_safe_address (lexer
->buffer
));
770 return cp_lexer_token_at (lexer
, tp
);
773 /* nonzero if we are presently saving tokens. */
776 cp_lexer_saving_tokens (const cp_lexer
* lexer
)
778 return lexer
->saved_tokens
.length () != 0;
781 /* Store the next token from the preprocessor in *TOKEN. Return true
782 if we reach EOF. If LEXER is NULL, assume we are handling an
783 initial #pragma pch_preprocess, and thus want the lexer to return
784 processed strings. */
787 cp_lexer_get_preprocessor_token (cp_lexer
*lexer
, cp_token
*token
)
789 static int is_extern_c
= 0;
791 /* Get a new token from the preprocessor. */
793 = c_lex_with_flags (&token
->u
.value
, &token
->location
, &token
->flags
,
794 lexer
== NULL
? 0 : C_LEX_STRING_NO_JOIN
);
795 token
->keyword
= RID_MAX
;
796 token
->purged_p
= false;
797 token
->error_reported
= false;
799 /* On some systems, some header files are surrounded by an
800 implicit extern "C" block. Set a flag in the token if it
801 comes from such a header. */
802 is_extern_c
+= pending_lang_change
;
803 pending_lang_change
= 0;
804 token
->implicit_extern_c
= is_extern_c
> 0;
806 /* Check to see if this token is a keyword. */
807 if (token
->type
== CPP_NAME
)
809 if (IDENTIFIER_KEYWORD_P (token
->u
.value
))
811 /* Mark this token as a keyword. */
812 token
->type
= CPP_KEYWORD
;
813 /* Record which keyword. */
814 token
->keyword
= C_RID_CODE (token
->u
.value
);
818 if (warn_cxx11_compat
819 && C_RID_CODE (token
->u
.value
) >= RID_FIRST_CXX11
820 && C_RID_CODE (token
->u
.value
) <= RID_LAST_CXX11
)
822 /* Warn about the C++0x keyword (but still treat it as
824 warning (OPT_Wc__11_compat
,
825 "identifier %qE is a keyword in C++11",
828 /* Clear out the C_RID_CODE so we don't warn about this
829 particular identifier-turned-keyword again. */
830 C_SET_RID_CODE (token
->u
.value
, RID_MAX
);
833 token
->keyword
= RID_MAX
;
836 else if (token
->type
== CPP_AT_NAME
)
838 /* This only happens in Objective-C++; it must be a keyword. */
839 token
->type
= CPP_KEYWORD
;
840 switch (C_RID_CODE (token
->u
.value
))
842 /* Replace 'class' with '@class', 'private' with '@private',
843 etc. This prevents confusion with the C++ keyword
844 'class', and makes the tokens consistent with other
845 Objective-C 'AT' keywords. For example '@class' is
846 reported as RID_AT_CLASS which is consistent with
847 '@synchronized', which is reported as
850 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
851 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
852 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
853 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
854 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
855 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
856 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
857 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
858 default: token
->keyword
= C_RID_CODE (token
->u
.value
);
863 /* Update the globals input_location and the input file stack from TOKEN. */
865 cp_lexer_set_source_position_from_token (cp_token
*token
)
867 if (token
->type
!= CPP_EOF
)
869 input_location
= token
->location
;
873 /* Update the globals input_location and the input file stack from LEXER. */
875 cp_lexer_set_source_position (cp_lexer
*lexer
)
877 cp_token
*token
= cp_lexer_peek_token (lexer
);
878 cp_lexer_set_source_position_from_token (token
);
881 /* Return a pointer to the next token in the token stream, but do not
884 static inline cp_token
*
885 cp_lexer_peek_token (cp_lexer
*lexer
)
887 if (cp_lexer_debugging_p (lexer
))
889 fputs ("cp_lexer: peeking at token: ", cp_lexer_debug_stream
);
890 cp_lexer_print_token (cp_lexer_debug_stream
, lexer
->next_token
);
891 putc ('\n', cp_lexer_debug_stream
);
893 return lexer
->next_token
;
896 /* Return true if the next token has the indicated TYPE. */
899 cp_lexer_next_token_is (cp_lexer
* lexer
, enum cpp_ttype type
)
901 return cp_lexer_peek_token (lexer
)->type
== type
;
904 /* Return true if the next token does not have the indicated TYPE. */
907 cp_lexer_next_token_is_not (cp_lexer
* lexer
, enum cpp_ttype type
)
909 return !cp_lexer_next_token_is (lexer
, type
);
912 /* Return true if the next token is the indicated KEYWORD. */
915 cp_lexer_next_token_is_keyword (cp_lexer
* lexer
, enum rid keyword
)
917 return cp_lexer_peek_token (lexer
)->keyword
== keyword
;
921 cp_lexer_nth_token_is (cp_lexer
* lexer
, size_t n
, enum cpp_ttype type
)
923 return cp_lexer_peek_nth_token (lexer
, n
)->type
== type
;
927 cp_lexer_nth_token_is_keyword (cp_lexer
* lexer
, size_t n
, enum rid keyword
)
929 return cp_lexer_peek_nth_token (lexer
, n
)->keyword
== keyword
;
932 /* Return true if the next token is not the indicated KEYWORD. */
935 cp_lexer_next_token_is_not_keyword (cp_lexer
* lexer
, enum rid keyword
)
937 return cp_lexer_peek_token (lexer
)->keyword
!= keyword
;
940 /* Return true if KEYWORD can start a decl-specifier. */
943 cp_keyword_starts_decl_specifier_p (enum rid keyword
)
947 /* auto specifier: storage-class-specifier in C++,
948 simple-type-specifier in C++0x. */
950 /* Storage classes. */
956 /* Elaborated type specifiers. */
962 /* Simple type specifiers. */
976 /* GNU extensions. */
979 /* C++0x extensions. */
981 case RID_UNDERLYING_TYPE
:
986 if (keyword
>= RID_FIRST_INT_N
987 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
988 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
994 /* Return true if the next token is a keyword for a decl-specifier. */
997 cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer
*lexer
)
1001 token
= cp_lexer_peek_token (lexer
);
1002 return cp_keyword_starts_decl_specifier_p (token
->keyword
);
1005 /* Returns TRUE iff the token T begins a decltype type. */
1008 token_is_decltype (cp_token
*t
)
1010 return (t
->keyword
== RID_DECLTYPE
1011 || t
->type
== CPP_DECLTYPE
);
1014 /* Returns TRUE iff the next token begins a decltype type. */
1017 cp_lexer_next_token_is_decltype (cp_lexer
*lexer
)
1019 cp_token
*t
= cp_lexer_peek_token (lexer
);
1020 return token_is_decltype (t
);
1023 /* Called when processing a token with tree_check_value; perform or defer the
1024 associated checks and return the value. */
1027 saved_checks_value (struct tree_check
*check_value
)
1029 /* Perform any access checks that were deferred. */
1030 vec
<deferred_access_check
, va_gc
> *checks
;
1031 deferred_access_check
*chk
;
1032 checks
= check_value
->checks
;
1036 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
1037 perform_or_defer_access_check (chk
->binfo
,
1039 chk
->diag_decl
, tf_warning_or_error
);
1041 /* Return the stored value. */
1042 return check_value
->value
;
1045 /* Return a pointer to the Nth token in the token stream. If N is 1,
1046 then this is precisely equivalent to cp_lexer_peek_token (except
1047 that it is not inline). One would like to disallow that case, but
1048 there is one case (cp_parser_nth_token_starts_template_id) where
1049 the caller passes a variable for N and it might be 1. */
1052 cp_lexer_peek_nth_token (cp_lexer
* lexer
, size_t n
)
1056 /* N is 1-based, not zero-based. */
1059 if (cp_lexer_debugging_p (lexer
))
1060 fprintf (cp_lexer_debug_stream
,
1061 "cp_lexer: peeking ahead %ld at token: ", (long)n
);
1064 token
= lexer
->next_token
;
1065 gcc_assert (!n
|| token
!= &eof_token
);
1069 if (token
== lexer
->last_token
)
1075 if (!token
->purged_p
)
1079 if (cp_lexer_debugging_p (lexer
))
1081 cp_lexer_print_token (cp_lexer_debug_stream
, token
);
1082 putc ('\n', cp_lexer_debug_stream
);
1088 /* Return the next token, and advance the lexer's next_token pointer
1089 to point to the next non-purged token. */
1092 cp_lexer_consume_token (cp_lexer
* lexer
)
1094 cp_token
*token
= lexer
->next_token
;
1096 gcc_assert (token
!= &eof_token
);
1097 gcc_assert (!lexer
->in_pragma
|| token
->type
!= CPP_PRAGMA_EOL
);
1101 lexer
->next_token
++;
1102 if (lexer
->next_token
== lexer
->last_token
)
1104 lexer
->next_token
= &eof_token
;
1109 while (lexer
->next_token
->purged_p
);
1111 cp_lexer_set_source_position_from_token (token
);
1113 /* Provide debugging output. */
1114 if (cp_lexer_debugging_p (lexer
))
1116 fputs ("cp_lexer: consuming token: ", cp_lexer_debug_stream
);
1117 cp_lexer_print_token (cp_lexer_debug_stream
, token
);
1118 putc ('\n', cp_lexer_debug_stream
);
1124 /* Permanently remove the next token from the token stream, and
1125 advance the next_token pointer to refer to the next non-purged
1129 cp_lexer_purge_token (cp_lexer
*lexer
)
1131 cp_token
*tok
= lexer
->next_token
;
1133 gcc_assert (tok
!= &eof_token
);
1134 tok
->purged_p
= true;
1135 tok
->location
= UNKNOWN_LOCATION
;
1136 tok
->u
.value
= NULL_TREE
;
1137 tok
->keyword
= RID_MAX
;
1142 if (tok
== lexer
->last_token
)
1148 while (tok
->purged_p
);
1149 lexer
->next_token
= tok
;
1152 /* Permanently remove all tokens after TOK, up to, but not
1153 including, the token that will be returned next by
1154 cp_lexer_peek_token. */
1157 cp_lexer_purge_tokens_after (cp_lexer
*lexer
, cp_token
*tok
)
1159 cp_token
*peek
= lexer
->next_token
;
1161 if (peek
== &eof_token
)
1162 peek
= lexer
->last_token
;
1164 gcc_assert (tok
< peek
);
1166 for ( tok
+= 1; tok
!= peek
; tok
+= 1)
1168 tok
->purged_p
= true;
1169 tok
->location
= UNKNOWN_LOCATION
;
1170 tok
->u
.value
= NULL_TREE
;
1171 tok
->keyword
= RID_MAX
;
1175 /* Begin saving tokens. All tokens consumed after this point will be
1179 cp_lexer_save_tokens (cp_lexer
* lexer
)
1181 /* Provide debugging output. */
1182 if (cp_lexer_debugging_p (lexer
))
1183 fprintf (cp_lexer_debug_stream
, "cp_lexer: saving tokens\n");
1185 lexer
->saved_tokens
.safe_push (lexer
->next_token
);
1188 /* Commit to the portion of the token stream most recently saved. */
1191 cp_lexer_commit_tokens (cp_lexer
* lexer
)
1193 /* Provide debugging output. */
1194 if (cp_lexer_debugging_p (lexer
))
1195 fprintf (cp_lexer_debug_stream
, "cp_lexer: committing tokens\n");
1197 lexer
->saved_tokens
.pop ();
1200 /* Return all tokens saved since the last call to cp_lexer_save_tokens
1201 to the token stream. Stop saving tokens. */
1204 cp_lexer_rollback_tokens (cp_lexer
* lexer
)
1206 /* Provide debugging output. */
1207 if (cp_lexer_debugging_p (lexer
))
1208 fprintf (cp_lexer_debug_stream
, "cp_lexer: restoring tokens\n");
1210 lexer
->next_token
= lexer
->saved_tokens
.pop ();
1213 /* RAII wrapper around the above functions, with sanity checking. Creating
1214 a variable saves tokens, which are committed when the variable is
1215 destroyed unless they are explicitly rolled back by calling the rollback
1218 struct saved_token_sentinel
1223 saved_token_sentinel(cp_lexer
*lexer
): lexer(lexer
), commit(true)
1225 len
= lexer
->saved_tokens
.length ();
1226 cp_lexer_save_tokens (lexer
);
1230 cp_lexer_rollback_tokens (lexer
);
1233 ~saved_token_sentinel()
1236 cp_lexer_commit_tokens (lexer
);
1237 gcc_assert (lexer
->saved_tokens
.length () == len
);
1241 /* Print a representation of the TOKEN on the STREAM. */
1244 cp_lexer_print_token (FILE * stream
, cp_token
*token
)
1246 /* We don't use cpp_type2name here because the parser defines
1247 a few tokens of its own. */
1248 static const char *const token_names
[] = {
1249 /* cpplib-defined token types */
1250 #define OP(e, s) #e,
1251 #define TK(e, s) #e,
1255 /* C++ parser token types - see "Manifest constants", above. */
1258 "NESTED_NAME_SPECIFIER",
1261 /* For some tokens, print the associated data. */
1262 switch (token
->type
)
1265 /* Some keywords have a value that is not an IDENTIFIER_NODE.
1266 For example, `struct' is mapped to an INTEGER_CST. */
1267 if (!identifier_p (token
->u
.value
))
1271 fputs (IDENTIFIER_POINTER (token
->u
.value
), stream
);
1278 case CPP_UTF8STRING
:
1279 fprintf (stream
, " \"%s\"", TREE_STRING_POINTER (token
->u
.value
));
1283 print_generic_expr (stream
, token
->u
.value
);
1287 /* If we have a name for the token, print it out. Otherwise, we
1288 simply give the numeric code. */
1289 if (token
->type
< ARRAY_SIZE(token_names
))
1290 fputs (token_names
[token
->type
], stream
);
1292 fprintf (stream
, "[%d]", token
->type
);
1298 debug (cp_token
&ref
)
1300 cp_lexer_print_token (stderr
, &ref
);
1301 fprintf (stderr
, "\n");
1305 debug (cp_token
*ptr
)
1310 fprintf (stderr
, "<nil>\n");
1314 /* Start emitting debugging information. */
1317 cp_lexer_start_debugging (cp_lexer
* lexer
)
1319 if (!LEXER_DEBUGGING_ENABLED_P
)
1320 fatal_error (input_location
,
1321 "LEXER_DEBUGGING_ENABLED_P is not set to true");
1323 lexer
->debugging_p
= true;
1324 cp_lexer_debug_stream
= stderr
;
1327 /* Stop emitting debugging information. */
1330 cp_lexer_stop_debugging (cp_lexer
* lexer
)
1332 if (!LEXER_DEBUGGING_ENABLED_P
)
1333 fatal_error (input_location
,
1334 "LEXER_DEBUGGING_ENABLED_P is not set to true");
1336 lexer
->debugging_p
= false;
1337 cp_lexer_debug_stream
= NULL
;
1340 /* Create a new cp_token_cache, representing a range of tokens. */
1342 static cp_token_cache
*
1343 cp_token_cache_new (cp_token
*first
, cp_token
*last
)
1345 cp_token_cache
*cache
= ggc_alloc
<cp_token_cache
> ();
1346 cache
->first
= first
;
1351 /* Diagnose if #pragma omp declare simd isn't followed immediately
1352 by function declaration or definition. */
1355 cp_ensure_no_omp_declare_simd (cp_parser
*parser
)
1357 if (parser
->omp_declare_simd
&& !parser
->omp_declare_simd
->error_seen
)
1359 error ("%<#pragma omp declare simd%> not immediately followed by "
1360 "function declaration or definition");
1361 parser
->omp_declare_simd
= NULL
;
1365 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
1366 and put that into "omp declare simd" attribute. */
1369 cp_finalize_omp_declare_simd (cp_parser
*parser
, tree fndecl
)
1371 if (__builtin_expect (parser
->omp_declare_simd
!= NULL
, 0))
1373 if (fndecl
== error_mark_node
)
1375 parser
->omp_declare_simd
= NULL
;
1378 if (TREE_CODE (fndecl
) != FUNCTION_DECL
)
1380 cp_ensure_no_omp_declare_simd (parser
);
1386 /* Diagnose if #pragma acc routine isn't followed immediately by function
1387 declaration or definition. */
1390 cp_ensure_no_oacc_routine (cp_parser
*parser
)
1392 if (parser
->oacc_routine
&& !parser
->oacc_routine
->error_seen
)
1394 error_at (parser
->oacc_routine
->loc
,
1395 "%<#pragma acc routine%> not immediately followed by "
1396 "function declaration or definition");
1397 parser
->oacc_routine
= NULL
;
1401 /* Decl-specifiers. */
1403 /* Set *DECL_SPECS to represent an empty decl-specifier-seq. */
1406 clear_decl_specs (cp_decl_specifier_seq
*decl_specs
)
1408 memset (decl_specs
, 0, sizeof (cp_decl_specifier_seq
));
1413 /* Nothing other than the parser should be creating declarators;
1414 declarators are a semi-syntactic representation of C++ entities.
1415 Other parts of the front end that need to create entities (like
1416 VAR_DECLs or FUNCTION_DECLs) should do that directly. */
1418 static cp_declarator
*make_call_declarator
1419 (cp_declarator
*, tree
, cp_cv_quals
, cp_virt_specifiers
, cp_ref_qualifier
, tree
, tree
, tree
, tree
);
1420 static cp_declarator
*make_array_declarator
1421 (cp_declarator
*, tree
);
1422 static cp_declarator
*make_pointer_declarator
1423 (cp_cv_quals
, cp_declarator
*, tree
);
1424 static cp_declarator
*make_reference_declarator
1425 (cp_cv_quals
, cp_declarator
*, bool, tree
);
1426 static cp_declarator
*make_ptrmem_declarator
1427 (cp_cv_quals
, tree
, cp_declarator
*, tree
);
1429 /* An erroneous declarator. */
1430 static cp_declarator
*cp_error_declarator
;
1432 /* The obstack on which declarators and related data structures are
1434 static struct obstack declarator_obstack
;
1436 /* Alloc BYTES from the declarator memory pool. */
1438 static inline void *
1439 alloc_declarator (size_t bytes
)
1441 return obstack_alloc (&declarator_obstack
, bytes
);
1444 /* Allocate a declarator of the indicated KIND. Clear fields that are
1445 common to all declarators. */
1447 static cp_declarator
*
1448 make_declarator (cp_declarator_kind kind
)
1450 cp_declarator
*declarator
;
1452 declarator
= (cp_declarator
*) alloc_declarator (sizeof (cp_declarator
));
1453 declarator
->kind
= kind
;
1454 declarator
->attributes
= NULL_TREE
;
1455 declarator
->std_attributes
= NULL_TREE
;
1456 declarator
->declarator
= NULL
;
1457 declarator
->parameter_pack_p
= false;
1458 declarator
->id_loc
= UNKNOWN_LOCATION
;
1463 /* Make a declarator for a generalized identifier. If
1464 QUALIFYING_SCOPE is non-NULL, the identifier is
1465 QUALIFYING_SCOPE::UNQUALIFIED_NAME; otherwise, it is just
1466 UNQUALIFIED_NAME. SFK indicates the kind of special function this
1469 static cp_declarator
*
1470 make_id_declarator (tree qualifying_scope
, tree unqualified_name
,
1471 special_function_kind sfk
)
1473 cp_declarator
*declarator
;
1475 /* It is valid to write:
1477 class C { void f(); };
1481 The standard is not clear about whether `typedef const C D' is
1482 legal; as of 2002-09-15 the committee is considering that
1483 question. EDG 3.0 allows that syntax. Therefore, we do as
1485 if (qualifying_scope
&& TYPE_P (qualifying_scope
))
1486 qualifying_scope
= TYPE_MAIN_VARIANT (qualifying_scope
);
1488 gcc_assert (identifier_p (unqualified_name
)
1489 || TREE_CODE (unqualified_name
) == BIT_NOT_EXPR
1490 || TREE_CODE (unqualified_name
) == TEMPLATE_ID_EXPR
);
1492 declarator
= make_declarator (cdk_id
);
1493 declarator
->u
.id
.qualifying_scope
= qualifying_scope
;
1494 declarator
->u
.id
.unqualified_name
= unqualified_name
;
1495 declarator
->u
.id
.sfk
= sfk
;
1500 /* Make a declarator for a pointer to TARGET. CV_QUALIFIERS is a list
1501 of modifiers such as const or volatile to apply to the pointer
1502 type, represented as identifiers. ATTRIBUTES represent the attributes that
1503 appertain to the pointer or reference. */
1506 make_pointer_declarator (cp_cv_quals cv_qualifiers
, cp_declarator
*target
,
1509 cp_declarator
*declarator
;
1511 declarator
= make_declarator (cdk_pointer
);
1512 declarator
->declarator
= target
;
1513 declarator
->u
.pointer
.qualifiers
= cv_qualifiers
;
1514 declarator
->u
.pointer
.class_type
= NULL_TREE
;
1517 declarator
->id_loc
= target
->id_loc
;
1518 declarator
->parameter_pack_p
= target
->parameter_pack_p
;
1519 target
->parameter_pack_p
= false;
1522 declarator
->parameter_pack_p
= false;
1524 declarator
->std_attributes
= attributes
;
1529 /* Like make_pointer_declarator -- but for references. ATTRIBUTES
1530 represent the attributes that appertain to the pointer or
1534 make_reference_declarator (cp_cv_quals cv_qualifiers
, cp_declarator
*target
,
1535 bool rvalue_ref
, tree attributes
)
1537 cp_declarator
*declarator
;
1539 declarator
= make_declarator (cdk_reference
);
1540 declarator
->declarator
= target
;
1541 declarator
->u
.reference
.qualifiers
= cv_qualifiers
;
1542 declarator
->u
.reference
.rvalue_ref
= rvalue_ref
;
1545 declarator
->id_loc
= target
->id_loc
;
1546 declarator
->parameter_pack_p
= target
->parameter_pack_p
;
1547 target
->parameter_pack_p
= false;
1550 declarator
->parameter_pack_p
= false;
1552 declarator
->std_attributes
= attributes
;
1557 /* Like make_pointer_declarator -- but for a pointer to a non-static
1558 member of CLASS_TYPE. ATTRIBUTES represent the attributes that
1559 appertain to the pointer or reference. */
1562 make_ptrmem_declarator (cp_cv_quals cv_qualifiers
, tree class_type
,
1563 cp_declarator
*pointee
,
1566 cp_declarator
*declarator
;
1568 declarator
= make_declarator (cdk_ptrmem
);
1569 declarator
->declarator
= pointee
;
1570 declarator
->u
.pointer
.qualifiers
= cv_qualifiers
;
1571 declarator
->u
.pointer
.class_type
= class_type
;
1575 declarator
->parameter_pack_p
= pointee
->parameter_pack_p
;
1576 pointee
->parameter_pack_p
= false;
1579 declarator
->parameter_pack_p
= false;
1581 declarator
->std_attributes
= attributes
;
1586 /* Make a declarator for the function given by TARGET, with the
1587 indicated PARMS. The CV_QUALIFIERS apply to the function, as in
1588 "const"-qualified member function. The EXCEPTION_SPECIFICATION
1589 indicates what exceptions can be thrown. */
1592 make_call_declarator (cp_declarator
*target
,
1594 cp_cv_quals cv_qualifiers
,
1595 cp_virt_specifiers virt_specifiers
,
1596 cp_ref_qualifier ref_qualifier
,
1598 tree exception_specification
,
1599 tree late_return_type
,
1600 tree requires_clause
)
1602 cp_declarator
*declarator
;
1604 declarator
= make_declarator (cdk_function
);
1605 declarator
->declarator
= target
;
1606 declarator
->u
.function
.parameters
= parms
;
1607 declarator
->u
.function
.qualifiers
= cv_qualifiers
;
1608 declarator
->u
.function
.virt_specifiers
= virt_specifiers
;
1609 declarator
->u
.function
.ref_qualifier
= ref_qualifier
;
1610 declarator
->u
.function
.tx_qualifier
= tx_qualifier
;
1611 declarator
->u
.function
.exception_specification
= exception_specification
;
1612 declarator
->u
.function
.late_return_type
= late_return_type
;
1613 declarator
->u
.function
.requires_clause
= requires_clause
;
1616 declarator
->id_loc
= target
->id_loc
;
1617 declarator
->parameter_pack_p
= target
->parameter_pack_p
;
1618 target
->parameter_pack_p
= false;
1621 declarator
->parameter_pack_p
= false;
1626 /* Make a declarator for an array of BOUNDS elements, each of which is
1627 defined by ELEMENT. */
1630 make_array_declarator (cp_declarator
*element
, tree bounds
)
1632 cp_declarator
*declarator
;
1634 declarator
= make_declarator (cdk_array
);
1635 declarator
->declarator
= element
;
1636 declarator
->u
.array
.bounds
= bounds
;
1639 declarator
->id_loc
= element
->id_loc
;
1640 declarator
->parameter_pack_p
= element
->parameter_pack_p
;
1641 element
->parameter_pack_p
= false;
1644 declarator
->parameter_pack_p
= false;
1649 /* Determine whether the declarator we've seen so far can be a
1650 parameter pack, when followed by an ellipsis. */
1652 declarator_can_be_parameter_pack (cp_declarator
*declarator
)
1654 if (declarator
&& declarator
->parameter_pack_p
)
1655 /* We already saw an ellipsis. */
1658 /* Search for a declarator name, or any other declarator that goes
1659 after the point where the ellipsis could appear in a parameter
1660 pack. If we find any of these, then this declarator can not be
1661 made into a parameter pack. */
1663 while (declarator
&& !found
)
1665 switch ((int)declarator
->kind
)
1677 declarator
= declarator
->declarator
;
1685 cp_parameter_declarator
*no_parameters
;
1687 /* Create a parameter declarator with the indicated DECL_SPECIFIERS,
1688 DECLARATOR and DEFAULT_ARGUMENT. */
1690 cp_parameter_declarator
*
1691 make_parameter_declarator (cp_decl_specifier_seq
*decl_specifiers
,
1692 cp_declarator
*declarator
,
1693 tree default_argument
,
1694 bool template_parameter_pack_p
= false)
1696 cp_parameter_declarator
*parameter
;
1698 parameter
= ((cp_parameter_declarator
*)
1699 alloc_declarator (sizeof (cp_parameter_declarator
)));
1700 parameter
->next
= NULL
;
1701 if (decl_specifiers
)
1702 parameter
->decl_specifiers
= *decl_specifiers
;
1704 clear_decl_specs (¶meter
->decl_specifiers
);
1705 parameter
->declarator
= declarator
;
1706 parameter
->default_argument
= default_argument
;
1707 parameter
->template_parameter_pack_p
= template_parameter_pack_p
;
1712 /* Returns true iff DECLARATOR is a declaration for a function. */
1715 function_declarator_p (const cp_declarator
*declarator
)
1719 if (declarator
->kind
== cdk_function
1720 && declarator
->declarator
->kind
== cdk_id
)
1722 if (declarator
->kind
== cdk_id
1723 || declarator
->kind
== cdk_decomp
1724 || declarator
->kind
== cdk_error
)
1726 declarator
= declarator
->declarator
;
1736 A cp_parser parses the token stream as specified by the C++
1737 grammar. Its job is purely parsing, not semantic analysis. For
1738 example, the parser breaks the token stream into declarators,
1739 expressions, statements, and other similar syntactic constructs.
1740 It does not check that the types of the expressions on either side
1741 of an assignment-statement are compatible, or that a function is
1742 not declared with a parameter of type `void'.
1744 The parser invokes routines elsewhere in the compiler to perform
1745 semantic analysis and to build up the abstract syntax tree for the
1748 The parser (and the template instantiation code, which is, in a
1749 way, a close relative of parsing) are the only parts of the
1750 compiler that should be calling push_scope and pop_scope, or
1751 related functions. The parser (and template instantiation code)
1752 keeps track of what scope is presently active; everything else
1753 should simply honor that. (The code that generates static
1754 initializers may also need to set the scope, in order to check
1755 access control correctly when emitting the initializers.)
1760 The parser is of the standard recursive-descent variety. Upcoming
1761 tokens in the token stream are examined in order to determine which
1762 production to use when parsing a non-terminal. Some C++ constructs
1763 require arbitrary look ahead to disambiguate. For example, it is
1764 impossible, in the general case, to tell whether a statement is an
1765 expression or declaration without scanning the entire statement.
1766 Therefore, the parser is capable of "parsing tentatively." When the
1767 parser is not sure what construct comes next, it enters this mode.
1768 Then, while we attempt to parse the construct, the parser queues up
1769 error messages, rather than issuing them immediately, and saves the
1770 tokens it consumes. If the construct is parsed successfully, the
1771 parser "commits", i.e., it issues any queued error messages and
1772 the tokens that were being preserved are permanently discarded.
1773 If, however, the construct is not parsed successfully, the parser
1774 rolls back its state completely so that it can resume parsing using
1775 a different alternative.
1780 The performance of the parser could probably be improved substantially.
1781 We could often eliminate the need to parse tentatively by looking ahead
1782 a little bit. In some places, this approach might not entirely eliminate
1783 the need to parse tentatively, but it might still speed up the average
1786 /* Flags that are passed to some parsing functions. These values can
1787 be bitwise-ored together. */
1792 CP_PARSER_FLAGS_NONE
= 0x0,
1793 /* The construct is optional. If it is not present, then no error
1794 should be issued. */
1795 CP_PARSER_FLAGS_OPTIONAL
= 0x1,
1796 /* When parsing a type-specifier, treat user-defined type-names
1797 as non-type identifiers. */
1798 CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES
= 0x2,
1799 /* When parsing a type-specifier, do not try to parse a class-specifier
1800 or enum-specifier. */
1801 CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
= 0x4,
1802 /* When parsing a decl-specifier-seq, only allow type-specifier or
1804 CP_PARSER_FLAGS_ONLY_TYPE_OR_CONSTEXPR
= 0x8,
1805 /* When parsing a decl-specifier-seq, only allow mutable or constexpr. */
1806 CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR
= 0x10
1809 /* This type is used for parameters and variables which hold
1810 combinations of the above flags. */
1811 typedef int cp_parser_flags
;
1813 /* The different kinds of declarators we want to parse. */
1815 enum cp_parser_declarator_kind
1817 /* We want an abstract declarator. */
1818 CP_PARSER_DECLARATOR_ABSTRACT
,
1819 /* We want a named declarator. */
1820 CP_PARSER_DECLARATOR_NAMED
,
1821 /* We don't mind, but the name must be an unqualified-id. */
1822 CP_PARSER_DECLARATOR_EITHER
1825 /* The precedence values used to parse binary expressions. The minimum value
1826 of PREC must be 1, because zero is reserved to quickly discriminate
1827 binary operators from other tokens. */
1832 PREC_LOGICAL_OR_EXPRESSION
,
1833 PREC_LOGICAL_AND_EXPRESSION
,
1834 PREC_INCLUSIVE_OR_EXPRESSION
,
1835 PREC_EXCLUSIVE_OR_EXPRESSION
,
1836 PREC_AND_EXPRESSION
,
1837 PREC_EQUALITY_EXPRESSION
,
1838 PREC_RELATIONAL_EXPRESSION
,
1839 PREC_SHIFT_EXPRESSION
,
1840 PREC_ADDITIVE_EXPRESSION
,
1841 PREC_MULTIPLICATIVE_EXPRESSION
,
1843 NUM_PREC_VALUES
= PREC_PM_EXPRESSION
1846 /* A mapping from a token type to a corresponding tree node type, with a
1847 precedence value. */
1849 struct cp_parser_binary_operations_map_node
1851 /* The token type. */
1852 enum cpp_ttype token_type
;
1853 /* The corresponding tree code. */
1854 enum tree_code tree_type
;
1855 /* The precedence of this operator. */
1856 enum cp_parser_prec prec
;
1859 struct cp_parser_expression_stack_entry
1861 /* Left hand side of the binary operation we are currently
1864 /* Original tree code for left hand side, if it was a binary
1865 expression itself (used for -Wparentheses). */
1866 enum tree_code lhs_type
;
1867 /* Tree code for the binary operation we are parsing. */
1868 enum tree_code tree_type
;
1869 /* Precedence of the binary operation we are parsing. */
1870 enum cp_parser_prec prec
;
1871 /* Location of the binary operation we are parsing. */
1875 /* The stack for storing partial expressions. We only need NUM_PREC_VALUES
1876 entries because precedence levels on the stack are monotonically
1878 typedef struct cp_parser_expression_stack_entry
1879 cp_parser_expression_stack
[NUM_PREC_VALUES
];
1883 /* Constructors and destructors. */
1885 static cp_parser_context
*cp_parser_context_new
1886 (cp_parser_context
*);
1888 /* Class variables. */
1890 static GTY((deletable
)) cp_parser_context
* cp_parser_context_free_list
;
1892 /* The operator-precedence table used by cp_parser_binary_expression.
1893 Transformed into an associative array (binops_by_token) by
1896 static const cp_parser_binary_operations_map_node binops
[] = {
1897 { CPP_DEREF_STAR
, MEMBER_REF
, PREC_PM_EXPRESSION
},
1898 { CPP_DOT_STAR
, DOTSTAR_EXPR
, PREC_PM_EXPRESSION
},
1900 { CPP_MULT
, MULT_EXPR
, PREC_MULTIPLICATIVE_EXPRESSION
},
1901 { CPP_DIV
, TRUNC_DIV_EXPR
, PREC_MULTIPLICATIVE_EXPRESSION
},
1902 { CPP_MOD
, TRUNC_MOD_EXPR
, PREC_MULTIPLICATIVE_EXPRESSION
},
1904 { CPP_PLUS
, PLUS_EXPR
, PREC_ADDITIVE_EXPRESSION
},
1905 { CPP_MINUS
, MINUS_EXPR
, PREC_ADDITIVE_EXPRESSION
},
1907 { CPP_LSHIFT
, LSHIFT_EXPR
, PREC_SHIFT_EXPRESSION
},
1908 { CPP_RSHIFT
, RSHIFT_EXPR
, PREC_SHIFT_EXPRESSION
},
1910 { CPP_LESS
, LT_EXPR
, PREC_RELATIONAL_EXPRESSION
},
1911 { CPP_GREATER
, GT_EXPR
, PREC_RELATIONAL_EXPRESSION
},
1912 { CPP_LESS_EQ
, LE_EXPR
, PREC_RELATIONAL_EXPRESSION
},
1913 { CPP_GREATER_EQ
, GE_EXPR
, PREC_RELATIONAL_EXPRESSION
},
1915 { CPP_EQ_EQ
, EQ_EXPR
, PREC_EQUALITY_EXPRESSION
},
1916 { CPP_NOT_EQ
, NE_EXPR
, PREC_EQUALITY_EXPRESSION
},
1918 { CPP_AND
, BIT_AND_EXPR
, PREC_AND_EXPRESSION
},
1920 { CPP_XOR
, BIT_XOR_EXPR
, PREC_EXCLUSIVE_OR_EXPRESSION
},
1922 { CPP_OR
, BIT_IOR_EXPR
, PREC_INCLUSIVE_OR_EXPRESSION
},
1924 { CPP_AND_AND
, TRUTH_ANDIF_EXPR
, PREC_LOGICAL_AND_EXPRESSION
},
1926 { CPP_OR_OR
, TRUTH_ORIF_EXPR
, PREC_LOGICAL_OR_EXPRESSION
}
1929 /* The same as binops, but initialized by cp_parser_new so that
1930 binops_by_token[N].token_type == N. Used in cp_parser_binary_expression
1932 static cp_parser_binary_operations_map_node binops_by_token
[N_CP_TTYPES
];
1934 /* Constructors and destructors. */
1936 /* Construct a new context. The context below this one on the stack
1937 is given by NEXT. */
1939 static cp_parser_context
*
1940 cp_parser_context_new (cp_parser_context
* next
)
1942 cp_parser_context
*context
;
1944 /* Allocate the storage. */
1945 if (cp_parser_context_free_list
!= NULL
)
1947 /* Pull the first entry from the free list. */
1948 context
= cp_parser_context_free_list
;
1949 cp_parser_context_free_list
= context
->next
;
1950 memset (context
, 0, sizeof (*context
));
1953 context
= ggc_cleared_alloc
<cp_parser_context
> ();
1955 /* No errors have occurred yet in this context. */
1956 context
->status
= CP_PARSER_STATUS_KIND_NO_ERROR
;
1957 /* If this is not the bottommost context, copy information that we
1958 need from the previous context. */
1961 /* If, in the NEXT context, we are parsing an `x->' or `x.'
1962 expression, then we are parsing one in this context, too. */
1963 context
->object_type
= next
->object_type
;
1964 /* Thread the stack. */
1965 context
->next
= next
;
1971 /* Managing the unparsed function queues. */
1973 #define unparsed_funs_with_default_args \
1974 parser->unparsed_queues->last ().funs_with_default_args
1975 #define unparsed_funs_with_definitions \
1976 parser->unparsed_queues->last ().funs_with_definitions
1977 #define unparsed_nsdmis \
1978 parser->unparsed_queues->last ().nsdmis
1979 #define unparsed_classes \
1980 parser->unparsed_queues->last ().classes
1983 push_unparsed_function_queues (cp_parser
*parser
)
1985 cp_unparsed_functions_entry e
= {NULL
, make_tree_vector (), NULL
, NULL
};
1986 vec_safe_push (parser
->unparsed_queues
, e
);
1990 pop_unparsed_function_queues (cp_parser
*parser
)
1992 release_tree_vector (unparsed_funs_with_definitions
);
1993 parser
->unparsed_queues
->pop ();
1998 /* Constructors and destructors. */
2000 static cp_parser
*cp_parser_new
2003 /* Routines to parse various constructs.
2005 Those that return `tree' will return the error_mark_node (rather
2006 than NULL_TREE) if a parse error occurs, unless otherwise noted.
2007 Sometimes, they will return an ordinary node if error-recovery was
2008 attempted, even though a parse error occurred. So, to check
2009 whether or not a parse error occurred, you should always use
2010 cp_parser_error_occurred. If the construct is optional (indicated
2011 either by an `_opt' in the name of the function that does the
2012 parsing or via a FLAGS parameter), then NULL_TREE is returned if
2013 the construct is not present. */
2015 /* Lexical conventions [gram.lex] */
2017 static cp_expr cp_parser_identifier
2019 static cp_expr cp_parser_string_literal
2020 (cp_parser
*, bool, bool, bool);
2021 static cp_expr cp_parser_userdef_char_literal
2023 static tree cp_parser_userdef_string_literal
2025 static cp_expr cp_parser_userdef_numeric_literal
2028 /* Basic concepts [gram.basic] */
2030 static bool cp_parser_translation_unit
2033 /* Expressions [gram.expr] */
2035 static cp_expr cp_parser_primary_expression
2036 (cp_parser
*, bool, bool, bool, cp_id_kind
*);
2037 static cp_expr cp_parser_id_expression
2038 (cp_parser
*, bool, bool, bool *, bool, bool);
2039 static cp_expr cp_parser_unqualified_id
2040 (cp_parser
*, bool, bool, bool, bool);
2041 static tree cp_parser_nested_name_specifier_opt
2042 (cp_parser
*, bool, bool, bool, bool, bool = false);
2043 static tree cp_parser_nested_name_specifier
2044 (cp_parser
*, bool, bool, bool, bool);
2045 static tree cp_parser_qualifying_entity
2046 (cp_parser
*, bool, bool, bool, bool, bool);
2047 static cp_expr cp_parser_postfix_expression
2048 (cp_parser
*, bool, bool, bool, bool, cp_id_kind
*);
2049 static tree cp_parser_postfix_open_square_expression
2050 (cp_parser
*, tree
, bool, bool);
2051 static tree cp_parser_postfix_dot_deref_expression
2052 (cp_parser
*, enum cpp_ttype
, cp_expr
, bool, cp_id_kind
*, location_t
);
2053 static vec
<tree
, va_gc
> *cp_parser_parenthesized_expression_list
2054 (cp_parser
*, int, bool, bool, bool *, location_t
* = NULL
);
2055 /* Values for the second parameter of cp_parser_parenthesized_expression_list. */
2056 enum { non_attr
= 0, normal_attr
= 1, id_attr
= 2 };
2057 static void cp_parser_pseudo_destructor_name
2058 (cp_parser
*, tree
, tree
*, tree
*);
2059 static cp_expr cp_parser_unary_expression
2060 (cp_parser
*, cp_id_kind
* = NULL
, bool = false, bool = false, bool = false);
2061 static enum tree_code cp_parser_unary_operator
2063 static tree cp_parser_new_expression
2065 static vec
<tree
, va_gc
> *cp_parser_new_placement
2067 static tree cp_parser_new_type_id
2068 (cp_parser
*, tree
*);
2069 static cp_declarator
*cp_parser_new_declarator_opt
2071 static cp_declarator
*cp_parser_direct_new_declarator
2073 static vec
<tree
, va_gc
> *cp_parser_new_initializer
2075 static tree cp_parser_delete_expression
2077 static cp_expr cp_parser_cast_expression
2078 (cp_parser
*, bool, bool, bool, cp_id_kind
*);
2079 static cp_expr cp_parser_binary_expression
2080 (cp_parser
*, bool, bool, enum cp_parser_prec
, cp_id_kind
*);
2081 static tree cp_parser_question_colon_clause
2082 (cp_parser
*, cp_expr
);
2083 static cp_expr cp_parser_assignment_expression
2084 (cp_parser
*, cp_id_kind
* = NULL
, bool = false, bool = false);
2085 static enum tree_code cp_parser_assignment_operator_opt
2087 static cp_expr cp_parser_expression
2088 (cp_parser
*, cp_id_kind
* = NULL
, bool = false, bool = false);
2089 static cp_expr cp_parser_constant_expression
2090 (cp_parser
*, bool = false, bool * = NULL
);
2091 static cp_expr cp_parser_builtin_offsetof
2093 static cp_expr cp_parser_lambda_expression
2095 static void cp_parser_lambda_introducer
2096 (cp_parser
*, tree
);
2097 static bool cp_parser_lambda_declarator_opt
2098 (cp_parser
*, tree
);
2099 static void cp_parser_lambda_body
2100 (cp_parser
*, tree
);
2102 /* Statements [gram.stmt.stmt] */
2104 static void cp_parser_statement
2105 (cp_parser
*, tree
, bool, bool *, vec
<tree
> * = NULL
, location_t
* = NULL
);
2106 static void cp_parser_label_for_labeled_statement
2107 (cp_parser
*, tree
);
2108 static tree cp_parser_expression_statement
2109 (cp_parser
*, tree
);
2110 static tree cp_parser_compound_statement
2111 (cp_parser
*, tree
, int, bool);
2112 static void cp_parser_statement_seq_opt
2113 (cp_parser
*, tree
);
2114 static tree cp_parser_selection_statement
2115 (cp_parser
*, bool *, vec
<tree
> *);
2116 static tree cp_parser_condition
2118 static tree cp_parser_iteration_statement
2119 (cp_parser
*, bool *, bool);
2120 static bool cp_parser_init_statement
2121 (cp_parser
*, tree
*decl
);
2122 static tree cp_parser_for
2123 (cp_parser
*, bool);
2124 static tree cp_parser_c_for
2125 (cp_parser
*, tree
, tree
, bool);
2126 static tree cp_parser_range_for
2127 (cp_parser
*, tree
, tree
, tree
, bool);
2128 static void do_range_for_auto_deduction
2130 static tree cp_parser_perform_range_for_lookup
2131 (tree
, tree
*, tree
*);
2132 static tree cp_parser_range_for_member_function
2134 static tree cp_parser_jump_statement
2136 static void cp_parser_declaration_statement
2139 static tree cp_parser_implicitly_scoped_statement
2140 (cp_parser
*, bool *, const token_indent_info
&, vec
<tree
> * = NULL
);
2141 static void cp_parser_already_scoped_statement
2142 (cp_parser
*, bool *, const token_indent_info
&);
2144 /* Declarations [gram.dcl.dcl] */
2146 static void cp_parser_declaration_seq_opt
2148 static void cp_parser_declaration
2150 static void cp_parser_block_declaration
2151 (cp_parser
*, bool);
2152 static void cp_parser_simple_declaration
2153 (cp_parser
*, bool, tree
*);
2154 static void cp_parser_decl_specifier_seq
2155 (cp_parser
*, cp_parser_flags
, cp_decl_specifier_seq
*, int *);
2156 static tree cp_parser_storage_class_specifier_opt
2158 static tree cp_parser_function_specifier_opt
2159 (cp_parser
*, cp_decl_specifier_seq
*);
2160 static tree cp_parser_type_specifier
2161 (cp_parser
*, cp_parser_flags
, cp_decl_specifier_seq
*, bool,
2163 static tree cp_parser_simple_type_specifier
2164 (cp_parser
*, cp_decl_specifier_seq
*, cp_parser_flags
);
2165 static tree cp_parser_type_name
2166 (cp_parser
*, bool);
2167 static tree cp_parser_type_name
2169 static tree cp_parser_nonclass_name
2170 (cp_parser
* parser
);
2171 static tree cp_parser_elaborated_type_specifier
2172 (cp_parser
*, bool, bool);
2173 static tree cp_parser_enum_specifier
2175 static void cp_parser_enumerator_list
2176 (cp_parser
*, tree
);
2177 static void cp_parser_enumerator_definition
2178 (cp_parser
*, tree
);
2179 static tree cp_parser_namespace_name
2181 static void cp_parser_namespace_definition
2183 static void cp_parser_namespace_body
2185 static tree cp_parser_qualified_namespace_specifier
2187 static void cp_parser_namespace_alias_definition
2189 static bool cp_parser_using_declaration
2190 (cp_parser
*, bool);
2191 static void cp_parser_using_directive
2193 static tree cp_parser_alias_declaration
2195 static void cp_parser_asm_definition
2197 static void cp_parser_linkage_specification
2199 static void cp_parser_static_assert
2200 (cp_parser
*, bool);
2201 static tree cp_parser_decltype
2203 static tree cp_parser_decomposition_declaration
2204 (cp_parser
*, cp_decl_specifier_seq
*, tree
*, location_t
*);
2206 /* Declarators [gram.dcl.decl] */
2208 static tree cp_parser_init_declarator
2209 (cp_parser
*, cp_decl_specifier_seq
*, vec
<deferred_access_check
, va_gc
> *,
2210 bool, bool, int, bool *, tree
*, location_t
*, tree
*);
2211 static cp_declarator
*cp_parser_declarator
2212 (cp_parser
*, cp_parser_declarator_kind
, int *, bool *, bool, bool);
2213 static cp_declarator
*cp_parser_direct_declarator
2214 (cp_parser
*, cp_parser_declarator_kind
, int *, bool, bool);
2215 static enum tree_code cp_parser_ptr_operator
2216 (cp_parser
*, tree
*, cp_cv_quals
*, tree
*);
2217 static cp_cv_quals cp_parser_cv_qualifier_seq_opt
2219 static cp_virt_specifiers cp_parser_virt_specifier_seq_opt
2221 static cp_ref_qualifier cp_parser_ref_qualifier_opt
2223 static tree cp_parser_tx_qualifier_opt
2225 static tree cp_parser_late_return_type_opt
2226 (cp_parser
*, cp_declarator
*, tree
&, cp_cv_quals
);
2227 static tree cp_parser_declarator_id
2228 (cp_parser
*, bool);
2229 static tree cp_parser_type_id
2231 static tree cp_parser_template_type_arg
2233 static tree
cp_parser_trailing_type_id (cp_parser
*);
2234 static tree cp_parser_type_id_1
2235 (cp_parser
*, bool, bool);
2236 static void cp_parser_type_specifier_seq
2237 (cp_parser
*, bool, bool, cp_decl_specifier_seq
*);
2238 static tree cp_parser_parameter_declaration_clause
2240 static tree cp_parser_parameter_declaration_list
2241 (cp_parser
*, bool *);
2242 static cp_parameter_declarator
*cp_parser_parameter_declaration
2243 (cp_parser
*, bool, bool *);
2244 static tree cp_parser_default_argument
2245 (cp_parser
*, bool);
2246 static void cp_parser_function_body
2247 (cp_parser
*, bool);
2248 static tree cp_parser_initializer
2249 (cp_parser
*, bool *, bool *);
2250 static cp_expr cp_parser_initializer_clause
2251 (cp_parser
*, bool *);
2252 static cp_expr cp_parser_braced_list
2253 (cp_parser
*, bool*);
2254 static vec
<constructor_elt
, va_gc
> *cp_parser_initializer_list
2255 (cp_parser
*, bool *);
2257 static bool cp_parser_ctor_initializer_opt_and_function_body
2258 (cp_parser
*, bool);
2260 static tree cp_parser_late_parsing_omp_declare_simd
2261 (cp_parser
*, tree
);
2263 static tree cp_parser_late_parsing_cilk_simd_fn_info
2264 (cp_parser
*, tree
);
2266 static tree cp_parser_late_parsing_oacc_routine
2267 (cp_parser
*, tree
);
2269 static tree synthesize_implicit_template_parm
2270 (cp_parser
*, tree
);
2271 static tree finish_fully_implicit_template
2272 (cp_parser
*, tree
);
2274 /* Classes [gram.class] */
2276 static tree cp_parser_class_name
2277 (cp_parser
*, bool, bool, enum tag_types
, bool, bool, bool, bool = false);
2278 static tree cp_parser_class_specifier
2280 static tree cp_parser_class_head
2281 (cp_parser
*, bool *);
2282 static enum tag_types cp_parser_class_key
2284 static void cp_parser_type_parameter_key
2285 (cp_parser
* parser
);
2286 static void cp_parser_member_specification_opt
2288 static void cp_parser_member_declaration
2290 static tree cp_parser_pure_specifier
2292 static tree cp_parser_constant_initializer
2295 /* Derived classes [gram.class.derived] */
2297 static tree cp_parser_base_clause
2299 static tree cp_parser_base_specifier
2302 /* Special member functions [gram.special] */
2304 static tree cp_parser_conversion_function_id
2306 static tree cp_parser_conversion_type_id
2308 static cp_declarator
*cp_parser_conversion_declarator_opt
2310 static bool cp_parser_ctor_initializer_opt
2312 static void cp_parser_mem_initializer_list
2314 static tree cp_parser_mem_initializer
2316 static tree cp_parser_mem_initializer_id
2319 /* Overloading [gram.over] */
2321 static cp_expr cp_parser_operator_function_id
2323 static cp_expr cp_parser_operator
2326 /* Templates [gram.temp] */
2328 static void cp_parser_template_declaration
2329 (cp_parser
*, bool);
2330 static tree cp_parser_template_parameter_list
2332 static tree cp_parser_template_parameter
2333 (cp_parser
*, bool *, bool *);
2334 static tree cp_parser_type_parameter
2335 (cp_parser
*, bool *);
2336 static tree cp_parser_template_id
2337 (cp_parser
*, bool, bool, enum tag_types
, bool);
2338 static tree cp_parser_template_name
2339 (cp_parser
*, bool, bool, bool, enum tag_types
, bool *);
2340 static tree cp_parser_template_argument_list
2342 static tree cp_parser_template_argument
2344 static void cp_parser_explicit_instantiation
2346 static void cp_parser_explicit_specialization
2349 /* Exception handling [gram.exception] */
2351 static tree cp_parser_try_block
2353 static bool cp_parser_function_try_block
2355 static void cp_parser_handler_seq
2357 static void cp_parser_handler
2359 static tree cp_parser_exception_declaration
2361 static tree cp_parser_throw_expression
2363 static tree cp_parser_exception_specification_opt
2365 static tree cp_parser_type_id_list
2368 /* GNU Extensions */
2370 static tree cp_parser_asm_specification_opt
2372 static tree cp_parser_asm_operand_list
2374 static tree cp_parser_asm_clobber_list
2376 static tree cp_parser_asm_label_list
2378 static bool cp_next_tokens_can_be_attribute_p
2380 static bool cp_next_tokens_can_be_gnu_attribute_p
2382 static bool cp_next_tokens_can_be_std_attribute_p
2384 static bool cp_nth_tokens_can_be_std_attribute_p
2385 (cp_parser
*, size_t);
2386 static bool cp_nth_tokens_can_be_gnu_attribute_p
2387 (cp_parser
*, size_t);
2388 static bool cp_nth_tokens_can_be_attribute_p
2389 (cp_parser
*, size_t);
2390 static tree cp_parser_attributes_opt
2392 static tree cp_parser_gnu_attributes_opt
2394 static tree cp_parser_gnu_attribute_list
2396 static tree cp_parser_std_attribute
2397 (cp_parser
*, tree
);
2398 static tree cp_parser_std_attribute_spec
2400 static tree cp_parser_std_attribute_spec_seq
2402 static bool cp_parser_extension_opt
2403 (cp_parser
*, int *);
2404 static void cp_parser_label_declaration
2407 /* Concept Extensions */
2409 static tree cp_parser_requires_clause
2411 static tree cp_parser_requires_clause_opt
2413 static tree cp_parser_requires_expression
2415 static tree cp_parser_requirement_parameter_list
2417 static tree cp_parser_requirement_body
2419 static tree cp_parser_requirement_list
2421 static tree cp_parser_requirement
2423 static tree cp_parser_simple_requirement
2425 static tree cp_parser_compound_requirement
2427 static tree cp_parser_type_requirement
2429 static tree cp_parser_nested_requirement
2432 /* Transactional Memory Extensions */
2434 static tree cp_parser_transaction
2435 (cp_parser
*, cp_token
*);
2436 static tree cp_parser_transaction_expression
2437 (cp_parser
*, enum rid
);
2438 static bool cp_parser_function_transaction
2439 (cp_parser
*, enum rid
);
2440 static tree cp_parser_transaction_cancel
2443 enum pragma_context
{
2450 static bool cp_parser_pragma
2451 (cp_parser
*, enum pragma_context
, bool *);
2453 /* Objective-C++ Productions */
2455 static tree cp_parser_objc_message_receiver
2457 static tree cp_parser_objc_message_args
2459 static tree cp_parser_objc_message_expression
2461 static cp_expr cp_parser_objc_encode_expression
2463 static tree cp_parser_objc_defs_expression
2465 static tree cp_parser_objc_protocol_expression
2467 static tree cp_parser_objc_selector_expression
2469 static cp_expr cp_parser_objc_expression
2471 static bool cp_parser_objc_selector_p
2473 static tree cp_parser_objc_selector
2475 static tree cp_parser_objc_protocol_refs_opt
2477 static void cp_parser_objc_declaration
2478 (cp_parser
*, tree
);
2479 static tree cp_parser_objc_statement
2481 static bool cp_parser_objc_valid_prefix_attributes
2482 (cp_parser
*, tree
*);
2483 static void cp_parser_objc_at_property_declaration
2485 static void cp_parser_objc_at_synthesize_declaration
2487 static void cp_parser_objc_at_dynamic_declaration
2489 static tree cp_parser_objc_struct_declaration
2492 /* Utility Routines */
2494 static cp_expr cp_parser_lookup_name
2495 (cp_parser
*, tree
, enum tag_types
, bool, bool, bool, tree
*, location_t
);
2496 static tree cp_parser_lookup_name_simple
2497 (cp_parser
*, tree
, location_t
);
2498 static tree cp_parser_maybe_treat_template_as_class
2500 static bool cp_parser_check_declarator_template_parameters
2501 (cp_parser
*, cp_declarator
*, location_t
);
2502 static bool cp_parser_check_template_parameters
2503 (cp_parser
*, unsigned, location_t
, cp_declarator
*);
2504 static cp_expr cp_parser_simple_cast_expression
2506 static tree cp_parser_global_scope_opt
2507 (cp_parser
*, bool);
2508 static bool cp_parser_constructor_declarator_p
2509 (cp_parser
*, bool);
2510 static tree cp_parser_function_definition_from_specifiers_and_declarator
2511 (cp_parser
*, cp_decl_specifier_seq
*, tree
, const cp_declarator
*);
2512 static tree cp_parser_function_definition_after_declarator
2513 (cp_parser
*, bool);
2514 static bool cp_parser_template_declaration_after_export
2515 (cp_parser
*, bool);
2516 static void cp_parser_perform_template_parameter_access_checks
2517 (vec
<deferred_access_check
, va_gc
> *);
2518 static tree cp_parser_single_declaration
2519 (cp_parser
*, vec
<deferred_access_check
, va_gc
> *, bool, bool, bool *);
2520 static cp_expr cp_parser_functional_cast
2521 (cp_parser
*, tree
);
2522 static tree cp_parser_save_member_function_body
2523 (cp_parser
*, cp_decl_specifier_seq
*, cp_declarator
*, tree
);
2524 static tree cp_parser_save_nsdmi
2526 static tree cp_parser_enclosed_template_argument_list
2528 static void cp_parser_save_default_args
2529 (cp_parser
*, tree
);
2530 static void cp_parser_late_parsing_for_member
2531 (cp_parser
*, tree
);
2532 static tree cp_parser_late_parse_one_default_arg
2533 (cp_parser
*, tree
, tree
, tree
);
2534 static void cp_parser_late_parsing_nsdmi
2535 (cp_parser
*, tree
);
2536 static void cp_parser_late_parsing_default_args
2537 (cp_parser
*, tree
);
2538 static tree cp_parser_sizeof_operand
2539 (cp_parser
*, enum rid
);
2540 static tree cp_parser_trait_expr
2541 (cp_parser
*, enum rid
);
2542 static bool cp_parser_declares_only_class_p
2544 static void cp_parser_set_storage_class
2545 (cp_parser
*, cp_decl_specifier_seq
*, enum rid
, cp_token
*);
2546 static void cp_parser_set_decl_spec_type
2547 (cp_decl_specifier_seq
*, tree
, cp_token
*, bool);
2548 static void set_and_check_decl_spec_loc
2549 (cp_decl_specifier_seq
*decl_specs
,
2550 cp_decl_spec ds
, cp_token
*);
2551 static bool cp_parser_friend_p
2552 (const cp_decl_specifier_seq
*);
2553 static void cp_parser_required_error
2554 (cp_parser
*, required_token
, bool);
2555 static cp_token
*cp_parser_require
2556 (cp_parser
*, enum cpp_ttype
, required_token
);
2557 static cp_token
*cp_parser_require_keyword
2558 (cp_parser
*, enum rid
, required_token
);
2559 static bool cp_parser_token_starts_function_definition_p
2561 static bool cp_parser_next_token_starts_class_definition_p
2563 static bool cp_parser_next_token_ends_template_argument_p
2565 static bool cp_parser_nth_token_starts_template_argument_list_p
2566 (cp_parser
*, size_t);
2567 static enum tag_types cp_parser_token_is_class_key
2569 static enum tag_types cp_parser_token_is_type_parameter_key
2571 static void cp_parser_check_class_key
2572 (enum tag_types
, tree type
);
2573 static void cp_parser_check_access_in_redeclaration
2574 (tree type
, location_t location
);
2575 static bool cp_parser_optional_template_keyword
2577 static void cp_parser_pre_parsed_nested_name_specifier
2579 static bool cp_parser_cache_group
2580 (cp_parser
*, enum cpp_ttype
, unsigned);
2581 static tree cp_parser_cache_defarg
2582 (cp_parser
*parser
, bool nsdmi
);
2583 static void cp_parser_parse_tentatively
2585 static void cp_parser_commit_to_tentative_parse
2587 static void cp_parser_commit_to_topmost_tentative_parse
2589 static void cp_parser_abort_tentative_parse
2591 static bool cp_parser_parse_definitely
2593 static inline bool cp_parser_parsing_tentatively
2595 static bool cp_parser_uncommitted_to_tentative_parse_p
2597 static void cp_parser_error
2598 (cp_parser
*, const char *);
2599 static void cp_parser_name_lookup_error
2600 (cp_parser
*, tree
, tree
, name_lookup_error
, location_t
);
2601 static bool cp_parser_simulate_error
2603 static bool cp_parser_check_type_definition
2605 static void cp_parser_check_for_definition_in_return_type
2606 (cp_declarator
*, tree
, location_t type_location
);
2607 static void cp_parser_check_for_invalid_template_id
2608 (cp_parser
*, tree
, enum tag_types
, location_t location
);
2609 static bool cp_parser_non_integral_constant_expression
2610 (cp_parser
*, non_integral_constant
);
2611 static void cp_parser_diagnose_invalid_type_name
2612 (cp_parser
*, tree
, location_t
);
2613 static bool cp_parser_parse_and_diagnose_invalid_type_name
2615 static int cp_parser_skip_to_closing_parenthesis
2616 (cp_parser
*, bool, bool, bool);
2617 static void cp_parser_skip_to_end_of_statement
2619 static void cp_parser_consume_semicolon_at_end_of_statement
2621 static void cp_parser_skip_to_end_of_block_or_statement
2623 static bool cp_parser_skip_to_closing_brace
2625 static void cp_parser_skip_to_end_of_template_parameter_list
2627 static void cp_parser_skip_to_pragma_eol
2628 (cp_parser
*, cp_token
*);
2629 static bool cp_parser_error_occurred
2631 static bool cp_parser_allow_gnu_extensions_p
2633 static bool cp_parser_is_pure_string_literal
2635 static bool cp_parser_is_string_literal
2637 static bool cp_parser_is_keyword
2638 (cp_token
*, enum rid
);
2639 static tree cp_parser_make_typename_type
2640 (cp_parser
*, tree
, location_t location
);
2641 static cp_declarator
* cp_parser_make_indirect_declarator
2642 (enum tree_code
, tree
, cp_cv_quals
, cp_declarator
*, tree
);
2643 static bool cp_parser_compound_literal_p
2645 static bool cp_parser_array_designator_p
2647 static bool cp_parser_init_statement_p
2649 static bool cp_parser_skip_to_closing_square_bracket
2652 /* Concept-related syntactic transformations */
2654 static tree
cp_parser_maybe_concept_name (cp_parser
*, tree
);
2655 static tree
cp_parser_maybe_partial_concept_id (cp_parser
*, tree
, tree
);
2657 // -------------------------------------------------------------------------- //
2658 // Unevaluated Operand Guard
2660 // Implementation of an RAII helper for unevaluated operand parsing.
2661 cp_unevaluated::cp_unevaluated ()
2663 ++cp_unevaluated_operand
;
2664 ++c_inhibit_evaluation_warnings
;
2667 cp_unevaluated::~cp_unevaluated ()
2669 --c_inhibit_evaluation_warnings
;
2670 --cp_unevaluated_operand
;
2673 // -------------------------------------------------------------------------- //
2674 // Tentative Parsing
2676 /* Returns nonzero if we are parsing tentatively. */
2679 cp_parser_parsing_tentatively (cp_parser
* parser
)
2681 return parser
->context
->next
!= NULL
;
2684 /* Returns nonzero if TOKEN is a string literal. */
2687 cp_parser_is_pure_string_literal (cp_token
* token
)
2689 return (token
->type
== CPP_STRING
||
2690 token
->type
== CPP_STRING16
||
2691 token
->type
== CPP_STRING32
||
2692 token
->type
== CPP_WSTRING
||
2693 token
->type
== CPP_UTF8STRING
);
2696 /* Returns nonzero if TOKEN is a string literal
2697 of a user-defined string literal. */
2700 cp_parser_is_string_literal (cp_token
* token
)
2702 return (cp_parser_is_pure_string_literal (token
) ||
2703 token
->type
== CPP_STRING_USERDEF
||
2704 token
->type
== CPP_STRING16_USERDEF
||
2705 token
->type
== CPP_STRING32_USERDEF
||
2706 token
->type
== CPP_WSTRING_USERDEF
||
2707 token
->type
== CPP_UTF8STRING_USERDEF
);
2710 /* Returns nonzero if TOKEN is the indicated KEYWORD. */
2713 cp_parser_is_keyword (cp_token
* token
, enum rid keyword
)
2715 return token
->keyword
== keyword
;
2718 /* Return TOKEN's pragma_kind if it is CPP_PRAGMA, otherwise
2721 static enum pragma_kind
2722 cp_parser_pragma_kind (cp_token
*token
)
2724 if (token
->type
!= CPP_PRAGMA
)
2726 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
2727 return (enum pragma_kind
) TREE_INT_CST_LOW (token
->u
.value
);
2730 /* Helper function for cp_parser_error.
2731 Having peeked a token of kind TOK1_KIND that might signify
2732 a conflict marker, peek successor tokens to determine
2733 if we actually do have a conflict marker.
2734 Specifically, we consider a run of 7 '<', '=' or '>' characters
2735 at the start of a line as a conflict marker.
2736 These come through the lexer as three pairs and a single,
2737 e.g. three CPP_LSHIFT tokens ("<<") and a CPP_LESS token ('<').
2738 If it returns true, *OUT_LOC is written to with the location/range
2742 cp_lexer_peek_conflict_marker (cp_lexer
*lexer
, enum cpp_ttype tok1_kind
,
2743 location_t
*out_loc
)
2745 cp_token
*token2
= cp_lexer_peek_nth_token (lexer
, 2);
2746 if (token2
->type
!= tok1_kind
)
2748 cp_token
*token3
= cp_lexer_peek_nth_token (lexer
, 3);
2749 if (token3
->type
!= tok1_kind
)
2751 cp_token
*token4
= cp_lexer_peek_nth_token (lexer
, 4);
2752 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
2755 /* It must be at the start of the line. */
2756 location_t start_loc
= cp_lexer_peek_token (lexer
)->location
;
2757 if (LOCATION_COLUMN (start_loc
) != 1)
2760 /* We have a conflict marker. Construct a location of the form:
2763 with start == caret, finishing at the end of the marker. */
2764 location_t finish_loc
= get_finish (token4
->location
);
2765 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
2770 /* If not parsing tentatively, issue a diagnostic of the form
2771 FILE:LINE: MESSAGE before TOKEN
2772 where TOKEN is the next token in the input stream. MESSAGE
2773 (specified by the caller) is usually of the form "expected
2777 cp_parser_error (cp_parser
* parser
, const char* gmsgid
)
2779 if (!cp_parser_simulate_error (parser
))
2781 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
2782 /* This diagnostic makes more sense if it is tagged to the line
2783 of the token we just peeked at. */
2784 cp_lexer_set_source_position_from_token (token
);
2786 if (token
->type
== CPP_PRAGMA
)
2788 error_at (token
->location
,
2789 "%<#pragma%> is not allowed here");
2790 cp_parser_skip_to_pragma_eol (parser
, token
);
2794 /* If this is actually a conflict marker, report it as such. */
2795 if (token
->type
== CPP_LSHIFT
2796 || token
->type
== CPP_RSHIFT
2797 || token
->type
== CPP_EQ_EQ
)
2800 if (cp_lexer_peek_conflict_marker (parser
->lexer
, token
->type
, &loc
))
2802 error_at (loc
, "version control conflict marker in file");
2807 c_parse_error (gmsgid
,
2808 /* Because c_parser_error does not understand
2809 CPP_KEYWORD, keywords are treated like
2811 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
2812 token
->u
.value
, token
->flags
);
2816 /* Issue an error about name-lookup failing. NAME is the
2817 IDENTIFIER_NODE DECL is the result of
2818 the lookup (as returned from cp_parser_lookup_name). DESIRED is
2819 the thing that we hoped to find. */
2822 cp_parser_name_lookup_error (cp_parser
* parser
,
2825 name_lookup_error desired
,
2826 location_t location
)
2828 /* If name lookup completely failed, tell the user that NAME was not
2830 if (decl
== error_mark_node
)
2832 if (parser
->scope
&& parser
->scope
!= global_namespace
)
2833 error_at (location
, "%<%E::%E%> has not been declared",
2834 parser
->scope
, name
);
2835 else if (parser
->scope
== global_namespace
)
2836 error_at (location
, "%<::%E%> has not been declared", name
);
2837 else if (parser
->object_scope
2838 && !CLASS_TYPE_P (parser
->object_scope
))
2839 error_at (location
, "request for member %qE in non-class type %qT",
2840 name
, parser
->object_scope
);
2841 else if (parser
->object_scope
)
2842 error_at (location
, "%<%T::%E%> has not been declared",
2843 parser
->object_scope
, name
);
2845 error_at (location
, "%qE has not been declared", name
);
2847 else if (parser
->scope
&& parser
->scope
!= global_namespace
)
2852 error_at (location
, "%<%E::%E%> is not a type",
2853 parser
->scope
, name
);
2856 error_at (location
, "%<%E::%E%> is not a class or namespace",
2857 parser
->scope
, name
);
2861 "%<%E::%E%> is not a class, namespace, or enumeration",
2862 parser
->scope
, name
);
2869 else if (parser
->scope
== global_namespace
)
2874 error_at (location
, "%<::%E%> is not a type", name
);
2877 error_at (location
, "%<::%E%> is not a class or namespace", name
);
2881 "%<::%E%> is not a class, namespace, or enumeration",
2893 error_at (location
, "%qE is not a type", name
);
2896 error_at (location
, "%qE is not a class or namespace", name
);
2900 "%qE is not a class, namespace, or enumeration", name
);
2908 /* If we are parsing tentatively, remember that an error has occurred
2909 during this tentative parse. Returns true if the error was
2910 simulated; false if a message should be issued by the caller. */
2913 cp_parser_simulate_error (cp_parser
* parser
)
2915 if (cp_parser_uncommitted_to_tentative_parse_p (parser
))
2917 parser
->context
->status
= CP_PARSER_STATUS_KIND_ERROR
;
2923 /* This function is called when a type is defined. If type
2924 definitions are forbidden at this point, an error message is
2928 cp_parser_check_type_definition (cp_parser
* parser
)
2930 /* If types are forbidden here, issue a message. */
2931 if (parser
->type_definition_forbidden_message
)
2933 /* Don't use `%s' to print the string, because quotations (`%<', `%>')
2934 in the message need to be interpreted. */
2935 error (parser
->type_definition_forbidden_message
);
2941 /* This function is called when the DECLARATOR is processed. The TYPE
2942 was a type defined in the decl-specifiers. If it is invalid to
2943 define a type in the decl-specifiers for DECLARATOR, an error is
2944 issued. TYPE_LOCATION is the location of TYPE and is used
2945 for error reporting. */
2948 cp_parser_check_for_definition_in_return_type (cp_declarator
*declarator
,
2949 tree type
, location_t type_location
)
2951 /* [dcl.fct] forbids type definitions in return types.
2952 Unfortunately, it's not easy to know whether or not we are
2953 processing a return type until after the fact. */
2955 && (declarator
->kind
== cdk_pointer
2956 || declarator
->kind
== cdk_reference
2957 || declarator
->kind
== cdk_ptrmem
))
2958 declarator
= declarator
->declarator
;
2960 && declarator
->kind
== cdk_function
)
2962 error_at (type_location
,
2963 "new types may not be defined in a return type");
2964 inform (type_location
,
2965 "(perhaps a semicolon is missing after the definition of %qT)",
2970 /* A type-specifier (TYPE) has been parsed which cannot be followed by
2971 "<" in any valid C++ program. If the next token is indeed "<",
2972 issue a message warning the user about what appears to be an
2973 invalid attempt to form a template-id. LOCATION is the location
2974 of the type-specifier (TYPE) */
2977 cp_parser_check_for_invalid_template_id (cp_parser
* parser
,
2979 enum tag_types tag_type
,
2980 location_t location
)
2982 cp_token_position start
= 0;
2984 if (cp_lexer_next_token_is (parser
->lexer
, CPP_LESS
))
2986 if (TREE_CODE (type
) == TYPE_DECL
)
2987 type
= TREE_TYPE (type
);
2988 if (TYPE_P (type
) && !template_placeholder_p (type
))
2989 error_at (location
, "%qT is not a template", type
);
2990 else if (identifier_p (type
))
2992 if (tag_type
!= none_type
)
2993 error_at (location
, "%qE is not a class template", type
);
2995 error_at (location
, "%qE is not a template", type
);
2998 error_at (location
, "invalid template-id");
2999 /* Remember the location of the invalid "<". */
3000 if (cp_parser_uncommitted_to_tentative_parse_p (parser
))
3001 start
= cp_lexer_token_position (parser
->lexer
, true);
3002 /* Consume the "<". */
3003 cp_lexer_consume_token (parser
->lexer
);
3004 /* Parse the template arguments. */
3005 cp_parser_enclosed_template_argument_list (parser
);
3006 /* Permanently remove the invalid template arguments so that
3007 this error message is not issued again. */
3009 cp_lexer_purge_tokens_after (parser
->lexer
, start
);
3013 /* If parsing an integral constant-expression, issue an error message
3014 about the fact that THING appeared and return true. Otherwise,
3015 return false. In either case, set
3016 PARSER->NON_INTEGRAL_CONSTANT_EXPRESSION_P. */
3019 cp_parser_non_integral_constant_expression (cp_parser
*parser
,
3020 non_integral_constant thing
)
3022 parser
->non_integral_constant_expression_p
= true;
3023 if (parser
->integral_constant_expression_p
)
3025 if (!parser
->allow_non_integral_constant_expression_p
)
3027 const char *msg
= NULL
;
3031 pedwarn (input_location
, OPT_Wpedantic
,
3032 "ISO C++ forbids using a floating-point literal "
3033 "in a constant-expression");
3036 error ("a cast to a type other than an integral or "
3037 "enumeration type cannot appear in a "
3038 "constant-expression");
3041 error ("%<typeid%> operator "
3042 "cannot appear in a constant-expression");
3045 error ("non-constant compound literals "
3046 "cannot appear in a constant-expression");
3049 error ("a function call "
3050 "cannot appear in a constant-expression");
3053 error ("an increment "
3054 "cannot appear in a constant-expression");
3057 error ("an decrement "
3058 "cannot appear in a constant-expression");
3061 error ("an array reference "
3062 "cannot appear in a constant-expression");
3064 case NIC_ADDR_LABEL
:
3065 error ("the address of a label "
3066 "cannot appear in a constant-expression");
3068 case NIC_OVERLOADED
:
3069 error ("calls to overloaded operators "
3070 "cannot appear in a constant-expression");
3072 case NIC_ASSIGNMENT
:
3073 error ("an assignment cannot appear in a constant-expression");
3076 error ("a comma operator "
3077 "cannot appear in a constant-expression");
3079 case NIC_CONSTRUCTOR
:
3080 error ("a call to a constructor "
3081 "cannot appear in a constant-expression");
3083 case NIC_TRANSACTION
:
3084 error ("a transaction expression "
3085 "cannot appear in a constant-expression");
3091 msg
= "__FUNCTION__";
3093 case NIC_PRETTY_FUNC
:
3094 msg
= "__PRETTY_FUNCTION__";
3114 case NIC_PREINCREMENT
:
3117 case NIC_PREDECREMENT
:
3130 error ("%qs cannot appear in a constant-expression", msg
);
3137 /* Emit a diagnostic for an invalid type name. This function commits
3138 to the current active tentative parse, if any. (Otherwise, the
3139 problematic construct might be encountered again later, resulting
3140 in duplicate error messages.) LOCATION is the location of ID. */
3143 cp_parser_diagnose_invalid_type_name (cp_parser
*parser
, tree id
,
3144 location_t location
)
3146 tree decl
, ambiguous_decls
;
3147 cp_parser_commit_to_tentative_parse (parser
);
3148 /* Try to lookup the identifier. */
3149 decl
= cp_parser_lookup_name (parser
, id
, none_type
,
3150 /*is_template=*/false,
3151 /*is_namespace=*/false,
3152 /*check_dependency=*/true,
3153 &ambiguous_decls
, location
);
3154 if (ambiguous_decls
)
3155 /* If the lookup was ambiguous, an error will already have
3158 /* If the lookup found a template-name, it means that the user forgot
3159 to specify an argument list. Emit a useful error message. */
3160 if (DECL_TYPE_TEMPLATE_P (decl
))
3163 "invalid use of template-name %qE without an argument list",
3165 if (DECL_CLASS_TEMPLATE_P (decl
) && cxx_dialect
< cxx1z
)
3166 inform (location
, "class template argument deduction is only available "
3167 "with -std=c++1z or -std=gnu++1z");
3168 inform (DECL_SOURCE_LOCATION (decl
), "%qD declared here", decl
);
3170 else if (TREE_CODE (id
) == BIT_NOT_EXPR
)
3171 error_at (location
, "invalid use of destructor %qD as a type", id
);
3172 else if (TREE_CODE (decl
) == TYPE_DECL
)
3173 /* Something like 'unsigned A a;' */
3174 error_at (location
, "invalid combination of multiple type-specifiers");
3175 else if (!parser
->scope
)
3177 /* Issue an error message. */
3178 const char *suggestion
= NULL
;
3179 if (TREE_CODE (id
) == IDENTIFIER_NODE
)
3180 suggestion
= lookup_name_fuzzy (id
, FUZZY_LOOKUP_TYPENAME
);
3183 gcc_rich_location
richloc (location
);
3184 richloc
.add_fixit_replace (suggestion
);
3185 error_at_rich_loc (&richloc
,
3186 "%qE does not name a type; did you mean %qs?",
3190 error_at (location
, "%qE does not name a type", id
);
3191 /* If we're in a template class, it's possible that the user was
3192 referring to a type from a base class. For example:
3194 template <typename T> struct A { typedef T X; };
3195 template <typename T> struct B : public A<T> { X x; };
3197 The user should have said "typename A<T>::X". */
3198 if (cxx_dialect
< cxx11
&& id
== ridpointers
[(int)RID_CONSTEXPR
])
3199 inform (location
, "C++11 %<constexpr%> only available with "
3200 "-std=c++11 or -std=gnu++11");
3201 else if (cxx_dialect
< cxx11
&& id
== ridpointers
[(int)RID_NOEXCEPT
])
3202 inform (location
, "C++11 %<noexcept%> only available with "
3203 "-std=c++11 or -std=gnu++11");
3204 else if (cxx_dialect
< cxx11
3205 && TREE_CODE (id
) == IDENTIFIER_NODE
3206 && id_equal (id
, "thread_local"))
3207 inform (location
, "C++11 %<thread_local%> only available with "
3208 "-std=c++11 or -std=gnu++11");
3209 else if (!flag_concepts
&& id
== ridpointers
[(int)RID_CONCEPT
])
3210 inform (location
, "%<concept%> only available with -fconcepts");
3211 else if (processing_template_decl
&& current_class_type
3212 && TYPE_BINFO (current_class_type
))
3216 for (b
= TREE_CHAIN (TYPE_BINFO (current_class_type
));
3220 tree base_type
= BINFO_TYPE (b
);
3221 if (CLASS_TYPE_P (base_type
)
3222 && dependent_type_p (base_type
))
3225 /* Go from a particular instantiation of the
3226 template (which will have an empty TYPE_FIELDs),
3227 to the main version. */
3228 base_type
= CLASSTYPE_PRIMARY_TEMPLATE_TYPE (base_type
);
3229 for (field
= TYPE_FIELDS (base_type
);
3231 field
= DECL_CHAIN (field
))
3232 if (TREE_CODE (field
) == TYPE_DECL
3233 && DECL_NAME (field
) == id
)
3236 "(perhaps %<typename %T::%E%> was intended)",
3237 BINFO_TYPE (b
), id
);
3246 /* Here we diagnose qualified-ids where the scope is actually correct,
3247 but the identifier does not resolve to a valid type name. */
3248 else if (parser
->scope
!= error_mark_node
)
3250 if (TREE_CODE (parser
->scope
) == NAMESPACE_DECL
)
3252 if (cp_lexer_next_token_is (parser
->lexer
, CPP_LESS
))
3253 error_at (location_of (id
),
3254 "%qE in namespace %qE does not name a template type",
3256 else if (TREE_CODE (id
) == TEMPLATE_ID_EXPR
)
3257 error_at (location_of (id
),
3258 "%qE in namespace %qE does not name a template type",
3259 TREE_OPERAND (id
, 0), parser
->scope
);
3261 error_at (location_of (id
),
3262 "%qE in namespace %qE does not name a type",
3265 inform (DECL_SOURCE_LOCATION (decl
), "%qD declared here", decl
);
3267 else if (CLASS_TYPE_P (parser
->scope
)
3268 && constructor_name_p (id
, parser
->scope
))
3271 error_at (location
, "%<%T::%E%> names the constructor, not"
3272 " the type", parser
->scope
, id
);
3273 if (cp_lexer_next_token_is (parser
->lexer
, CPP_LESS
))
3274 error_at (location
, "and %qT has no template constructors",
3277 else if (TYPE_P (parser
->scope
)
3278 && dependent_scope_p (parser
->scope
))
3280 if (TREE_CODE (parser
->scope
) == TYPENAME_TYPE
)
3282 "need %<typename%> before %<%T::%D::%E%> because "
3283 "%<%T::%D%> is a dependent scope",
3284 TYPE_CONTEXT (parser
->scope
),
3285 TYPENAME_TYPE_FULLNAME (parser
->scope
),
3287 TYPE_CONTEXT (parser
->scope
),
3288 TYPENAME_TYPE_FULLNAME (parser
->scope
));
3290 error_at (location
, "need %<typename%> before %<%T::%E%> because "
3291 "%qT is a dependent scope",
3292 parser
->scope
, id
, parser
->scope
);
3294 else if (TYPE_P (parser
->scope
))
3296 if (!COMPLETE_TYPE_P (parser
->scope
))
3297 cxx_incomplete_type_error (location_of (id
), NULL_TREE
,
3299 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_LESS
))
3300 error_at (location_of (id
),
3301 "%qE in %q#T does not name a template type",
3303 else if (TREE_CODE (id
) == TEMPLATE_ID_EXPR
)
3304 error_at (location_of (id
),
3305 "%qE in %q#T does not name a template type",
3306 TREE_OPERAND (id
, 0), parser
->scope
);
3308 error_at (location_of (id
),
3309 "%qE in %q#T does not name a type",
3312 inform (DECL_SOURCE_LOCATION (decl
), "%qD declared here", decl
);
3319 /* Check for a common situation where a type-name should be present,
3320 but is not, and issue a sensible error message. Returns true if an
3321 invalid type-name was detected.
3323 The situation handled by this function are variable declarations of the
3324 form `ID a', where `ID' is an id-expression and `a' is a plain identifier.
3325 Usually, `ID' should name a type, but if we got here it means that it
3326 does not. We try to emit the best possible error message depending on
3327 how exactly the id-expression looks like. */
3330 cp_parser_parse_and_diagnose_invalid_type_name (cp_parser
*parser
)
3333 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
3335 /* Avoid duplicate error about ambiguous lookup. */
3336 if (token
->type
== CPP_NESTED_NAME_SPECIFIER
)
3338 cp_token
*next
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
3339 if (next
->type
== CPP_NAME
&& next
->error_reported
)
3343 cp_parser_parse_tentatively (parser
);
3344 id
= cp_parser_id_expression (parser
,
3345 /*template_keyword_p=*/false,
3346 /*check_dependency_p=*/true,
3347 /*template_p=*/NULL
,
3348 /*declarator_p=*/true,
3349 /*optional_p=*/false);
3350 /* If the next token is a (, this is a function with no explicit return
3351 type, i.e. constructor, destructor or conversion op. */
3352 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
)
3353 || TREE_CODE (id
) == TYPE_DECL
)
3355 cp_parser_abort_tentative_parse (parser
);
3358 if (!cp_parser_parse_definitely (parser
))
3361 /* Emit a diagnostic for the invalid type. */
3362 cp_parser_diagnose_invalid_type_name (parser
, id
, token
->location
);
3364 /* If we aren't in the middle of a declarator (i.e. in a
3365 parameter-declaration-clause), skip to the end of the declaration;
3366 there's no point in trying to process it. */
3367 if (!parser
->in_declarator_p
)
3368 cp_parser_skip_to_end_of_block_or_statement (parser
);
3372 /* Consume tokens up to, and including, the next non-nested closing `)'.
3373 Returns 1 iff we found a closing `)'. RECOVERING is true, if we
3374 are doing error recovery. Returns -1 if OR_TTYPE is not CPP_EOF and we
3375 found an unnested token of that type. */
3378 cp_parser_skip_to_closing_parenthesis_1 (cp_parser
*parser
,
3383 unsigned paren_depth
= 0;
3384 unsigned brace_depth
= 0;
3385 unsigned square_depth
= 0;
3387 if (recovering
&& or_ttype
== CPP_EOF
3388 && cp_parser_uncommitted_to_tentative_parse_p (parser
))
3393 cp_token
* token
= cp_lexer_peek_token (parser
->lexer
);
3395 /* Have we found what we're looking for before the closing paren? */
3396 if (token
->type
== or_ttype
&& or_ttype
!= CPP_EOF
3397 && !brace_depth
&& !paren_depth
&& !square_depth
)
3400 switch (token
->type
)
3403 case CPP_PRAGMA_EOL
:
3404 /* If we've run out of tokens, then there is no closing `)'. */
3407 /* This is good for lambda expression capture-lists. */
3408 case CPP_OPEN_SQUARE
:
3411 case CPP_CLOSE_SQUARE
:
3412 if (!square_depth
--)
3417 /* This matches the processing in skip_to_end_of_statement. */
3422 case CPP_OPEN_BRACE
:
3425 case CPP_CLOSE_BRACE
:
3430 case CPP_OPEN_PAREN
:
3435 case CPP_CLOSE_PAREN
:
3436 if (!brace_depth
&& !paren_depth
--)
3439 cp_lexer_consume_token (parser
->lexer
);
3448 /* Consume the token. */
3449 cp_lexer_consume_token (parser
->lexer
);
3453 /* Consume tokens up to, and including, the next non-nested closing `)'.
3454 Returns 1 iff we found a closing `)'. RECOVERING is true, if we
3455 are doing error recovery. Returns -1 if OR_COMMA is true and we
3456 found an unnested token of that type. */
3459 cp_parser_skip_to_closing_parenthesis (cp_parser
*parser
,
3464 cpp_ttype ttype
= or_comma
? CPP_COMMA
: CPP_EOF
;
3465 return cp_parser_skip_to_closing_parenthesis_1 (parser
, recovering
,
3466 ttype
, consume_paren
);
3469 /* Consume tokens until we reach the end of the current statement.
3470 Normally, that will be just before consuming a `;'. However, if a
3471 non-nested `}' comes first, then we stop before consuming that. */
3474 cp_parser_skip_to_end_of_statement (cp_parser
* parser
)
3476 unsigned nesting_depth
= 0;
3478 /* Unwind generic function template scope if necessary. */
3479 if (parser
->fully_implicit_function_template_p
)
3480 finish_fully_implicit_template (parser
, /*member_decl_opt=*/0);
3484 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
3486 switch (token
->type
)
3489 case CPP_PRAGMA_EOL
:
3490 /* If we've run out of tokens, stop. */
3494 /* If the next token is a `;', we have reached the end of the
3500 case CPP_CLOSE_BRACE
:
3501 /* If this is a non-nested '}', stop before consuming it.
3502 That way, when confronted with something like:
3506 we stop before consuming the closing '}', even though we
3507 have not yet reached a `;'. */
3508 if (nesting_depth
== 0)
3511 /* If it is the closing '}' for a block that we have
3512 scanned, stop -- but only after consuming the token.
3518 we will stop after the body of the erroneously declared
3519 function, but before consuming the following `typedef'
3521 if (--nesting_depth
== 0)
3523 cp_lexer_consume_token (parser
->lexer
);
3528 case CPP_OPEN_BRACE
:
3536 /* Consume the token. */
3537 cp_lexer_consume_token (parser
->lexer
);
3541 /* This function is called at the end of a statement or declaration.
3542 If the next token is a semicolon, it is consumed; otherwise, error
3543 recovery is attempted. */
3546 cp_parser_consume_semicolon_at_end_of_statement (cp_parser
*parser
)
3548 /* Look for the trailing `;'. */
3549 if (!cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
))
3551 /* If there is additional (erroneous) input, skip to the end of
3553 cp_parser_skip_to_end_of_statement (parser
);
3554 /* If the next token is now a `;', consume it. */
3555 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
3556 cp_lexer_consume_token (parser
->lexer
);
3560 /* Skip tokens until we have consumed an entire block, or until we
3561 have consumed a non-nested `;'. */
3564 cp_parser_skip_to_end_of_block_or_statement (cp_parser
* parser
)
3566 int nesting_depth
= 0;
3568 /* Unwind generic function template scope if necessary. */
3569 if (parser
->fully_implicit_function_template_p
)
3570 finish_fully_implicit_template (parser
, /*member_decl_opt=*/0);
3572 while (nesting_depth
>= 0)
3574 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
3576 switch (token
->type
)
3579 case CPP_PRAGMA_EOL
:
3580 /* If we've run out of tokens, stop. */
3584 /* Stop if this is an unnested ';'. */
3589 case CPP_CLOSE_BRACE
:
3590 /* Stop if this is an unnested '}', or closes the outermost
3593 if (nesting_depth
< 0)
3599 case CPP_OPEN_BRACE
:
3608 /* Consume the token. */
3609 cp_lexer_consume_token (parser
->lexer
);
3613 /* Skip tokens until a non-nested closing curly brace is the next
3614 token, or there are no more tokens. Return true in the first case,
3618 cp_parser_skip_to_closing_brace (cp_parser
*parser
)
3620 unsigned nesting_depth
= 0;
3624 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
3626 switch (token
->type
)
3629 case CPP_PRAGMA_EOL
:
3630 /* If we've run out of tokens, stop. */
3633 case CPP_CLOSE_BRACE
:
3634 /* If the next token is a non-nested `}', then we have reached
3635 the end of the current block. */
3636 if (nesting_depth
-- == 0)
3640 case CPP_OPEN_BRACE
:
3641 /* If it the next token is a `{', then we are entering a new
3642 block. Consume the entire block. */
3650 /* Consume the token. */
3651 cp_lexer_consume_token (parser
->lexer
);
3655 /* Consume tokens until we reach the end of the pragma. The PRAGMA_TOK
3656 parameter is the PRAGMA token, allowing us to purge the entire pragma
3660 cp_parser_skip_to_pragma_eol (cp_parser
* parser
, cp_token
*pragma_tok
)
3664 parser
->lexer
->in_pragma
= false;
3667 token
= cp_lexer_consume_token (parser
->lexer
);
3668 while (token
->type
!= CPP_PRAGMA_EOL
&& token
->type
!= CPP_EOF
);
3670 /* Ensure that the pragma is not parsed again. */
3671 cp_lexer_purge_tokens_after (parser
->lexer
, pragma_tok
);
3674 /* Require pragma end of line, resyncing with it as necessary. The
3675 arguments are as for cp_parser_skip_to_pragma_eol. */
3678 cp_parser_require_pragma_eol (cp_parser
*parser
, cp_token
*pragma_tok
)
3680 parser
->lexer
->in_pragma
= false;
3681 if (!cp_parser_require (parser
, CPP_PRAGMA_EOL
, RT_PRAGMA_EOL
))
3682 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
3685 /* This is a simple wrapper around make_typename_type. When the id is
3686 an unresolved identifier node, we can provide a superior diagnostic
3687 using cp_parser_diagnose_invalid_type_name. */
3690 cp_parser_make_typename_type (cp_parser
*parser
, tree id
,
3691 location_t id_location
)
3694 if (identifier_p (id
))
3696 result
= make_typename_type (parser
->scope
, id
, typename_type
,
3697 /*complain=*/tf_none
);
3698 if (result
== error_mark_node
)
3699 cp_parser_diagnose_invalid_type_name (parser
, id
, id_location
);
3702 return make_typename_type (parser
->scope
, id
, typename_type
, tf_error
);
3705 /* This is a wrapper around the
3706 make_{pointer,ptrmem,reference}_declarator functions that decides
3707 which one to call based on the CODE and CLASS_TYPE arguments. The
3708 CODE argument should be one of the values returned by
3709 cp_parser_ptr_operator. ATTRIBUTES represent the attributes that
3710 appertain to the pointer or reference. */
3712 static cp_declarator
*
3713 cp_parser_make_indirect_declarator (enum tree_code code
, tree class_type
,
3714 cp_cv_quals cv_qualifiers
,
3715 cp_declarator
*target
,
3718 if (code
== ERROR_MARK
)
3719 return cp_error_declarator
;
3721 if (code
== INDIRECT_REF
)
3722 if (class_type
== NULL_TREE
)
3723 return make_pointer_declarator (cv_qualifiers
, target
, attributes
);
3725 return make_ptrmem_declarator (cv_qualifiers
, class_type
,
3726 target
, attributes
);
3727 else if (code
== ADDR_EXPR
&& class_type
== NULL_TREE
)
3728 return make_reference_declarator (cv_qualifiers
, target
,
3730 else if (code
== NON_LVALUE_EXPR
&& class_type
== NULL_TREE
)
3731 return make_reference_declarator (cv_qualifiers
, target
,
3736 /* Create a new C++ parser. */
3739 cp_parser_new (void)
3745 /* cp_lexer_new_main is called before doing GC allocation because
3746 cp_lexer_new_main might load a PCH file. */
3747 lexer
= cp_lexer_new_main ();
3749 /* Initialize the binops_by_token so that we can get the tree
3750 directly from the token. */
3751 for (i
= 0; i
< sizeof (binops
) / sizeof (binops
[0]); i
++)
3752 binops_by_token
[binops
[i
].token_type
] = binops
[i
];
3754 parser
= ggc_cleared_alloc
<cp_parser
> ();
3755 parser
->lexer
= lexer
;
3756 parser
->context
= cp_parser_context_new (NULL
);
3758 /* For now, we always accept GNU extensions. */
3759 parser
->allow_gnu_extensions_p
= 1;
3761 /* The `>' token is a greater-than operator, not the end of a
3763 parser
->greater_than_is_operator_p
= true;
3765 parser
->default_arg_ok_p
= true;
3767 /* We are not parsing a constant-expression. */
3768 parser
->integral_constant_expression_p
= false;
3769 parser
->allow_non_integral_constant_expression_p
= false;
3770 parser
->non_integral_constant_expression_p
= false;
3772 /* Local variable names are not forbidden. */
3773 parser
->local_variables_forbidden_p
= false;
3775 /* We are not processing an `extern "C"' declaration. */
3776 parser
->in_unbraced_linkage_specification_p
= false;
3778 /* We are not processing a declarator. */
3779 parser
->in_declarator_p
= false;
3781 /* We are not processing a template-argument-list. */
3782 parser
->in_template_argument_list_p
= false;
3784 /* We are not in an iteration statement. */
3785 parser
->in_statement
= 0;
3787 /* We are not in a switch statement. */
3788 parser
->in_switch_statement_p
= false;
3790 /* We are not parsing a type-id inside an expression. */
3791 parser
->in_type_id_in_expr_p
= false;
3793 /* Declarations aren't implicitly extern "C". */
3794 parser
->implicit_extern_c
= false;
3796 /* String literals should be translated to the execution character set. */
3797 parser
->translate_strings_p
= true;
3799 /* We are not parsing a function body. */
3800 parser
->in_function_body
= false;
3802 /* We can correct until told otherwise. */
3803 parser
->colon_corrects_to_scope_p
= true;
3805 /* The unparsed function queue is empty. */
3806 push_unparsed_function_queues (parser
);
3808 /* There are no classes being defined. */
3809 parser
->num_classes_being_defined
= 0;
3811 /* No template parameters apply. */
3812 parser
->num_template_parameter_lists
= 0;
3814 /* Special parsing data structures. */
3815 parser
->omp_declare_simd
= NULL
;
3816 parser
->cilk_simd_fn_info
= NULL
;
3817 parser
->oacc_routine
= NULL
;
3819 /* Not declaring an implicit function template. */
3820 parser
->auto_is_implicit_function_template_parm_p
= false;
3821 parser
->fully_implicit_function_template_p
= false;
3822 parser
->implicit_template_parms
= 0;
3823 parser
->implicit_template_scope
= 0;
3825 /* Allow constrained-type-specifiers. */
3826 parser
->prevent_constrained_type_specifiers
= 0;
3831 /* Create a cp_lexer structure which will emit the tokens in CACHE
3832 and push it onto the parser's lexer stack. This is used for delayed
3833 parsing of in-class method bodies and default arguments, and should
3834 not be confused with tentative parsing. */
3836 cp_parser_push_lexer_for_tokens (cp_parser
*parser
, cp_token_cache
*cache
)
3838 cp_lexer
*lexer
= cp_lexer_new_from_tokens (cache
);
3839 lexer
->next
= parser
->lexer
;
3840 parser
->lexer
= lexer
;
3842 /* Move the current source position to that of the first token in the
3844 cp_lexer_set_source_position_from_token (lexer
->next_token
);
3847 /* Pop the top lexer off the parser stack. This is never used for the
3848 "main" lexer, only for those pushed by cp_parser_push_lexer_for_tokens. */
3850 cp_parser_pop_lexer (cp_parser
*parser
)
3852 cp_lexer
*lexer
= parser
->lexer
;
3853 parser
->lexer
= lexer
->next
;
3854 cp_lexer_destroy (lexer
);
3856 /* Put the current source position back where it was before this
3857 lexer was pushed. */
3858 cp_lexer_set_source_position_from_token (parser
->lexer
->next_token
);
3861 /* Lexical conventions [gram.lex] */
3863 /* Parse an identifier. Returns an IDENTIFIER_NODE representing the
3867 cp_parser_identifier (cp_parser
* parser
)
3871 /* Look for the identifier. */
3872 token
= cp_parser_require (parser
, CPP_NAME
, RT_NAME
);
3873 /* Return the value. */
3875 return cp_expr (token
->u
.value
, token
->location
);
3877 return error_mark_node
;
3880 /* Parse a sequence of adjacent string constants. Returns a
3881 TREE_STRING representing the combined, nul-terminated string
3882 constant. If TRANSLATE is true, translate the string to the
3883 execution character set. If WIDE_OK is true, a wide string is
3886 C++98 [lex.string] says that if a narrow string literal token is
3887 adjacent to a wide string literal token, the behavior is undefined.
3888 However, C99 6.4.5p4 says that this results in a wide string literal.
3889 We follow C99 here, for consistency with the C front end.
3891 This code is largely lifted from lex_string() in c-lex.c.
3893 FUTURE: ObjC++ will need to handle @-strings here. */
3895 cp_parser_string_literal (cp_parser
*parser
, bool translate
, bool wide_ok
,
3896 bool lookup_udlit
= true)
3900 struct obstack str_ob
;
3901 cpp_string str
, istr
, *strs
;
3903 enum cpp_ttype type
, curr_type
;
3904 int have_suffix_p
= 0;
3906 tree suffix_id
= NULL_TREE
;
3907 bool curr_tok_is_userdef_p
= false;
3909 tok
= cp_lexer_peek_token (parser
->lexer
);
3910 if (!cp_parser_is_string_literal (tok
))
3912 cp_parser_error (parser
, "expected string-literal");
3913 return error_mark_node
;
3916 location_t loc
= tok
->location
;
3918 if (cpp_userdef_string_p (tok
->type
))
3920 string_tree
= USERDEF_LITERAL_VALUE (tok
->u
.value
);
3921 curr_type
= cpp_userdef_string_remove_type (tok
->type
);
3922 curr_tok_is_userdef_p
= true;
3926 string_tree
= tok
->u
.value
;
3927 curr_type
= tok
->type
;
3931 /* Try to avoid the overhead of creating and destroying an obstack
3932 for the common case of just one string. */
3933 if (!cp_parser_is_string_literal
3934 (cp_lexer_peek_nth_token (parser
->lexer
, 2)))
3936 cp_lexer_consume_token (parser
->lexer
);
3938 str
.text
= (const unsigned char *)TREE_STRING_POINTER (string_tree
);
3939 str
.len
= TREE_STRING_LENGTH (string_tree
);
3942 if (curr_tok_is_userdef_p
)
3944 suffix_id
= USERDEF_LITERAL_SUFFIX_ID (tok
->u
.value
);
3946 curr_type
= cpp_userdef_string_remove_type (tok
->type
);
3949 curr_type
= tok
->type
;
3955 location_t last_tok_loc
= tok
->location
;
3956 gcc_obstack_init (&str_ob
);
3961 cp_lexer_consume_token (parser
->lexer
);
3963 str
.text
= (const unsigned char *)TREE_STRING_POINTER (string_tree
);
3964 str
.len
= TREE_STRING_LENGTH (string_tree
);
3966 if (curr_tok_is_userdef_p
)
3968 tree curr_suffix_id
= USERDEF_LITERAL_SUFFIX_ID (tok
->u
.value
);
3969 if (have_suffix_p
== 0)
3971 suffix_id
= curr_suffix_id
;
3974 else if (have_suffix_p
== 1
3975 && curr_suffix_id
!= suffix_id
)
3977 error ("inconsistent user-defined literal suffixes"
3978 " %qD and %qD in string literal",
3979 suffix_id
, curr_suffix_id
);
3982 curr_type
= cpp_userdef_string_remove_type (tok
->type
);
3985 curr_type
= tok
->type
;
3987 if (type
!= curr_type
)
3989 if (type
== CPP_STRING
)
3991 else if (curr_type
!= CPP_STRING
)
3993 rich_location
rich_loc (line_table
, tok
->location
);
3994 rich_loc
.add_range (last_tok_loc
, false);
3995 error_at_rich_loc (&rich_loc
,
3996 "unsupported non-standard concatenation "
3997 "of string literals");
4001 obstack_grow (&str_ob
, &str
, sizeof (cpp_string
));
4003 last_tok_loc
= tok
->location
;
4005 tok
= cp_lexer_peek_token (parser
->lexer
);
4006 if (cpp_userdef_string_p (tok
->type
))
4008 string_tree
= USERDEF_LITERAL_VALUE (tok
->u
.value
);
4009 curr_type
= cpp_userdef_string_remove_type (tok
->type
);
4010 curr_tok_is_userdef_p
= true;
4014 string_tree
= tok
->u
.value
;
4015 curr_type
= tok
->type
;
4016 curr_tok_is_userdef_p
= false;
4019 while (cp_parser_is_string_literal (tok
));
4021 /* A string literal built by concatenation has its caret=start at
4022 the start of the initial string, and its finish at the finish of
4023 the final string literal. */
4024 loc
= make_location (loc
, loc
, get_finish (last_tok_loc
));
4026 strs
= (cpp_string
*) obstack_finish (&str_ob
);
4029 if (type
!= CPP_STRING
&& !wide_ok
)
4031 cp_parser_error (parser
, "a wide string is invalid in this context");
4035 if ((translate
? cpp_interpret_string
: cpp_interpret_string_notranslate
)
4036 (parse_in
, strs
, count
, &istr
, type
))
4038 value
= build_string (istr
.len
, (const char *)istr
.text
);
4039 free (CONST_CAST (unsigned char *, istr
.text
));
4045 case CPP_UTF8STRING
:
4046 TREE_TYPE (value
) = char_array_type_node
;
4049 TREE_TYPE (value
) = char16_array_type_node
;
4052 TREE_TYPE (value
) = char32_array_type_node
;
4055 TREE_TYPE (value
) = wchar_array_type_node
;
4059 value
= fix_string_type (value
);
4063 tree literal
= build_userdef_literal (suffix_id
, value
,
4064 OT_NONE
, NULL_TREE
);
4066 value
= cp_parser_userdef_string_literal (literal
);
4072 /* cpp_interpret_string has issued an error. */
4073 value
= error_mark_node
;
4076 obstack_free (&str_ob
, 0);
4078 return cp_expr (value
, loc
);
4081 /* Look up a literal operator with the name and the exact arguments. */
4084 lookup_literal_operator (tree name
, vec
<tree
, va_gc
> *args
)
4087 decl
= lookup_name (name
);
4088 if (!decl
|| !is_overloaded_fn (decl
))
4089 return error_mark_node
;
4091 for (lkp_iterator
iter (decl
); iter
; ++iter
)
4096 tree parmtypes
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
4097 if (parmtypes
!= NULL_TREE
)
4099 for (ix
= 0; ix
< vec_safe_length (args
) && parmtypes
!= NULL_TREE
;
4100 ++ix
, parmtypes
= TREE_CHAIN (parmtypes
))
4102 tree tparm
= TREE_VALUE (parmtypes
);
4103 tree targ
= TREE_TYPE ((*args
)[ix
]);
4104 bool ptr
= TYPE_PTR_P (tparm
);
4105 bool arr
= TREE_CODE (targ
) == ARRAY_TYPE
;
4106 if ((ptr
|| arr
|| !same_type_p (tparm
, targ
))
4108 || !same_type_p (TREE_TYPE (tparm
),
4113 && ix
== vec_safe_length (args
)
4114 /* May be this should be sufficient_parms_p instead,
4115 depending on how exactly should user-defined literals
4116 work in presence of default arguments on the literal
4117 operator parameters. */
4118 && parmtypes
== void_list_node
)
4123 return error_mark_node
;
4126 /* Parse a user-defined char constant. Returns a call to a user-defined
4127 literal operator taking the character as an argument. */
4130 cp_parser_userdef_char_literal (cp_parser
*parser
)
4132 cp_token
*token
= cp_lexer_consume_token (parser
->lexer
);
4133 tree literal
= token
->u
.value
;
4134 tree suffix_id
= USERDEF_LITERAL_SUFFIX_ID (literal
);
4135 tree value
= USERDEF_LITERAL_VALUE (literal
);
4136 tree name
= cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id
));
4139 /* Build up a call to the user-defined operator */
4140 /* Lookup the name we got back from the id-expression. */
4141 vec
<tree
, va_gc
> *args
= make_tree_vector ();
4142 vec_safe_push (args
, value
);
4143 decl
= lookup_literal_operator (name
, args
);
4144 if (!decl
|| decl
== error_mark_node
)
4146 error ("unable to find character literal operator %qD with %qT argument",
4147 name
, TREE_TYPE (value
));
4148 release_tree_vector (args
);
4149 return error_mark_node
;
4151 result
= finish_call_expr (decl
, &args
, false, true, tf_warning_or_error
);
4152 release_tree_vector (args
);
4156 /* A subroutine of cp_parser_userdef_numeric_literal to
4157 create a char... template parameter pack from a string node. */
4160 make_char_string_pack (tree value
)
4163 tree argpack
= make_node (NONTYPE_ARGUMENT_PACK
);
4164 const char *str
= TREE_STRING_POINTER (value
);
4165 int i
, len
= TREE_STRING_LENGTH (value
) - 1;
4166 tree argvec
= make_tree_vec (1);
4168 /* Fill in CHARVEC with all of the parameters. */
4169 charvec
= make_tree_vec (len
);
4170 for (i
= 0; i
< len
; ++i
)
4171 TREE_VEC_ELT (charvec
, i
) = build_int_cst (char_type_node
, str
[i
]);
4173 /* Build the argument packs. */
4174 SET_ARGUMENT_PACK_ARGS (argpack
, charvec
);
4176 TREE_VEC_ELT (argvec
, 0) = argpack
;
4181 /* A subroutine of cp_parser_userdef_numeric_literal to
4182 create a char... template parameter pack from a string node. */
4185 make_string_pack (tree value
)
4188 tree argpack
= make_node (NONTYPE_ARGUMENT_PACK
);
4189 const unsigned char *str
4190 = (const unsigned char *) TREE_STRING_POINTER (value
);
4191 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (value
))));
4192 int len
= TREE_STRING_LENGTH (value
) / sz
- 1;
4193 tree argvec
= make_tree_vec (2);
4195 tree str_char_type_node
= TREE_TYPE (TREE_TYPE (value
));
4196 str_char_type_node
= TYPE_MAIN_VARIANT (str_char_type_node
);
4198 /* First template parm is character type. */
4199 TREE_VEC_ELT (argvec
, 0) = str_char_type_node
;
4201 /* Fill in CHARVEC with all of the parameters. */
4202 charvec
= make_tree_vec (len
);
4203 for (int i
= 0; i
< len
; ++i
)
4204 TREE_VEC_ELT (charvec
, i
)
4205 = double_int_to_tree (str_char_type_node
,
4206 double_int::from_buffer (str
+ i
* sz
, sz
));
4208 /* Build the argument packs. */
4209 SET_ARGUMENT_PACK_ARGS (argpack
, charvec
);
4211 TREE_VEC_ELT (argvec
, 1) = argpack
;
4216 /* Parse a user-defined numeric constant. returns a call to a user-defined
4217 literal operator. */
4220 cp_parser_userdef_numeric_literal (cp_parser
*parser
)
4222 cp_token
*token
= cp_lexer_consume_token (parser
->lexer
);
4223 tree literal
= token
->u
.value
;
4224 tree suffix_id
= USERDEF_LITERAL_SUFFIX_ID (literal
);
4225 tree value
= USERDEF_LITERAL_VALUE (literal
);
4226 int overflow
= USERDEF_LITERAL_OVERFLOW (literal
);
4227 tree num_string
= USERDEF_LITERAL_NUM_STRING (literal
);
4228 tree name
= cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id
));
4230 vec
<tree
, va_gc
> *args
;
4232 /* Look for a literal operator taking the exact type of numeric argument
4233 as the literal value. */
4234 args
= make_tree_vector ();
4235 vec_safe_push (args
, value
);
4236 decl
= lookup_literal_operator (name
, args
);
4237 if (decl
&& decl
!= error_mark_node
)
4239 result
= finish_call_expr (decl
, &args
, false, true,
4240 tf_warning_or_error
);
4242 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
&& overflow
> 0)
4244 warning_at (token
->location
, OPT_Woverflow
,
4245 "integer literal exceeds range of %qT type",
4246 long_long_unsigned_type_node
);
4251 warning_at (token
->location
, OPT_Woverflow
,
4252 "floating literal exceeds range of %qT type",
4253 long_double_type_node
);
4254 else if (overflow
< 0)
4255 warning_at (token
->location
, OPT_Woverflow
,
4256 "floating literal truncated to zero");
4259 release_tree_vector (args
);
4262 release_tree_vector (args
);
4264 /* If the numeric argument didn't work, look for a raw literal
4265 operator taking a const char* argument consisting of the number
4266 in string format. */
4267 args
= make_tree_vector ();
4268 vec_safe_push (args
, num_string
);
4269 decl
= lookup_literal_operator (name
, args
);
4270 if (decl
&& decl
!= error_mark_node
)
4272 result
= finish_call_expr (decl
, &args
, false, true,
4273 tf_warning_or_error
);
4274 release_tree_vector (args
);
4277 release_tree_vector (args
);
4279 /* If the raw literal didn't work, look for a non-type template
4280 function with parameter pack char.... Call the function with
4281 template parameter characters representing the number. */
4282 args
= make_tree_vector ();
4283 decl
= lookup_literal_operator (name
, args
);
4284 if (decl
&& decl
!= error_mark_node
)
4286 tree tmpl_args
= make_char_string_pack (num_string
);
4287 decl
= lookup_template_function (decl
, tmpl_args
);
4288 result
= finish_call_expr (decl
, &args
, false, true,
4289 tf_warning_or_error
);
4290 release_tree_vector (args
);
4294 release_tree_vector (args
);
4296 error ("unable to find numeric literal operator %qD", name
);
4297 if (!cpp_get_options (parse_in
)->ext_numeric_literals
)
4298 inform (token
->location
, "use -std=gnu++11 or -fext-numeric-literals "
4299 "to enable more built-in suffixes");
4300 return error_mark_node
;
4303 /* Parse a user-defined string constant. Returns a call to a user-defined
4304 literal operator taking a character pointer and the length of the string
4308 cp_parser_userdef_string_literal (tree literal
)
4310 tree suffix_id
= USERDEF_LITERAL_SUFFIX_ID (literal
);
4311 tree name
= cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id
));
4312 tree value
= USERDEF_LITERAL_VALUE (literal
);
4313 int len
= TREE_STRING_LENGTH (value
)
4314 / TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (value
)))) - 1;
4316 vec
<tree
, va_gc
> *args
;
4318 /* Build up a call to the user-defined operator. */
4319 /* Lookup the name we got back from the id-expression. */
4320 args
= make_tree_vector ();
4321 vec_safe_push (args
, value
);
4322 vec_safe_push (args
, build_int_cst (size_type_node
, len
));
4323 decl
= lookup_literal_operator (name
, args
);
4325 if (decl
&& decl
!= error_mark_node
)
4327 result
= finish_call_expr (decl
, &args
, false, true,
4328 tf_warning_or_error
);
4329 release_tree_vector (args
);
4332 release_tree_vector (args
);
4334 /* Look for a template function with typename parameter CharT
4335 and parameter pack CharT... Call the function with
4336 template parameter characters representing the string. */
4337 args
= make_tree_vector ();
4338 decl
= lookup_literal_operator (name
, args
);
4339 if (decl
&& decl
!= error_mark_node
)
4341 tree tmpl_args
= make_string_pack (value
);
4342 decl
= lookup_template_function (decl
, tmpl_args
);
4343 result
= finish_call_expr (decl
, &args
, false, true,
4344 tf_warning_or_error
);
4345 release_tree_vector (args
);
4348 release_tree_vector (args
);
4350 error ("unable to find string literal operator %qD with %qT, %qT arguments",
4351 name
, TREE_TYPE (value
), size_type_node
);
4352 return error_mark_node
;
4356 /* Basic concepts [gram.basic] */
4358 /* Parse a translation-unit.
4361 declaration-seq [opt]
4363 Returns TRUE if all went well. */
4366 cp_parser_translation_unit (cp_parser
* parser
)
4368 /* The address of the first non-permanent object on the declarator
4370 static void *declarator_obstack_base
;
4374 /* Create the declarator obstack, if necessary. */
4375 if (!cp_error_declarator
)
4377 gcc_obstack_init (&declarator_obstack
);
4378 /* Create the error declarator. */
4379 cp_error_declarator
= make_declarator (cdk_error
);
4380 /* Create the empty parameter list. */
4381 no_parameters
= make_parameter_declarator (NULL
, NULL
, NULL_TREE
);
4382 /* Remember where the base of the declarator obstack lies. */
4383 declarator_obstack_base
= obstack_next_free (&declarator_obstack
);
4386 cp_parser_declaration_seq_opt (parser
);
4388 /* If there are no tokens left then all went well. */
4389 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EOF
))
4391 /* Get rid of the token array; we don't need it any more. */
4392 cp_lexer_destroy (parser
->lexer
);
4393 parser
->lexer
= NULL
;
4395 /* This file might have been a context that's implicitly extern
4396 "C". If so, pop the lang context. (Only relevant for PCH.) */
4397 if (parser
->implicit_extern_c
)
4399 pop_lang_context ();
4400 parser
->implicit_extern_c
= false;
4404 finish_translation_unit ();
4410 cp_parser_error (parser
, "expected declaration");
4414 /* Make sure the declarator obstack was fully cleaned up. */
4415 gcc_assert (obstack_next_free (&declarator_obstack
)
4416 == declarator_obstack_base
);
4418 /* All went well. */
4422 /* Return the appropriate tsubst flags for parsing, possibly in N3276
4423 decltype context. */
4425 static inline tsubst_flags_t
4426 complain_flags (bool decltype_p
)
4428 tsubst_flags_t complain
= tf_warning_or_error
;
4430 complain
|= tf_decltype
;
4434 /* We're about to parse a collection of statements. If we're currently
4435 parsing tentatively, set up a firewall so that any nested
4436 cp_parser_commit_to_tentative_parse won't affect the current context. */
4438 static cp_token_position
4439 cp_parser_start_tentative_firewall (cp_parser
*parser
)
4441 if (!cp_parser_uncommitted_to_tentative_parse_p (parser
))
4444 cp_parser_parse_tentatively (parser
);
4445 cp_parser_commit_to_topmost_tentative_parse (parser
);
4446 return cp_lexer_token_position (parser
->lexer
, false);
4449 /* We've finished parsing the collection of statements. Wrap up the
4450 firewall and replace the relevant tokens with the parsed form. */
4453 cp_parser_end_tentative_firewall (cp_parser
*parser
, cp_token_position start
,
4459 /* Finish the firewall level. */
4460 cp_parser_parse_definitely (parser
);
4461 /* And remember the result of the parse for when we try again. */
4462 cp_token
*token
= cp_lexer_token_at (parser
->lexer
, start
);
4463 token
->type
= CPP_PREPARSED_EXPR
;
4464 token
->u
.value
= expr
;
4465 token
->keyword
= RID_MAX
;
4466 cp_lexer_purge_tokens_after (parser
->lexer
, start
);
4469 /* Like the above functions, but let the user modify the tokens. Used by
4470 CPP_DECLTYPE and CPP_TEMPLATE_ID, where we are saving the side-effects for
4471 later parses, so it makes sense to localize the effects of
4472 cp_parser_commit_to_tentative_parse. */
4474 struct tentative_firewall
4479 tentative_firewall (cp_parser
*p
): parser(p
)
4481 /* If we're currently parsing tentatively, start a committed level as a
4482 firewall and then an inner tentative parse. */
4483 if ((set
= cp_parser_uncommitted_to_tentative_parse_p (parser
)))
4485 cp_parser_parse_tentatively (parser
);
4486 cp_parser_commit_to_topmost_tentative_parse (parser
);
4487 cp_parser_parse_tentatively (parser
);
4491 ~tentative_firewall()
4495 /* Finish the inner tentative parse and the firewall, propagating any
4496 uncommitted error state to the outer tentative parse. */
4497 bool err
= cp_parser_error_occurred (parser
);
4498 cp_parser_parse_definitely (parser
);
4499 cp_parser_parse_definitely (parser
);
4501 cp_parser_simulate_error (parser
);
4506 /* Parse a GNU statement-expression, i.e. ({ stmts }), except for the
4507 enclosing parentheses. */
4510 cp_parser_statement_expr (cp_parser
*parser
)
4512 cp_token_position start
= cp_parser_start_tentative_firewall (parser
);
4514 /* Consume the '('. */
4515 location_t start_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
4516 cp_lexer_consume_token (parser
->lexer
);
4517 /* Start the statement-expression. */
4518 tree expr
= begin_stmt_expr ();
4519 /* Parse the compound-statement. */
4520 cp_parser_compound_statement (parser
, expr
, BCS_NORMAL
, false);
4522 expr
= finish_stmt_expr (expr
, false);
4523 /* Consume the ')'. */
4524 location_t finish_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
4525 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
4526 cp_parser_skip_to_end_of_statement (parser
);
4528 cp_parser_end_tentative_firewall (parser
, start
, expr
);
4529 location_t combined_loc
= make_location (start_loc
, start_loc
, finish_loc
);
4530 return cp_expr (expr
, combined_loc
);
4533 /* Expressions [gram.expr] */
4535 /* Parse a fold-operator.
4538 - * / % ^ & | = < > << >>
4539 = -= *= /= %= ^= &= |= <<= >>=
4540 == != <= >= && || , .* ->*
4542 This returns the tree code corresponding to the matched operator
4543 as an int. When the current token matches a compound assignment
4544 opertor, the resulting tree code is the negative value of the
4545 non-assignment operator. */
4548 cp_parser_fold_operator (cp_token
*token
)
4550 switch (token
->type
)
4552 case CPP_PLUS
: return PLUS_EXPR
;
4553 case CPP_MINUS
: return MINUS_EXPR
;
4554 case CPP_MULT
: return MULT_EXPR
;
4555 case CPP_DIV
: return TRUNC_DIV_EXPR
;
4556 case CPP_MOD
: return TRUNC_MOD_EXPR
;
4557 case CPP_XOR
: return BIT_XOR_EXPR
;
4558 case CPP_AND
: return BIT_AND_EXPR
;
4559 case CPP_OR
: return BIT_IOR_EXPR
;
4560 case CPP_LSHIFT
: return LSHIFT_EXPR
;
4561 case CPP_RSHIFT
: return RSHIFT_EXPR
;
4563 case CPP_EQ
: return -NOP_EXPR
;
4564 case CPP_PLUS_EQ
: return -PLUS_EXPR
;
4565 case CPP_MINUS_EQ
: return -MINUS_EXPR
;
4566 case CPP_MULT_EQ
: return -MULT_EXPR
;
4567 case CPP_DIV_EQ
: return -TRUNC_DIV_EXPR
;
4568 case CPP_MOD_EQ
: return -TRUNC_MOD_EXPR
;
4569 case CPP_XOR_EQ
: return -BIT_XOR_EXPR
;
4570 case CPP_AND_EQ
: return -BIT_AND_EXPR
;
4571 case CPP_OR_EQ
: return -BIT_IOR_EXPR
;
4572 case CPP_LSHIFT_EQ
: return -LSHIFT_EXPR
;
4573 case CPP_RSHIFT_EQ
: return -RSHIFT_EXPR
;
4575 case CPP_EQ_EQ
: return EQ_EXPR
;
4576 case CPP_NOT_EQ
: return NE_EXPR
;
4577 case CPP_LESS
: return LT_EXPR
;
4578 case CPP_GREATER
: return GT_EXPR
;
4579 case CPP_LESS_EQ
: return LE_EXPR
;
4580 case CPP_GREATER_EQ
: return GE_EXPR
;
4582 case CPP_AND_AND
: return TRUTH_ANDIF_EXPR
;
4583 case CPP_OR_OR
: return TRUTH_ORIF_EXPR
;
4585 case CPP_COMMA
: return COMPOUND_EXPR
;
4587 case CPP_DOT_STAR
: return DOTSTAR_EXPR
;
4588 case CPP_DEREF_STAR
: return MEMBER_REF
;
4590 default: return ERROR_MARK
;
4594 /* Returns true if CODE indicates a binary expression, which is not allowed in
4595 the LHS of a fold-expression. More codes will need to be added to use this
4596 function in other contexts. */
4599 is_binary_op (tree_code code
)
4604 case POINTER_PLUS_EXPR
:
4607 case TRUNC_DIV_EXPR
:
4608 case TRUNC_MOD_EXPR
:
4624 case TRUTH_ANDIF_EXPR
:
4625 case TRUTH_ORIF_EXPR
:
4638 /* If the next token is a suitable fold operator, consume it and return as
4639 the function above. */
4642 cp_parser_fold_operator (cp_parser
*parser
)
4644 cp_token
* token
= cp_lexer_peek_token (parser
->lexer
);
4645 int code
= cp_parser_fold_operator (token
);
4646 if (code
!= ERROR_MARK
)
4647 cp_lexer_consume_token (parser
->lexer
);
4651 /* Parse a fold-expression.
4654 ( ... folding-operator cast-expression)
4655 ( cast-expression folding-operator ... )
4656 ( cast-expression folding operator ... folding-operator cast-expression)
4658 Note that the '(' and ')' are matched in primary expression. */
4661 cp_parser_fold_expression (cp_parser
*parser
, tree expr1
)
4666 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
4668 cp_lexer_consume_token (parser
->lexer
);
4669 int op
= cp_parser_fold_operator (parser
);
4670 if (op
== ERROR_MARK
)
4672 cp_parser_error (parser
, "expected binary operator");
4673 return error_mark_node
;
4676 tree expr
= cp_parser_cast_expression (parser
, false, false,
4678 if (expr
== error_mark_node
)
4679 return error_mark_node
;
4680 return finish_left_unary_fold_expr (expr
, op
);
4683 const cp_token
* token
= cp_lexer_peek_token (parser
->lexer
);
4684 int op
= cp_parser_fold_operator (parser
);
4685 if (op
== ERROR_MARK
)
4687 cp_parser_error (parser
, "expected binary operator");
4688 return error_mark_node
;
4691 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_ELLIPSIS
))
4693 cp_parser_error (parser
, "expected ...");
4694 return error_mark_node
;
4696 cp_lexer_consume_token (parser
->lexer
);
4698 /* The operands of a fold-expression are cast-expressions, so binary or
4699 conditional expressions are not allowed. We check this here to avoid
4700 tentative parsing. */
4701 if (EXPR_P (expr1
) && TREE_NO_WARNING (expr1
))
4702 /* OK, the expression was parenthesized. */;
4703 else if (is_binary_op (TREE_CODE (expr1
)))
4704 error_at (location_of (expr1
),
4705 "binary expression in operand of fold-expression");
4706 else if (TREE_CODE (expr1
) == COND_EXPR
)
4707 error_at (location_of (expr1
),
4708 "conditional expression in operand of fold-expression");
4711 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_PAREN
))
4712 return finish_right_unary_fold_expr (expr1
, op
);
4714 if (cp_lexer_next_token_is_not (parser
->lexer
, token
->type
))
4716 cp_parser_error (parser
, "mismatched operator in fold-expression");
4717 return error_mark_node
;
4719 cp_lexer_consume_token (parser
->lexer
);
4721 // Binary left or right fold.
4722 tree expr2
= cp_parser_cast_expression (parser
, false, false, false, &pidk
);
4723 if (expr2
== error_mark_node
)
4724 return error_mark_node
;
4725 return finish_binary_fold_expr (expr1
, expr2
, op
);
4728 /* Parse a primary-expression.
4735 lambda-expression (C++11)
4740 ( compound-statement )
4741 __builtin_va_arg ( assignment-expression , type-id )
4742 __builtin_offsetof ( type-id , offsetof-expression )
4745 __has_nothrow_assign ( type-id )
4746 __has_nothrow_constructor ( type-id )
4747 __has_nothrow_copy ( type-id )
4748 __has_trivial_assign ( type-id )
4749 __has_trivial_constructor ( type-id )
4750 __has_trivial_copy ( type-id )
4751 __has_trivial_destructor ( type-id )
4752 __has_virtual_destructor ( type-id )
4753 __is_abstract ( type-id )
4754 __is_base_of ( type-id , type-id )
4755 __is_class ( type-id )
4756 __is_empty ( type-id )
4757 __is_enum ( type-id )
4758 __is_final ( type-id )
4759 __is_literal_type ( type-id )
4760 __is_pod ( type-id )
4761 __is_polymorphic ( type-id )
4762 __is_std_layout ( type-id )
4763 __is_trivial ( type-id )
4764 __is_union ( type-id )
4766 Objective-C++ Extension:
4774 ADDRESS_P is true iff this expression was immediately preceded by
4775 "&" and therefore might denote a pointer-to-member. CAST_P is true
4776 iff this expression is the target of a cast. TEMPLATE_ARG_P is
4777 true iff this expression is a template argument.
4779 Returns a representation of the expression. Upon return, *IDK
4780 indicates what kind of id-expression (if any) was present. */
4783 cp_parser_primary_expression (cp_parser
*parser
,
4786 bool template_arg_p
,
4790 cp_token
*token
= NULL
;
4792 /* Assume the primary expression is not an id-expression. */
4793 *idk
= CP_ID_KIND_NONE
;
4795 /* Peek at the next token. */
4796 token
= cp_lexer_peek_token (parser
->lexer
);
4797 switch ((int) token
->type
)
4806 user-defined-literal */
4813 case CPP_PREPARSED_EXPR
:
4814 if (TREE_CODE (token
->u
.value
) == USERDEF_LITERAL
)
4815 return cp_parser_userdef_numeric_literal (parser
);
4816 token
= cp_lexer_consume_token (parser
->lexer
);
4817 if (TREE_CODE (token
->u
.value
) == FIXED_CST
)
4819 error_at (token
->location
,
4820 "fixed-point types not supported in C++");
4821 return error_mark_node
;
4823 /* Floating-point literals are only allowed in an integral
4824 constant expression if they are cast to an integral or
4825 enumeration type. */
4826 if (TREE_CODE (token
->u
.value
) == REAL_CST
4827 && parser
->integral_constant_expression_p
4830 /* CAST_P will be set even in invalid code like "int(2.7 +
4831 ...)". Therefore, we have to check that the next token
4832 is sure to end the cast. */
4835 cp_token
*next_token
;
4837 next_token
= cp_lexer_peek_token (parser
->lexer
);
4838 if (/* The comma at the end of an
4839 enumerator-definition. */
4840 next_token
->type
!= CPP_COMMA
4841 /* The curly brace at the end of an enum-specifier. */
4842 && next_token
->type
!= CPP_CLOSE_BRACE
4843 /* The end of a statement. */
4844 && next_token
->type
!= CPP_SEMICOLON
4845 /* The end of the cast-expression. */
4846 && next_token
->type
!= CPP_CLOSE_PAREN
4847 /* The end of an array bound. */
4848 && next_token
->type
!= CPP_CLOSE_SQUARE
4849 /* The closing ">" in a template-argument-list. */
4850 && (next_token
->type
!= CPP_GREATER
4851 || parser
->greater_than_is_operator_p
)
4852 /* C++0x only: A ">>" treated like two ">" tokens,
4853 in a template-argument-list. */
4854 && (next_token
->type
!= CPP_RSHIFT
4855 || (cxx_dialect
== cxx98
)
4856 || parser
->greater_than_is_operator_p
))
4860 /* If we are within a cast, then the constraint that the
4861 cast is to an integral or enumeration type will be
4862 checked at that point. If we are not within a cast, then
4863 this code is invalid. */
4865 cp_parser_non_integral_constant_expression (parser
, NIC_FLOAT
);
4867 return cp_expr (token
->u
.value
, token
->location
);
4869 case CPP_CHAR_USERDEF
:
4870 case CPP_CHAR16_USERDEF
:
4871 case CPP_CHAR32_USERDEF
:
4872 case CPP_WCHAR_USERDEF
:
4873 case CPP_UTF8CHAR_USERDEF
:
4874 return cp_parser_userdef_char_literal (parser
);
4880 case CPP_UTF8STRING
:
4881 case CPP_STRING_USERDEF
:
4882 case CPP_STRING16_USERDEF
:
4883 case CPP_STRING32_USERDEF
:
4884 case CPP_WSTRING_USERDEF
:
4885 case CPP_UTF8STRING_USERDEF
:
4886 /* ??? Should wide strings be allowed when parser->translate_strings_p
4887 is false (i.e. in attributes)? If not, we can kill the third
4888 argument to cp_parser_string_literal. */
4889 return cp_parser_string_literal (parser
,
4890 parser
->translate_strings_p
,
4893 case CPP_OPEN_PAREN
:
4894 /* If we see `( { ' then we are looking at the beginning of
4895 a GNU statement-expression. */
4896 if (cp_parser_allow_gnu_extensions_p (parser
)
4897 && cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_OPEN_BRACE
))
4899 /* Statement-expressions are not allowed by the standard. */
4900 pedwarn (token
->location
, OPT_Wpedantic
,
4901 "ISO C++ forbids braced-groups within expressions");
4903 /* And they're not allowed outside of a function-body; you
4904 cannot, for example, write:
4906 int i = ({ int j = 3; j + 1; });
4908 at class or namespace scope. */
4909 if (!parser
->in_function_body
4910 || parser
->in_template_argument_list_p
)
4912 error_at (token
->location
,
4913 "statement-expressions are not allowed outside "
4914 "functions nor in template-argument lists");
4915 cp_parser_skip_to_end_of_block_or_statement (parser
);
4916 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_PAREN
))
4917 cp_lexer_consume_token (parser
->lexer
);
4918 return error_mark_node
;
4921 return cp_parser_statement_expr (parser
);
4923 /* Otherwise it's a normal parenthesized expression. */
4926 bool saved_greater_than_is_operator_p
;
4928 location_t open_paren_loc
= token
->location
;
4930 /* Consume the `('. */
4931 cp_lexer_consume_token (parser
->lexer
);
4932 /* Within a parenthesized expression, a `>' token is always
4933 the greater-than operator. */
4934 saved_greater_than_is_operator_p
4935 = parser
->greater_than_is_operator_p
;
4936 parser
->greater_than_is_operator_p
= true;
4938 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
4939 /* Left fold expression. */
4942 /* Parse the parenthesized expression. */
4943 expr
= cp_parser_expression (parser
, idk
, cast_p
, decltype_p
);
4945 token
= cp_lexer_peek_token (parser
->lexer
);
4946 if (token
->type
== CPP_ELLIPSIS
|| cp_parser_fold_operator (token
))
4948 expr
= cp_parser_fold_expression (parser
, expr
);
4949 if (expr
!= error_mark_node
4950 && cxx_dialect
< cxx1z
4951 && !in_system_header_at (input_location
))
4952 pedwarn (input_location
, 0, "fold-expressions only available "
4953 "with -std=c++1z or -std=gnu++1z");
4956 /* Let the front end know that this expression was
4957 enclosed in parentheses. This matters in case, for
4958 example, the expression is of the form `A::B', since
4959 `&A::B' might be a pointer-to-member, but `&(A::B)' is
4961 expr
= finish_parenthesized_expr (expr
);
4963 /* DR 705: Wrapping an unqualified name in parentheses
4964 suppresses arg-dependent lookup. We want to pass back
4965 CP_ID_KIND_QUALIFIED for suppressing vtable lookup
4966 (c++/37862), but none of the others. */
4967 if (*idk
!= CP_ID_KIND_QUALIFIED
)
4968 *idk
= CP_ID_KIND_NONE
;
4970 /* The `>' token might be the end of a template-id or
4971 template-parameter-list now. */
4972 parser
->greater_than_is_operator_p
4973 = saved_greater_than_is_operator_p
;
4975 /* Consume the `)'. */
4976 token
= cp_lexer_peek_token (parser
->lexer
);
4977 location_t close_paren_loc
= token
->location
;
4978 expr
.set_range (open_paren_loc
, close_paren_loc
);
4979 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
)
4980 && !cp_parser_uncommitted_to_tentative_parse_p (parser
))
4981 cp_parser_skip_to_end_of_statement (parser
);
4986 case CPP_OPEN_SQUARE
:
4988 if (c_dialect_objc ())
4990 /* We might have an Objective-C++ message. */
4991 cp_parser_parse_tentatively (parser
);
4992 tree msg
= cp_parser_objc_message_expression (parser
);
4993 /* If that works out, we're done ... */
4994 if (cp_parser_parse_definitely (parser
))
4996 /* ... else, fall though to see if it's a lambda. */
4998 cp_expr lam
= cp_parser_lambda_expression (parser
);
4999 /* Don't warn about a failed tentative parse. */
5000 if (cp_parser_error_occurred (parser
))
5001 return error_mark_node
;
5002 maybe_warn_cpp0x (CPP0X_LAMBDA_EXPR
);
5006 case CPP_OBJC_STRING
:
5007 if (c_dialect_objc ())
5008 /* We have an Objective-C++ string literal. */
5009 return cp_parser_objc_expression (parser
);
5010 cp_parser_error (parser
, "expected primary-expression");
5011 return error_mark_node
;
5014 switch (token
->keyword
)
5016 /* These two are the boolean literals. */
5018 cp_lexer_consume_token (parser
->lexer
);
5019 return cp_expr (boolean_true_node
, token
->location
);
5021 cp_lexer_consume_token (parser
->lexer
);
5022 return cp_expr (boolean_false_node
, token
->location
);
5024 /* The `__null' literal. */
5026 cp_lexer_consume_token (parser
->lexer
);
5027 return cp_expr (null_node
, token
->location
);
5029 /* The `nullptr' literal. */
5031 cp_lexer_consume_token (parser
->lexer
);
5032 return cp_expr (nullptr_node
, token
->location
);
5034 /* Recognize the `this' keyword. */
5036 cp_lexer_consume_token (parser
->lexer
);
5037 if (parser
->local_variables_forbidden_p
)
5039 error_at (token
->location
,
5040 "%<this%> may not be used in this context");
5041 return error_mark_node
;
5043 /* Pointers cannot appear in constant-expressions. */
5044 if (cp_parser_non_integral_constant_expression (parser
, NIC_THIS
))
5045 return error_mark_node
;
5046 return cp_expr (finish_this_expr (), token
->location
);
5048 /* The `operator' keyword can be the beginning of an
5053 case RID_FUNCTION_NAME
:
5054 case RID_PRETTY_FUNCTION_NAME
:
5055 case RID_C99_FUNCTION_NAME
:
5057 non_integral_constant name
;
5059 /* The symbols __FUNCTION__, __PRETTY_FUNCTION__, and
5060 __func__ are the names of variables -- but they are
5061 treated specially. Therefore, they are handled here,
5062 rather than relying on the generic id-expression logic
5063 below. Grammatically, these names are id-expressions.
5065 Consume the token. */
5066 token
= cp_lexer_consume_token (parser
->lexer
);
5068 switch (token
->keyword
)
5070 case RID_FUNCTION_NAME
:
5071 name
= NIC_FUNC_NAME
;
5073 case RID_PRETTY_FUNCTION_NAME
:
5074 name
= NIC_PRETTY_FUNC
;
5076 case RID_C99_FUNCTION_NAME
:
5077 name
= NIC_C99_FUNC
;
5083 if (cp_parser_non_integral_constant_expression (parser
, name
))
5084 return error_mark_node
;
5086 /* Look up the name. */
5087 return finish_fname (token
->u
.value
);
5094 source_location type_location
;
5095 location_t start_loc
5096 = cp_lexer_peek_token (parser
->lexer
)->location
;
5097 /* The `__builtin_va_arg' construct is used to handle
5098 `va_arg'. Consume the `__builtin_va_arg' token. */
5099 cp_lexer_consume_token (parser
->lexer
);
5100 /* Look for the opening `('. */
5101 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
5102 /* Now, parse the assignment-expression. */
5103 expression
= cp_parser_assignment_expression (parser
);
5104 /* Look for the `,'. */
5105 cp_parser_require (parser
, CPP_COMMA
, RT_COMMA
);
5106 type_location
= cp_lexer_peek_token (parser
->lexer
)->location
;
5107 /* Parse the type-id. */
5109 type_id_in_expr_sentinel
s (parser
);
5110 type
= cp_parser_type_id (parser
);
5112 /* Look for the closing `)'. */
5113 location_t finish_loc
5114 = cp_lexer_peek_token (parser
->lexer
)->location
;
5115 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
5116 /* Using `va_arg' in a constant-expression is not
5118 if (cp_parser_non_integral_constant_expression (parser
,
5120 return error_mark_node
;
5121 /* Construct a location of the form:
5122 __builtin_va_arg (v, int)
5123 ~~~~~~~~~~~~~~~~~~~~~^~~~
5124 with the caret at the type, ranging from the start of the
5125 "__builtin_va_arg" token to the close paren. */
5126 location_t combined_loc
5127 = make_location (type_location
, start_loc
, finish_loc
);
5128 return build_x_va_arg (combined_loc
, expression
, type
);
5132 return cp_parser_builtin_offsetof (parser
);
5134 case RID_HAS_NOTHROW_ASSIGN
:
5135 case RID_HAS_NOTHROW_CONSTRUCTOR
:
5136 case RID_HAS_NOTHROW_COPY
:
5137 case RID_HAS_TRIVIAL_ASSIGN
:
5138 case RID_HAS_TRIVIAL_CONSTRUCTOR
:
5139 case RID_HAS_TRIVIAL_COPY
:
5140 case RID_HAS_TRIVIAL_DESTRUCTOR
:
5141 case RID_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
5142 case RID_HAS_VIRTUAL_DESTRUCTOR
:
5143 case RID_IS_ABSTRACT
:
5144 case RID_IS_AGGREGATE
:
5145 case RID_IS_BASE_OF
:
5150 case RID_IS_LITERAL_TYPE
:
5152 case RID_IS_POLYMORPHIC
:
5153 case RID_IS_SAME_AS
:
5154 case RID_IS_STD_LAYOUT
:
5155 case RID_IS_TRIVIAL
:
5156 case RID_IS_TRIVIALLY_ASSIGNABLE
:
5157 case RID_IS_TRIVIALLY_CONSTRUCTIBLE
:
5158 case RID_IS_TRIVIALLY_COPYABLE
:
5160 case RID_IS_ASSIGNABLE
:
5161 case RID_IS_CONSTRUCTIBLE
:
5162 return cp_parser_trait_expr (parser
, token
->keyword
);
5166 return cp_parser_requires_expression (parser
);
5168 /* Objective-C++ expressions. */
5170 case RID_AT_PROTOCOL
:
5171 case RID_AT_SELECTOR
:
5172 return cp_parser_objc_expression (parser
);
5175 if (parser
->in_function_body
5176 && (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
5179 error_at (token
->location
,
5180 "a template declaration cannot appear at block scope");
5181 cp_parser_skip_to_end_of_block_or_statement (parser
);
5182 return error_mark_node
;
5186 cp_parser_error (parser
, "expected primary-expression");
5187 return error_mark_node
;
5190 /* An id-expression can start with either an identifier, a
5191 `::' as the beginning of a qualified-id, or the "operator"
5195 case CPP_TEMPLATE_ID
:
5196 case CPP_NESTED_NAME_SPECIFIER
:
5199 cp_expr id_expression
;
5201 const char *error_msg
;
5204 cp_token
*id_expr_token
;
5206 /* Parse the id-expression. */
5208 = cp_parser_id_expression (parser
,
5209 /*template_keyword_p=*/false,
5210 /*check_dependency_p=*/true,
5212 /*declarator_p=*/false,
5213 /*optional_p=*/false);
5214 if (id_expression
== error_mark_node
)
5215 return error_mark_node
;
5216 id_expr_token
= token
;
5217 token
= cp_lexer_peek_token (parser
->lexer
);
5218 done
= (token
->type
!= CPP_OPEN_SQUARE
5219 && token
->type
!= CPP_OPEN_PAREN
5220 && token
->type
!= CPP_DOT
5221 && token
->type
!= CPP_DEREF
5222 && token
->type
!= CPP_PLUS_PLUS
5223 && token
->type
!= CPP_MINUS_MINUS
);
5224 /* If we have a template-id, then no further lookup is
5225 required. If the template-id was for a template-class, we
5226 will sometimes have a TYPE_DECL at this point. */
5227 if (TREE_CODE (id_expression
) == TEMPLATE_ID_EXPR
5228 || TREE_CODE (id_expression
) == TYPE_DECL
)
5229 decl
= id_expression
;
5230 /* Look up the name. */
5233 tree ambiguous_decls
;
5235 /* If we already know that this lookup is ambiguous, then
5236 we've already issued an error message; there's no reason
5238 if (id_expr_token
->type
== CPP_NAME
5239 && id_expr_token
->error_reported
)
5241 cp_parser_simulate_error (parser
);
5242 return error_mark_node
;
5245 decl
= cp_parser_lookup_name (parser
, id_expression
,
5248 /*is_namespace=*/false,
5249 /*check_dependency=*/true,
5251 id_expr_token
->location
);
5252 /* If the lookup was ambiguous, an error will already have
5254 if (ambiguous_decls
)
5255 return error_mark_node
;
5257 /* In Objective-C++, we may have an Objective-C 2.0
5258 dot-syntax for classes here. */
5259 if (c_dialect_objc ()
5260 && cp_lexer_peek_token (parser
->lexer
)->type
== CPP_DOT
5261 && TREE_CODE (decl
) == TYPE_DECL
5262 && objc_is_class_name (decl
))
5265 cp_lexer_consume_token (parser
->lexer
);
5266 component
= cp_parser_identifier (parser
);
5267 if (component
== error_mark_node
)
5268 return error_mark_node
;
5270 tree result
= objc_build_class_component_ref (id_expression
,
5272 /* Build a location of the form:
5275 with caret at the start of the component name (at
5276 input_location), ranging from the start of the id_expression
5277 to the end of the component name. */
5278 location_t combined_loc
5279 = make_location (input_location
, id_expression
.get_start (),
5280 get_finish (input_location
));
5281 protected_set_expr_location (result
, combined_loc
);
5285 /* In Objective-C++, an instance variable (ivar) may be preferred
5286 to whatever cp_parser_lookup_name() found.
5287 Call objc_lookup_ivar. To avoid exposing cp_expr to the
5288 rest of c-family, we have to do a little extra work to preserve
5289 any location information in cp_expr "decl". Given that
5290 objc_lookup_ivar is implemented in "c-family" and "objc", we
5291 have a trip through the pure "tree" type, rather than cp_expr.
5292 Naively copying it back to "decl" would implicitly give the
5293 new cp_expr value an UNKNOWN_LOCATION for nodes that don't
5294 store an EXPR_LOCATION. Hence we only update "decl" (and
5295 hence its location_t) if we get back a different tree node. */
5296 tree decl_tree
= objc_lookup_ivar (decl
.get_value (),
5298 if (decl_tree
!= decl
.get_value ())
5299 decl
= cp_expr (decl_tree
);
5301 /* If name lookup gives us a SCOPE_REF, then the
5302 qualifying scope was dependent. */
5303 if (TREE_CODE (decl
) == SCOPE_REF
)
5305 /* At this point, we do not know if DECL is a valid
5306 integral constant expression. We assume that it is
5307 in fact such an expression, so that code like:
5309 template <int N> struct A {
5313 is accepted. At template-instantiation time, we
5314 will check that B<N>::i is actually a constant. */
5317 /* Check to see if DECL is a local variable in a context
5318 where that is forbidden. */
5319 if (parser
->local_variables_forbidden_p
5320 && local_variable_p (decl
))
5322 /* It might be that we only found DECL because we are
5323 trying to be generous with pre-ISO scoping rules.
5324 For example, consider:
5328 for (int i = 0; i < 10; ++i) {}
5329 extern void f(int j = i);
5332 Here, name look up will originally find the out
5333 of scope `i'. We need to issue a warning message,
5334 but then use the global `i'. */
5335 decl
= check_for_out_of_scope_variable (decl
);
5336 if (local_variable_p (decl
))
5338 error_at (id_expr_token
->location
,
5339 "local variable %qD may not appear in this context",
5341 return error_mark_node
;
5346 decl
= (finish_id_expression
5347 (id_expression
, decl
, parser
->scope
,
5349 parser
->integral_constant_expression_p
,
5350 parser
->allow_non_integral_constant_expression_p
,
5351 &parser
->non_integral_constant_expression_p
,
5352 template_p
, done
, address_p
,
5355 id_expression
.get_location ()));
5357 cp_parser_error (parser
, error_msg
);
5358 decl
.set_location (id_expr_token
->location
);
5362 /* Anything else is an error. */
5364 cp_parser_error (parser
, "expected primary-expression");
5365 return error_mark_node
;
5369 static inline cp_expr
5370 cp_parser_primary_expression (cp_parser
*parser
,
5373 bool template_arg_p
,
5376 return cp_parser_primary_expression (parser
, address_p
, cast_p
, template_arg_p
,
5377 /*decltype*/false, idk
);
5380 /* Parse an id-expression.
5387 :: [opt] nested-name-specifier template [opt] unqualified-id
5389 :: operator-function-id
5392 Return a representation of the unqualified portion of the
5393 identifier. Sets PARSER->SCOPE to the qualifying scope if there is
5394 a `::' or nested-name-specifier.
5396 Often, if the id-expression was a qualified-id, the caller will
5397 want to make a SCOPE_REF to represent the qualified-id. This
5398 function does not do this in order to avoid wastefully creating
5399 SCOPE_REFs when they are not required.
5401 If TEMPLATE_KEYWORD_P is true, then we have just seen the
5404 If CHECK_DEPENDENCY_P is false, then names are looked up inside
5405 uninstantiated templates.
5407 If *TEMPLATE_P is non-NULL, it is set to true iff the
5408 `template' keyword is used to explicitly indicate that the entity
5409 named is a template.
5411 If DECLARATOR_P is true, the id-expression is appearing as part of
5412 a declarator, rather than as part of an expression. */
5415 cp_parser_id_expression (cp_parser
*parser
,
5416 bool template_keyword_p
,
5417 bool check_dependency_p
,
5422 bool global_scope_p
;
5423 bool nested_name_specifier_p
;
5425 /* Assume the `template' keyword was not used. */
5427 *template_p
= template_keyword_p
;
5429 /* Look for the optional `::' operator. */
5431 = (!template_keyword_p
5432 && (cp_parser_global_scope_opt (parser
,
5433 /*current_scope_valid_p=*/false)
5436 /* Look for the optional nested-name-specifier. */
5437 nested_name_specifier_p
5438 = (cp_parser_nested_name_specifier_opt (parser
,
5439 /*typename_keyword_p=*/false,
5446 /* If there is a nested-name-specifier, then we are looking at
5447 the first qualified-id production. */
5448 if (nested_name_specifier_p
)
5451 tree saved_object_scope
;
5452 tree saved_qualifying_scope
;
5453 cp_expr unqualified_id
;
5456 /* See if the next token is the `template' keyword. */
5458 template_p
= &is_template
;
5459 *template_p
= cp_parser_optional_template_keyword (parser
);
5460 /* Name lookup we do during the processing of the
5461 unqualified-id might obliterate SCOPE. */
5462 saved_scope
= parser
->scope
;
5463 saved_object_scope
= parser
->object_scope
;
5464 saved_qualifying_scope
= parser
->qualifying_scope
;
5465 /* Process the final unqualified-id. */
5466 unqualified_id
= cp_parser_unqualified_id (parser
, *template_p
,
5469 /*optional_p=*/false);
5470 /* Restore the SAVED_SCOPE for our caller. */
5471 parser
->scope
= saved_scope
;
5472 parser
->object_scope
= saved_object_scope
;
5473 parser
->qualifying_scope
= saved_qualifying_scope
;
5475 return unqualified_id
;
5477 /* Otherwise, if we are in global scope, then we are looking at one
5478 of the other qualified-id productions. */
5479 else if (global_scope_p
)
5484 /* Peek at the next token. */
5485 token
= cp_lexer_peek_token (parser
->lexer
);
5487 /* If it's an identifier, and the next token is not a "<", then
5488 we can avoid the template-id case. This is an optimization
5489 for this common case. */
5490 if (token
->type
== CPP_NAME
5491 && !cp_parser_nth_token_starts_template_argument_list_p
5493 return cp_parser_identifier (parser
);
5495 cp_parser_parse_tentatively (parser
);
5496 /* Try a template-id. */
5497 id
= cp_parser_template_id (parser
,
5498 /*template_keyword_p=*/false,
5499 /*check_dependency_p=*/true,
5502 /* If that worked, we're done. */
5503 if (cp_parser_parse_definitely (parser
))
5506 /* Peek at the next token. (Changes in the token buffer may
5507 have invalidated the pointer obtained above.) */
5508 token
= cp_lexer_peek_token (parser
->lexer
);
5510 switch (token
->type
)
5513 return cp_parser_identifier (parser
);
5516 if (token
->keyword
== RID_OPERATOR
)
5517 return cp_parser_operator_function_id (parser
);
5521 cp_parser_error (parser
, "expected id-expression");
5522 return error_mark_node
;
5526 return cp_parser_unqualified_id (parser
, template_keyword_p
,
5527 /*check_dependency_p=*/true,
5532 /* Parse an unqualified-id.
5536 operator-function-id
5537 conversion-function-id
5541 If TEMPLATE_KEYWORD_P is TRUE, we have just seen the `template'
5542 keyword, in a construct like `A::template ...'.
5544 Returns a representation of unqualified-id. For the `identifier'
5545 production, an IDENTIFIER_NODE is returned. For the `~ class-name'
5546 production a BIT_NOT_EXPR is returned; the operand of the
5547 BIT_NOT_EXPR is an IDENTIFIER_NODE for the class-name. For the
5548 other productions, see the documentation accompanying the
5549 corresponding parsing functions. If CHECK_DEPENDENCY_P is false,
5550 names are looked up in uninstantiated templates. If DECLARATOR_P
5551 is true, the unqualified-id is appearing as part of a declarator,
5552 rather than as part of an expression. */
5555 cp_parser_unqualified_id (cp_parser
* parser
,
5556 bool template_keyword_p
,
5557 bool check_dependency_p
,
5563 /* Peek at the next token. */
5564 token
= cp_lexer_peek_token (parser
->lexer
);
5566 switch ((int) token
->type
)
5572 /* We don't know yet whether or not this will be a
5574 cp_parser_parse_tentatively (parser
);
5575 /* Try a template-id. */
5576 id
= cp_parser_template_id (parser
, template_keyword_p
,
5580 /* If it worked, we're done. */
5581 if (cp_parser_parse_definitely (parser
))
5583 /* Otherwise, it's an ordinary identifier. */
5584 return cp_parser_identifier (parser
);
5587 case CPP_TEMPLATE_ID
:
5588 return cp_parser_template_id (parser
, template_keyword_p
,
5596 tree qualifying_scope
;
5601 /* Consume the `~' token. */
5602 cp_lexer_consume_token (parser
->lexer
);
5603 /* Parse the class-name. The standard, as written, seems to
5606 template <typename T> struct S { ~S (); };
5607 template <typename T> S<T>::~S() {}
5609 is invalid, since `~' must be followed by a class-name, but
5610 `S<T>' is dependent, and so not known to be a class.
5611 That's not right; we need to look in uninstantiated
5612 templates. A further complication arises from:
5614 template <typename T> void f(T t) {
5618 Here, it is not possible to look up `T' in the scope of `T'
5619 itself. We must look in both the current scope, and the
5620 scope of the containing complete expression.
5622 Yet another issue is:
5631 The standard does not seem to say that the `S' in `~S'
5632 should refer to the type `S' and not the data member
5635 /* DR 244 says that we look up the name after the "~" in the
5636 same scope as we looked up the qualifying name. That idea
5637 isn't fully worked out; it's more complicated than that. */
5638 scope
= parser
->scope
;
5639 object_scope
= parser
->object_scope
;
5640 qualifying_scope
= parser
->qualifying_scope
;
5642 /* Check for invalid scopes. */
5643 if (scope
== error_mark_node
)
5645 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
5646 cp_lexer_consume_token (parser
->lexer
);
5647 return error_mark_node
;
5649 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
5651 if (!cp_parser_uncommitted_to_tentative_parse_p (parser
))
5652 error_at (token
->location
,
5653 "scope %qT before %<~%> is not a class-name",
5655 cp_parser_simulate_error (parser
);
5656 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
5657 cp_lexer_consume_token (parser
->lexer
);
5658 return error_mark_node
;
5660 gcc_assert (!scope
|| TYPE_P (scope
));
5662 /* If the name is of the form "X::~X" it's OK even if X is a
5664 token
= cp_lexer_peek_token (parser
->lexer
);
5666 && token
->type
== CPP_NAME
5667 && (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
5669 && (token
->u
.value
== TYPE_IDENTIFIER (scope
)
5670 || (CLASS_TYPE_P (scope
)
5671 && constructor_name_p (token
->u
.value
, scope
))))
5673 cp_lexer_consume_token (parser
->lexer
);
5674 return build_nt (BIT_NOT_EXPR
, scope
);
5677 /* ~auto means the destructor of whatever the object is. */
5678 if (cp_parser_is_keyword (token
, RID_AUTO
))
5680 if (cxx_dialect
< cxx14
)
5681 pedwarn (input_location
, 0,
5682 "%<~auto%> only available with "
5683 "-std=c++14 or -std=gnu++14");
5684 cp_lexer_consume_token (parser
->lexer
);
5685 return build_nt (BIT_NOT_EXPR
, make_auto ());
5688 /* If there was an explicit qualification (S::~T), first look
5689 in the scope given by the qualification (i.e., S).
5691 Note: in the calls to cp_parser_class_name below we pass
5692 typename_type so that lookup finds the injected-class-name
5693 rather than the constructor. */
5695 type_decl
= NULL_TREE
;
5698 cp_parser_parse_tentatively (parser
);
5699 type_decl
= cp_parser_class_name (parser
,
5700 /*typename_keyword_p=*/false,
5701 /*template_keyword_p=*/false,
5703 /*check_dependency=*/false,
5704 /*class_head_p=*/false,
5706 if (cp_parser_parse_definitely (parser
))
5709 /* In "N::S::~S", look in "N" as well. */
5710 if (!done
&& scope
&& qualifying_scope
)
5712 cp_parser_parse_tentatively (parser
);
5713 parser
->scope
= qualifying_scope
;
5714 parser
->object_scope
= NULL_TREE
;
5715 parser
->qualifying_scope
= NULL_TREE
;
5717 = cp_parser_class_name (parser
,
5718 /*typename_keyword_p=*/false,
5719 /*template_keyword_p=*/false,
5721 /*check_dependency=*/false,
5722 /*class_head_p=*/false,
5724 if (cp_parser_parse_definitely (parser
))
5727 /* In "p->S::~T", look in the scope given by "*p" as well. */
5728 else if (!done
&& object_scope
)
5730 cp_parser_parse_tentatively (parser
);
5731 parser
->scope
= object_scope
;
5732 parser
->object_scope
= NULL_TREE
;
5733 parser
->qualifying_scope
= NULL_TREE
;
5735 = cp_parser_class_name (parser
,
5736 /*typename_keyword_p=*/false,
5737 /*template_keyword_p=*/false,
5739 /*check_dependency=*/false,
5740 /*class_head_p=*/false,
5742 if (cp_parser_parse_definitely (parser
))
5745 /* Look in the surrounding context. */
5748 parser
->scope
= NULL_TREE
;
5749 parser
->object_scope
= NULL_TREE
;
5750 parser
->qualifying_scope
= NULL_TREE
;
5751 if (processing_template_decl
)
5752 cp_parser_parse_tentatively (parser
);
5754 = cp_parser_class_name (parser
,
5755 /*typename_keyword_p=*/false,
5756 /*template_keyword_p=*/false,
5758 /*check_dependency=*/false,
5759 /*class_head_p=*/false,
5761 if (processing_template_decl
5762 && ! cp_parser_parse_definitely (parser
))
5764 /* We couldn't find a type with this name. If we're parsing
5765 tentatively, fail and try something else. */
5766 if (cp_parser_uncommitted_to_tentative_parse_p (parser
))
5768 cp_parser_simulate_error (parser
);
5769 return error_mark_node
;
5771 /* Otherwise, accept it and check for a match at instantiation
5773 type_decl
= cp_parser_identifier (parser
);
5774 if (type_decl
!= error_mark_node
)
5775 type_decl
= build_nt (BIT_NOT_EXPR
, type_decl
);
5779 /* If an error occurred, assume that the name of the
5780 destructor is the same as the name of the qualifying
5781 class. That allows us to keep parsing after running
5782 into ill-formed destructor names. */
5783 if (type_decl
== error_mark_node
&& scope
)
5784 return build_nt (BIT_NOT_EXPR
, scope
);
5785 else if (type_decl
== error_mark_node
)
5786 return error_mark_node
;
5788 /* Check that destructor name and scope match. */
5789 if (declarator_p
&& scope
&& !check_dtor_name (scope
, type_decl
))
5791 if (!cp_parser_uncommitted_to_tentative_parse_p (parser
))
5792 error_at (token
->location
,
5793 "declaration of %<~%T%> as member of %qT",
5795 cp_parser_simulate_error (parser
);
5796 return error_mark_node
;
5801 A typedef-name that names a class shall not be used as the
5802 identifier in the declarator for a destructor declaration. */
5804 && !DECL_IMPLICIT_TYPEDEF_P (type_decl
)
5805 && !DECL_SELF_REFERENCE_P (type_decl
)
5806 && !cp_parser_uncommitted_to_tentative_parse_p (parser
))
5807 error_at (token
->location
,
5808 "typedef-name %qD used as destructor declarator",
5811 return build_nt (BIT_NOT_EXPR
, TREE_TYPE (type_decl
));
5815 if (token
->keyword
== RID_OPERATOR
)
5819 /* This could be a template-id, so we try that first. */
5820 cp_parser_parse_tentatively (parser
);
5821 /* Try a template-id. */
5822 id
= cp_parser_template_id (parser
, template_keyword_p
,
5823 /*check_dependency_p=*/true,
5826 /* If that worked, we're done. */
5827 if (cp_parser_parse_definitely (parser
))
5829 /* We still don't know whether we're looking at an
5830 operator-function-id or a conversion-function-id. */
5831 cp_parser_parse_tentatively (parser
);
5832 /* Try an operator-function-id. */
5833 id
= cp_parser_operator_function_id (parser
);
5834 /* If that didn't work, try a conversion-function-id. */
5835 if (!cp_parser_parse_definitely (parser
))
5836 id
= cp_parser_conversion_function_id (parser
);
5837 else if (UDLIT_OPER_P (id
))
5840 const char *name
= UDLIT_OP_SUFFIX (id
);
5841 if (name
[0] != '_' && !in_system_header_at (input_location
)
5843 warning (OPT_Wliteral_suffix
,
5844 "literal operator suffixes not preceded by %<_%>"
5845 " are reserved for future standardization");
5855 cp_parser_error (parser
, "expected unqualified-id");
5856 return error_mark_node
;
5860 /* Parse an (optional) nested-name-specifier.
5862 nested-name-specifier: [C++98]
5863 class-or-namespace-name :: nested-name-specifier [opt]
5864 class-or-namespace-name :: template nested-name-specifier [opt]
5866 nested-name-specifier: [C++0x]
5869 nested-name-specifier identifier ::
5870 nested-name-specifier template [opt] simple-template-id ::
5872 PARSER->SCOPE should be set appropriately before this function is
5873 called. TYPENAME_KEYWORD_P is TRUE if the `typename' keyword is in
5874 effect. TYPE_P is TRUE if we non-type bindings should be ignored
5877 Sets PARSER->SCOPE to the class (TYPE) or namespace
5878 (NAMESPACE_DECL) specified by the nested-name-specifier, or leaves
5879 it unchanged if there is no nested-name-specifier. Returns the new
5880 scope iff there is a nested-name-specifier, or NULL_TREE otherwise.
5882 If IS_DECLARATION is TRUE, the nested-name-specifier is known to be
5883 part of a declaration and/or decl-specifier. */
5886 cp_parser_nested_name_specifier_opt (cp_parser
*parser
,
5887 bool typename_keyword_p
,
5888 bool check_dependency_p
,
5890 bool is_declaration
,
5891 bool template_keyword_p
/* = false */)
5893 bool success
= false;
5894 cp_token_position start
= 0;
5897 /* Remember where the nested-name-specifier starts. */
5898 if (cp_parser_uncommitted_to_tentative_parse_p (parser
))
5900 start
= cp_lexer_token_position (parser
->lexer
, false);
5901 push_deferring_access_checks (dk_deferred
);
5908 tree saved_qualifying_scope
;
5910 /* Spot cases that cannot be the beginning of a
5911 nested-name-specifier. */
5912 token
= cp_lexer_peek_token (parser
->lexer
);
5914 /* If the next token is CPP_NESTED_NAME_SPECIFIER, just process
5915 the already parsed nested-name-specifier. */
5916 if (token
->type
== CPP_NESTED_NAME_SPECIFIER
)
5918 /* Grab the nested-name-specifier and continue the loop. */
5919 cp_parser_pre_parsed_nested_name_specifier (parser
);
5920 /* If we originally encountered this nested-name-specifier
5921 with IS_DECLARATION set to false, we will not have
5922 resolved TYPENAME_TYPEs, so we must do so here. */
5924 && TREE_CODE (parser
->scope
) == TYPENAME_TYPE
)
5926 new_scope
= resolve_typename_type (parser
->scope
,
5927 /*only_current_p=*/false);
5928 if (TREE_CODE (new_scope
) != TYPENAME_TYPE
)
5929 parser
->scope
= new_scope
;
5935 /* Spot cases that cannot be the beginning of a
5936 nested-name-specifier. On the second and subsequent times
5937 through the loop, we look for the `template' keyword. */
5938 if (success
&& token
->keyword
== RID_TEMPLATE
)
5940 /* A template-id can start a nested-name-specifier. */
5941 else if (token
->type
== CPP_TEMPLATE_ID
)
5943 /* DR 743: decltype can be used in a nested-name-specifier. */
5944 else if (token_is_decltype (token
))
5948 /* If the next token is not an identifier, then it is
5949 definitely not a type-name or namespace-name. */
5950 if (token
->type
!= CPP_NAME
)
5952 /* If the following token is neither a `<' (to begin a
5953 template-id), nor a `::', then we are not looking at a
5954 nested-name-specifier. */
5955 token
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
5957 if (token
->type
== CPP_COLON
5958 && parser
->colon_corrects_to_scope_p
5959 && cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
== CPP_NAME
)
5961 gcc_rich_location
richloc (token
->location
);
5962 richloc
.add_fixit_replace ("::");
5963 error_at_rich_loc (&richloc
,
5964 "found %<:%> in nested-name-specifier, "
5966 token
->type
= CPP_SCOPE
;
5969 if (token
->type
!= CPP_SCOPE
5970 && !cp_parser_nth_token_starts_template_argument_list_p
5975 /* The nested-name-specifier is optional, so we parse
5977 cp_parser_parse_tentatively (parser
);
5979 /* Look for the optional `template' keyword, if this isn't the
5980 first time through the loop. */
5982 template_keyword_p
= cp_parser_optional_template_keyword (parser
);
5984 /* Save the old scope since the name lookup we are about to do
5985 might destroy it. */
5986 old_scope
= parser
->scope
;
5987 saved_qualifying_scope
= parser
->qualifying_scope
;
5988 /* In a declarator-id like "X<T>::I::Y<T>" we must be able to
5989 look up names in "X<T>::I" in order to determine that "Y" is
5990 a template. So, if we have a typename at this point, we make
5991 an effort to look through it. */
5993 && !typename_keyword_p
5995 && TREE_CODE (parser
->scope
) == TYPENAME_TYPE
)
5996 parser
->scope
= resolve_typename_type (parser
->scope
,
5997 /*only_current_p=*/false);
5998 /* Parse the qualifying entity. */
6000 = cp_parser_qualifying_entity (parser
,
6006 /* Look for the `::' token. */
6007 cp_parser_require (parser
, CPP_SCOPE
, RT_SCOPE
);
6009 /* If we found what we wanted, we keep going; otherwise, we're
6011 if (!cp_parser_parse_definitely (parser
))
6013 bool error_p
= false;
6015 /* Restore the OLD_SCOPE since it was valid before the
6016 failed attempt at finding the last
6017 class-or-namespace-name. */
6018 parser
->scope
= old_scope
;
6019 parser
->qualifying_scope
= saved_qualifying_scope
;
6021 /* If the next token is a decltype, and the one after that is a
6022 `::', then the decltype has failed to resolve to a class or
6023 enumeration type. Give this error even when parsing
6024 tentatively since it can't possibly be valid--and we're going
6025 to replace it with a CPP_NESTED_NAME_SPECIFIER below, so we
6026 won't get another chance.*/
6027 if (cp_lexer_next_token_is (parser
->lexer
, CPP_DECLTYPE
)
6028 && (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
6031 token
= cp_lexer_consume_token (parser
->lexer
);
6032 error_at (token
->location
, "decltype evaluates to %qT, "
6033 "which is not a class or enumeration type",
6034 token
->u
.tree_check_value
->value
);
6035 parser
->scope
= error_mark_node
;
6039 cp_lexer_consume_token (parser
->lexer
);
6042 if (cp_lexer_next_token_is (parser
->lexer
, CPP_TEMPLATE_ID
)
6043 && cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_SCOPE
))
6045 /* If we have a non-type template-id followed by ::, it can't
6046 possibly be valid. */
6047 token
= cp_lexer_peek_token (parser
->lexer
);
6048 tree tid
= token
->u
.tree_check_value
->value
;
6049 if (TREE_CODE (tid
) == TEMPLATE_ID_EXPR
6050 && TREE_CODE (TREE_OPERAND (tid
, 0)) != IDENTIFIER_NODE
)
6052 tree tmpl
= NULL_TREE
;
6053 if (is_overloaded_fn (tid
))
6055 tree fns
= get_fns (tid
);
6056 if (OVL_SINGLE_P (fns
))
6057 tmpl
= OVL_FIRST (fns
);
6058 error_at (token
->location
, "function template-id %qD "
6059 "in nested-name-specifier", tid
);
6063 /* Variable template. */
6064 tmpl
= TREE_OPERAND (tid
, 0);
6065 gcc_assert (variable_template_p (tmpl
));
6066 error_at (token
->location
, "variable template-id %qD "
6067 "in nested-name-specifier", tid
);
6070 inform (DECL_SOURCE_LOCATION (tmpl
),
6071 "%qD declared here", tmpl
);
6073 parser
->scope
= error_mark_node
;
6077 cp_lexer_consume_token (parser
->lexer
);
6078 cp_lexer_consume_token (parser
->lexer
);
6082 if (cp_parser_uncommitted_to_tentative_parse_p (parser
))
6084 /* If the next token is an identifier, and the one after
6085 that is a `::', then any valid interpretation would have
6086 found a class-or-namespace-name. */
6087 while (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
)
6088 && (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
6090 && (cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
6093 token
= cp_lexer_consume_token (parser
->lexer
);
6096 if (!token
->error_reported
)
6099 tree ambiguous_decls
;
6101 decl
= cp_parser_lookup_name (parser
, token
->u
.value
,
6103 /*is_template=*/false,
6104 /*is_namespace=*/false,
6105 /*check_dependency=*/true,
6108 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
6109 error_at (token
->location
,
6110 "%qD used without template parameters",
6112 else if (ambiguous_decls
)
6114 // cp_parser_lookup_name has the same diagnostic,
6115 // thus make sure to emit it at most once.
6116 if (cp_parser_uncommitted_to_tentative_parse_p
6119 error_at (token
->location
,
6120 "reference to %qD is ambiguous",
6122 print_candidates (ambiguous_decls
);
6124 decl
= error_mark_node
;
6128 if (cxx_dialect
!= cxx98
)
6129 cp_parser_name_lookup_error
6130 (parser
, token
->u
.value
, decl
, NLE_NOT_CXX98
,
6133 cp_parser_name_lookup_error
6134 (parser
, token
->u
.value
, decl
, NLE_CXX98
,
6138 parser
->scope
= error_mark_node
;
6140 /* Treat this as a successful nested-name-specifier
6145 If the name found is not a class-name (clause
6146 _class_) or namespace-name (_namespace.def_), the
6147 program is ill-formed. */
6150 cp_lexer_consume_token (parser
->lexer
);
6154 /* We've found one valid nested-name-specifier. */
6156 /* Name lookup always gives us a DECL. */
6157 if (TREE_CODE (new_scope
) == TYPE_DECL
)
6158 new_scope
= TREE_TYPE (new_scope
);
6159 /* Uses of "template" must be followed by actual templates. */
6160 if (template_keyword_p
6161 && !(CLASS_TYPE_P (new_scope
)
6162 && ((CLASSTYPE_USE_TEMPLATE (new_scope
)
6163 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (new_scope
)))
6164 || CLASSTYPE_IS_TEMPLATE (new_scope
)))
6165 && !(TREE_CODE (new_scope
) == TYPENAME_TYPE
6166 && (TREE_CODE (TYPENAME_TYPE_FULLNAME (new_scope
))
6167 == TEMPLATE_ID_EXPR
)))
6168 permerror (input_location
, TYPE_P (new_scope
)
6169 ? G_("%qT is not a template")
6170 : G_("%qD is not a template"),
6172 /* If it is a class scope, try to complete it; we are about to
6173 be looking up names inside the class. */
6174 if (TYPE_P (new_scope
)
6175 /* Since checking types for dependency can be expensive,
6176 avoid doing it if the type is already complete. */
6177 && !COMPLETE_TYPE_P (new_scope
)
6178 /* Do not try to complete dependent types. */
6179 && !dependent_type_p (new_scope
))
6181 new_scope
= complete_type (new_scope
);
6182 /* If it is a typedef to current class, use the current
6183 class instead, as the typedef won't have any names inside
6185 if (!COMPLETE_TYPE_P (new_scope
)
6186 && currently_open_class (new_scope
))
6187 new_scope
= TYPE_MAIN_VARIANT (new_scope
);
6189 /* Make sure we look in the right scope the next time through
6191 parser
->scope
= new_scope
;
6194 /* If parsing tentatively, replace the sequence of tokens that makes
6195 up the nested-name-specifier with a CPP_NESTED_NAME_SPECIFIER
6196 token. That way, should we re-parse the token stream, we will
6197 not have to repeat the effort required to do the parse, nor will
6198 we issue duplicate error messages. */
6199 if (success
&& start
)
6203 token
= cp_lexer_token_at (parser
->lexer
, start
);
6204 /* Reset the contents of the START token. */
6205 token
->type
= CPP_NESTED_NAME_SPECIFIER
;
6206 /* Retrieve any deferred checks. Do not pop this access checks yet
6207 so the memory will not be reclaimed during token replacing below. */
6208 token
->u
.tree_check_value
= ggc_cleared_alloc
<struct tree_check
> ();
6209 token
->u
.tree_check_value
->value
= parser
->scope
;
6210 token
->u
.tree_check_value
->checks
= get_deferred_access_checks ();
6211 token
->u
.tree_check_value
->qualifying_scope
=
6212 parser
->qualifying_scope
;
6213 token
->keyword
= RID_MAX
;
6215 /* Purge all subsequent tokens. */
6216 cp_lexer_purge_tokens_after (parser
->lexer
, start
);
6220 pop_to_parent_deferring_access_checks ();
6222 return success
? parser
->scope
: NULL_TREE
;
6225 /* Parse a nested-name-specifier. See
6226 cp_parser_nested_name_specifier_opt for details. This function
6227 behaves identically, except that it will an issue an error if no
6228 nested-name-specifier is present. */
6231 cp_parser_nested_name_specifier (cp_parser
*parser
,
6232 bool typename_keyword_p
,
6233 bool check_dependency_p
,
6235 bool is_declaration
)
6239 /* Look for the nested-name-specifier. */
6240 scope
= cp_parser_nested_name_specifier_opt (parser
,
6245 /* If it was not present, issue an error message. */
6248 cp_parser_error (parser
, "expected nested-name-specifier");
6249 parser
->scope
= NULL_TREE
;
6255 /* Parse the qualifying entity in a nested-name-specifier. For C++98,
6256 this is either a class-name or a namespace-name (which corresponds
6257 to the class-or-namespace-name production in the grammar). For
6258 C++0x, it can also be a type-name that refers to an enumeration
6259 type or a simple-template-id.
6261 TYPENAME_KEYWORD_P is TRUE iff the `typename' keyword is in effect.
6262 TEMPLATE_KEYWORD_P is TRUE iff the `template' keyword is in effect.
6263 CHECK_DEPENDENCY_P is FALSE iff dependent names should be looked up.
6264 TYPE_P is TRUE iff the next name should be taken as a class-name,
6265 even the same name is declared to be another entity in the same
6268 Returns the class (TYPE_DECL) or namespace (NAMESPACE_DECL)
6269 specified by the class-or-namespace-name. If neither is found the
6270 ERROR_MARK_NODE is returned. */
6273 cp_parser_qualifying_entity (cp_parser
*parser
,
6274 bool typename_keyword_p
,
6275 bool template_keyword_p
,
6276 bool check_dependency_p
,
6278 bool is_declaration
)
6281 tree saved_qualifying_scope
;
6282 tree saved_object_scope
;
6285 bool successful_parse_p
;
6287 /* DR 743: decltype can appear in a nested-name-specifier. */
6288 if (cp_lexer_next_token_is_decltype (parser
->lexer
))
6290 scope
= cp_parser_decltype (parser
);
6291 if (TREE_CODE (scope
) != ENUMERAL_TYPE
6292 && !MAYBE_CLASS_TYPE_P (scope
))
6294 cp_parser_simulate_error (parser
);
6295 return error_mark_node
;
6297 if (TYPE_NAME (scope
))
6298 scope
= TYPE_NAME (scope
);
6302 /* Before we try to parse the class-name, we must save away the
6303 current PARSER->SCOPE since cp_parser_class_name will destroy
6305 saved_scope
= parser
->scope
;
6306 saved_qualifying_scope
= parser
->qualifying_scope
;
6307 saved_object_scope
= parser
->object_scope
;
6308 /* Try for a class-name first. If the SAVED_SCOPE is a type, then
6309 there is no need to look for a namespace-name. */
6310 only_class_p
= template_keyword_p
6311 || (saved_scope
&& TYPE_P (saved_scope
) && cxx_dialect
== cxx98
);
6313 cp_parser_parse_tentatively (parser
);
6314 scope
= cp_parser_class_name (parser
,
6317 type_p
? class_type
: none_type
,
6319 /*class_head_p=*/false,
6321 /*enum_ok=*/cxx_dialect
> cxx98
);
6322 successful_parse_p
= only_class_p
|| cp_parser_parse_definitely (parser
);
6323 /* If that didn't work, try for a namespace-name. */
6324 if (!only_class_p
&& !successful_parse_p
)
6326 /* Restore the saved scope. */
6327 parser
->scope
= saved_scope
;
6328 parser
->qualifying_scope
= saved_qualifying_scope
;
6329 parser
->object_scope
= saved_object_scope
;
6330 /* If we are not looking at an identifier followed by the scope
6331 resolution operator, then this is not part of a
6332 nested-name-specifier. (Note that this function is only used
6333 to parse the components of a nested-name-specifier.) */
6334 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_NAME
)
6335 || cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
!= CPP_SCOPE
)
6336 return error_mark_node
;
6337 scope
= cp_parser_namespace_name (parser
);
6343 /* Return true if we are looking at a compound-literal, false otherwise. */
6346 cp_parser_compound_literal_p (cp_parser
*parser
)
6348 /* Consume the `('. */
6349 cp_lexer_consume_token (parser
->lexer
);
6351 cp_lexer_save_tokens (parser
->lexer
);
6353 /* Skip tokens until the next token is a closing parenthesis.
6354 If we find the closing `)', and the next token is a `{', then
6355 we are looking at a compound-literal. */
6356 bool compound_literal_p
6357 = (cp_parser_skip_to_closing_parenthesis (parser
, false, false,
6358 /*consume_paren=*/true)
6359 && cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
));
6361 /* Roll back the tokens we skipped. */
6362 cp_lexer_rollback_tokens (parser
->lexer
);
6364 return compound_literal_p
;
6367 /* Parse a postfix-expression.
6371 postfix-expression [ expression ]
6372 postfix-expression ( expression-list [opt] )
6373 simple-type-specifier ( expression-list [opt] )
6374 typename :: [opt] nested-name-specifier identifier
6375 ( expression-list [opt] )
6376 typename :: [opt] nested-name-specifier template [opt] template-id
6377 ( expression-list [opt] )
6378 postfix-expression . template [opt] id-expression
6379 postfix-expression -> template [opt] id-expression
6380 postfix-expression . pseudo-destructor-name
6381 postfix-expression -> pseudo-destructor-name
6382 postfix-expression ++
6383 postfix-expression --
6384 dynamic_cast < type-id > ( expression )
6385 static_cast < type-id > ( expression )
6386 reinterpret_cast < type-id > ( expression )
6387 const_cast < type-id > ( expression )
6388 typeid ( expression )
6394 ( type-id ) { initializer-list , [opt] }
6396 This extension is a GNU version of the C99 compound-literal
6397 construct. (The C99 grammar uses `type-name' instead of `type-id',
6398 but they are essentially the same concept.)
6400 If ADDRESS_P is true, the postfix expression is the operand of the
6401 `&' operator. CAST_P is true if this expression is the target of a
6404 If MEMBER_ACCESS_ONLY_P, we only allow postfix expressions that are
6405 class member access expressions [expr.ref].
6407 Returns a representation of the expression. */
6410 cp_parser_postfix_expression (cp_parser
*parser
, bool address_p
, bool cast_p
,
6411 bool member_access_only_p
, bool decltype_p
,
6412 cp_id_kind
* pidk_return
)
6417 cp_id_kind idk
= CP_ID_KIND_NONE
;
6418 cp_expr postfix_expression
= NULL_TREE
;
6419 bool is_member_access
= false;
6420 int saved_in_statement
= -1;
6422 /* Peek at the next token. */
6423 token
= cp_lexer_peek_token (parser
->lexer
);
6424 loc
= token
->location
;
6425 location_t start_loc
= get_range_from_loc (line_table
, loc
).m_start
;
6427 /* Some of the productions are determined by keywords. */
6428 keyword
= token
->keyword
;
6438 const char *saved_message
;
6439 bool saved_in_type_id_in_expr_p
;
6441 /* All of these can be handled in the same way from the point
6442 of view of parsing. Begin by consuming the token
6443 identifying the cast. */
6444 cp_lexer_consume_token (parser
->lexer
);
6446 /* New types cannot be defined in the cast. */
6447 saved_message
= parser
->type_definition_forbidden_message
;
6448 parser
->type_definition_forbidden_message
6449 = G_("types may not be defined in casts");
6451 /* Look for the opening `<'. */
6452 cp_parser_require (parser
, CPP_LESS
, RT_LESS
);
6453 /* Parse the type to which we are casting. */
6454 saved_in_type_id_in_expr_p
= parser
->in_type_id_in_expr_p
;
6455 parser
->in_type_id_in_expr_p
= true;
6456 type
= cp_parser_type_id (parser
);
6457 parser
->in_type_id_in_expr_p
= saved_in_type_id_in_expr_p
;
6458 /* Look for the closing `>'. */
6459 cp_parser_require (parser
, CPP_GREATER
, RT_GREATER
);
6460 /* Restore the old message. */
6461 parser
->type_definition_forbidden_message
= saved_message
;
6463 bool saved_greater_than_is_operator_p
6464 = parser
->greater_than_is_operator_p
;
6465 parser
->greater_than_is_operator_p
= true;
6467 /* And the expression which is being cast. */
6468 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
6469 expression
= cp_parser_expression (parser
, & idk
, /*cast_p=*/true);
6470 cp_token
*close_paren
= cp_parser_require (parser
, CPP_CLOSE_PAREN
,
6472 location_t end_loc
= close_paren
?
6473 close_paren
->location
: UNKNOWN_LOCATION
;
6475 parser
->greater_than_is_operator_p
6476 = saved_greater_than_is_operator_p
;
6478 /* Only type conversions to integral or enumeration types
6479 can be used in constant-expressions. */
6480 if (!cast_valid_in_integral_constant_expression_p (type
)
6481 && cp_parser_non_integral_constant_expression (parser
, NIC_CAST
))
6483 postfix_expression
= error_mark_node
;
6491 = build_dynamic_cast (type
, expression
, tf_warning_or_error
);
6495 = build_static_cast (type
, expression
, tf_warning_or_error
);
6499 = build_reinterpret_cast (type
, expression
,
6500 tf_warning_or_error
);
6504 = build_const_cast (type
, expression
, tf_warning_or_error
);
6510 /* Construct a location e.g. :
6511 reinterpret_cast <int *> (expr)
6512 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6513 ranging from the start of the "*_cast" token to the final closing
6514 paren, with the caret at the start. */
6515 location_t cp_cast_loc
= make_location (start_loc
, start_loc
, end_loc
);
6516 postfix_expression
.set_location (cp_cast_loc
);
6523 const char *saved_message
;
6524 bool saved_in_type_id_in_expr_p
;
6526 /* Consume the `typeid' token. */
6527 cp_lexer_consume_token (parser
->lexer
);
6528 /* Look for the `(' token. */
6529 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
6530 /* Types cannot be defined in a `typeid' expression. */
6531 saved_message
= parser
->type_definition_forbidden_message
;
6532 parser
->type_definition_forbidden_message
6533 = G_("types may not be defined in a %<typeid%> expression");
6534 /* We can't be sure yet whether we're looking at a type-id or an
6536 cp_parser_parse_tentatively (parser
);
6537 /* Try a type-id first. */
6538 saved_in_type_id_in_expr_p
= parser
->in_type_id_in_expr_p
;
6539 parser
->in_type_id_in_expr_p
= true;
6540 type
= cp_parser_type_id (parser
);
6541 parser
->in_type_id_in_expr_p
= saved_in_type_id_in_expr_p
;
6542 /* Look for the `)' token. Otherwise, we can't be sure that
6543 we're not looking at an expression: consider `typeid (int
6544 (3))', for example. */
6545 cp_token
*close_paren
= cp_parser_require (parser
, CPP_CLOSE_PAREN
,
6547 /* If all went well, simply lookup the type-id. */
6548 if (cp_parser_parse_definitely (parser
))
6549 postfix_expression
= get_typeid (type
, tf_warning_or_error
);
6550 /* Otherwise, fall back to the expression variant. */
6555 /* Look for an expression. */
6556 expression
= cp_parser_expression (parser
, & idk
);
6557 /* Compute its typeid. */
6558 postfix_expression
= build_typeid (expression
, tf_warning_or_error
);
6559 /* Look for the `)' token. */
6561 = cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
6563 /* Restore the saved message. */
6564 parser
->type_definition_forbidden_message
= saved_message
;
6565 /* `typeid' may not appear in an integral constant expression. */
6566 if (cp_parser_non_integral_constant_expression (parser
, NIC_TYPEID
))
6567 postfix_expression
= error_mark_node
;
6569 /* Construct a location e.g. :
6572 ranging from the start of the "typeid" token to the final closing
6573 paren, with the caret at the start. */
6576 location_t typeid_loc
6577 = make_location (start_loc
, start_loc
, close_paren
->location
);
6578 postfix_expression
.set_location (typeid_loc
);
6586 /* The syntax permitted here is the same permitted for an
6587 elaborated-type-specifier. */
6588 ++parser
->prevent_constrained_type_specifiers
;
6589 type
= cp_parser_elaborated_type_specifier (parser
,
6590 /*is_friend=*/false,
6591 /*is_declaration=*/false);
6592 --parser
->prevent_constrained_type_specifiers
;
6593 postfix_expression
= cp_parser_functional_cast (parser
, type
);
6597 case RID_CILK_SPAWN
:
6599 location_t cilk_spawn_loc
6600 = cp_lexer_peek_token (parser
->lexer
)->location
;
6601 cp_lexer_consume_token (parser
->lexer
);
6602 token
= cp_lexer_peek_token (parser
->lexer
);
6603 if (token
->type
== CPP_SEMICOLON
)
6605 error_at (token
->location
, "%<_Cilk_spawn%> must be followed by "
6607 postfix_expression
= error_mark_node
;
6610 else if (!current_function_decl
)
6612 error_at (token
->location
, "%<_Cilk_spawn%> may only be used "
6613 "inside a function");
6614 postfix_expression
= error_mark_node
;
6619 /* Consecutive _Cilk_spawns are not allowed in a statement. */
6620 saved_in_statement
= parser
->in_statement
;
6621 parser
->in_statement
|= IN_CILK_SPAWN
;
6623 cfun
->calls_cilk_spawn
= 1;
6624 postfix_expression
=
6625 cp_parser_postfix_expression (parser
, false, false,
6626 false, false, &idk
);
6629 error_at (token
->location
, "-fcilkplus must be enabled to use"
6630 " %<_Cilk_spawn%>");
6631 cfun
->calls_cilk_spawn
= 0;
6633 else if (saved_in_statement
& IN_CILK_SPAWN
)
6635 error_at (token
->location
, "consecutive %<_Cilk_spawn%> keywords "
6636 "are not permitted");
6637 postfix_expression
= error_mark_node
;
6638 cfun
->calls_cilk_spawn
= 0;
6642 location_t loc
= postfix_expression
.get_location ();
6643 postfix_expression
= build_cilk_spawn (token
->location
,
6644 postfix_expression
);
6645 /* Build a location of the form:
6648 with caret at the expr, ranging from the start of the
6649 _Cilk_spawn token to the end of the expression. */
6650 location_t combined_loc
=
6651 make_location (loc
, cilk_spawn_loc
, get_finish (loc
));
6652 postfix_expression
.set_location (combined_loc
);
6653 if (postfix_expression
!= error_mark_node
)
6654 SET_EXPR_LOCATION (postfix_expression
, input_location
);
6655 parser
->in_statement
= parser
->in_statement
& ~IN_CILK_SPAWN
;
6661 case RID_BUILTIN_SHUFFLE
:
6662 case RID_BUILTIN_LAUNDER
:
6664 vec
<tree
, va_gc
> *vec
;
6668 cp_lexer_consume_token (parser
->lexer
);
6669 vec
= cp_parser_parenthesized_expression_list (parser
, non_attr
,
6670 /*cast_p=*/false, /*allow_expansion_p=*/true,
6671 /*non_constant_p=*/NULL
);
6674 postfix_expression
= error_mark_node
;
6678 FOR_EACH_VEC_ELT (*vec
, i
, p
)
6684 if (vec
->length () == 1)
6686 = cp_build_addressof (loc
, (*vec
)[0], tf_warning_or_error
);
6689 error_at (loc
, "wrong number of arguments to "
6690 "%<__builtin_addressof%>");
6691 postfix_expression
= error_mark_node
;
6695 case RID_BUILTIN_LAUNDER
:
6696 if (vec
->length () == 1)
6697 postfix_expression
= finish_builtin_launder (loc
, (*vec
)[0],
6698 tf_warning_or_error
);
6701 error_at (loc
, "wrong number of arguments to "
6702 "%<__builtin_launder%>");
6703 postfix_expression
= error_mark_node
;
6707 case RID_BUILTIN_SHUFFLE
:
6708 if (vec
->length () == 2)
6710 = build_x_vec_perm_expr (loc
, (*vec
)[0], NULL_TREE
,
6711 (*vec
)[1], tf_warning_or_error
);
6712 else if (vec
->length () == 3)
6714 = build_x_vec_perm_expr (loc
, (*vec
)[0], (*vec
)[1],
6715 (*vec
)[2], tf_warning_or_error
);
6718 error_at (loc
, "wrong number of arguments to "
6719 "%<__builtin_shuffle%>");
6720 postfix_expression
= error_mark_node
;
6734 /* If the next thing is a simple-type-specifier, we may be
6735 looking at a functional cast. We could also be looking at
6736 an id-expression. So, we try the functional cast, and if
6737 that doesn't work we fall back to the primary-expression. */
6738 cp_parser_parse_tentatively (parser
);
6739 /* Look for the simple-type-specifier. */
6740 ++parser
->prevent_constrained_type_specifiers
;
6741 type
= cp_parser_simple_type_specifier (parser
,
6742 /*decl_specs=*/NULL
,
6743 CP_PARSER_FLAGS_NONE
);
6744 --parser
->prevent_constrained_type_specifiers
;
6745 /* Parse the cast itself. */
6746 if (!cp_parser_error_occurred (parser
))
6748 = cp_parser_functional_cast (parser
, type
);
6749 /* If that worked, we're done. */
6750 if (cp_parser_parse_definitely (parser
))
6753 /* If the functional-cast didn't work out, try a
6754 compound-literal. */
6755 if (cp_parser_allow_gnu_extensions_p (parser
)
6756 && cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
6758 cp_expr initializer
= NULL_TREE
;
6760 cp_parser_parse_tentatively (parser
);
6762 /* Avoid calling cp_parser_type_id pointlessly, see comment
6763 in cp_parser_cast_expression about c++/29234. */
6764 if (!cp_parser_compound_literal_p (parser
))
6765 cp_parser_simulate_error (parser
);
6768 /* Parse the type. */
6769 bool saved_in_type_id_in_expr_p
= parser
->in_type_id_in_expr_p
;
6770 parser
->in_type_id_in_expr_p
= true;
6771 type
= cp_parser_type_id (parser
);
6772 parser
->in_type_id_in_expr_p
= saved_in_type_id_in_expr_p
;
6773 /* Look for the `)'. */
6774 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
6777 /* If things aren't going well, there's no need to
6779 if (!cp_parser_error_occurred (parser
))
6781 bool non_constant_p
;
6782 /* Parse the brace-enclosed initializer list. */
6783 initializer
= cp_parser_braced_list (parser
,
6786 /* If that worked, we're definitely looking at a
6787 compound-literal expression. */
6788 if (cp_parser_parse_definitely (parser
))
6790 /* Warn the user that a compound literal is not
6791 allowed in standard C++. */
6792 pedwarn (input_location
, OPT_Wpedantic
,
6793 "ISO C++ forbids compound-literals");
6794 /* For simplicity, we disallow compound literals in
6795 constant-expressions. We could
6796 allow compound literals of integer type, whose
6797 initializer was a constant, in constant
6798 expressions. Permitting that usage, as a further
6799 extension, would not change the meaning of any
6800 currently accepted programs. (Of course, as
6801 compound literals are not part of ISO C++, the
6802 standard has nothing to say.) */
6803 if (cp_parser_non_integral_constant_expression (parser
,
6806 postfix_expression
= error_mark_node
;
6809 /* Form the representation of the compound-literal. */
6811 = finish_compound_literal (type
, initializer
,
6812 tf_warning_or_error
, fcl_c99
);
6813 postfix_expression
.set_location (initializer
.get_location ());
6818 /* It must be a primary-expression. */
6820 = cp_parser_primary_expression (parser
, address_p
, cast_p
,
6821 /*template_arg_p=*/false,
6828 /* Note that we don't need to worry about calling build_cplus_new on a
6829 class-valued CALL_EXPR in decltype when it isn't the end of the
6830 postfix-expression; unary_complex_lvalue will take care of that for
6833 /* Keep looping until the postfix-expression is complete. */
6836 if (idk
== CP_ID_KIND_UNQUALIFIED
6837 && identifier_p (postfix_expression
)
6838 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_PAREN
))
6839 /* It is not a Koenig lookup function call. */
6841 = unqualified_name_lookup_error (postfix_expression
);
6843 /* Peek at the next token. */
6844 token
= cp_lexer_peek_token (parser
->lexer
);
6846 switch (token
->type
)
6848 case CPP_OPEN_SQUARE
:
6849 if (cp_next_tokens_can_be_std_attribute_p (parser
))
6851 cp_parser_error (parser
,
6852 "two consecutive %<[%> shall "
6853 "only introduce an attribute");
6854 return error_mark_node
;
6857 = cp_parser_postfix_open_square_expression (parser
,
6861 postfix_expression
.set_range (start_loc
,
6862 postfix_expression
.get_location ());
6864 idk
= CP_ID_KIND_NONE
;
6865 is_member_access
= false;
6868 case CPP_OPEN_PAREN
:
6869 /* postfix-expression ( expression-list [opt] ) */
6872 bool is_builtin_constant_p
;
6873 bool saved_integral_constant_expression_p
= false;
6874 bool saved_non_integral_constant_expression_p
= false;
6875 tsubst_flags_t complain
= complain_flags (decltype_p
);
6876 vec
<tree
, va_gc
> *args
;
6877 location_t close_paren_loc
= UNKNOWN_LOCATION
;
6879 is_member_access
= false;
6881 is_builtin_constant_p
6882 = DECL_IS_BUILTIN_CONSTANT_P (postfix_expression
);
6883 if (is_builtin_constant_p
)
6885 /* The whole point of __builtin_constant_p is to allow
6886 non-constant expressions to appear as arguments. */
6887 saved_integral_constant_expression_p
6888 = parser
->integral_constant_expression_p
;
6889 saved_non_integral_constant_expression_p
6890 = parser
->non_integral_constant_expression_p
;
6891 parser
->integral_constant_expression_p
= false;
6893 args
= (cp_parser_parenthesized_expression_list
6895 /*cast_p=*/false, /*allow_expansion_p=*/true,
6896 /*non_constant_p=*/NULL
,
6897 /*close_paren_loc=*/&close_paren_loc
));
6898 if (is_builtin_constant_p
)
6900 parser
->integral_constant_expression_p
6901 = saved_integral_constant_expression_p
;
6902 parser
->non_integral_constant_expression_p
6903 = saved_non_integral_constant_expression_p
;
6908 postfix_expression
= error_mark_node
;
6912 /* Function calls are not permitted in
6913 constant-expressions. */
6914 if (! builtin_valid_in_constant_expr_p (postfix_expression
)
6915 && cp_parser_non_integral_constant_expression (parser
,
6918 postfix_expression
= error_mark_node
;
6919 release_tree_vector (args
);
6924 if (idk
== CP_ID_KIND_UNQUALIFIED
6925 || idk
== CP_ID_KIND_TEMPLATE_ID
)
6927 if (identifier_p (postfix_expression
))
6929 if (!args
->is_empty ())
6932 if (!any_type_dependent_arguments_p (args
))
6934 = perform_koenig_lookup (postfix_expression
, args
,
6939 = unqualified_fn_lookup_error (postfix_expression
);
6941 /* We do not perform argument-dependent lookup if
6942 normal lookup finds a non-function, in accordance
6943 with the expected resolution of DR 218. */
6944 else if (!args
->is_empty ()
6945 && is_overloaded_fn (postfix_expression
))
6947 tree fn
= get_first_fn (postfix_expression
);
6948 fn
= STRIP_TEMPLATE (fn
);
6950 /* Do not do argument dependent lookup if regular
6951 lookup finds a member function or a block-scope
6952 function declaration. [basic.lookup.argdep]/3 */
6953 if (!DECL_FUNCTION_MEMBER_P (fn
)
6954 && !DECL_LOCAL_FUNCTION_P (fn
))
6957 if (!any_type_dependent_arguments_p (args
))
6959 = perform_koenig_lookup (postfix_expression
, args
,
6965 if (TREE_CODE (postfix_expression
) == FUNCTION_DECL
6966 && DECL_BUILT_IN_CLASS (postfix_expression
) == BUILT_IN_NORMAL
6967 && DECL_FUNCTION_CODE (postfix_expression
) == BUILT_IN_MEMSET
6968 && vec_safe_length (args
) == 3)
6970 tree arg0
= (*args
)[0];
6971 tree arg1
= (*args
)[1];
6972 tree arg2
= (*args
)[2];
6973 int literal_mask
= ((!!integer_zerop (arg1
) << 1)
6974 | (!!integer_zerop (arg2
) << 2));
6975 if (TREE_CODE (arg2
) == CONST_DECL
)
6976 arg2
= DECL_INITIAL (arg2
);
6977 warn_for_memset (input_location
, arg0
, arg2
, literal_mask
);
6980 if (TREE_CODE (postfix_expression
) == COMPONENT_REF
)
6982 tree instance
= TREE_OPERAND (postfix_expression
, 0);
6983 tree fn
= TREE_OPERAND (postfix_expression
, 1);
6985 if (processing_template_decl
6986 && (type_dependent_object_expression_p (instance
)
6987 || (!BASELINK_P (fn
)
6988 && TREE_CODE (fn
) != FIELD_DECL
)
6989 || type_dependent_expression_p (fn
)
6990 || any_type_dependent_arguments_p (args
)))
6992 maybe_generic_this_capture (instance
, fn
);
6994 = build_min_nt_call_vec (postfix_expression
, args
);
6995 release_tree_vector (args
);
6999 if (BASELINK_P (fn
))
7002 = (build_new_method_call
7003 (instance
, fn
, &args
, NULL_TREE
,
7004 (idk
== CP_ID_KIND_QUALIFIED
7005 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
7012 = finish_call_expr (postfix_expression
, &args
,
7013 /*disallow_virtual=*/false,
7017 else if (TREE_CODE (postfix_expression
) == OFFSET_REF
7018 || TREE_CODE (postfix_expression
) == MEMBER_REF
7019 || TREE_CODE (postfix_expression
) == DOTSTAR_EXPR
)
7020 postfix_expression
= (build_offset_ref_call_from_tree
7021 (postfix_expression
, &args
,
7023 else if (idk
== CP_ID_KIND_QUALIFIED
)
7024 /* A call to a static class member, or a namespace-scope
7027 = finish_call_expr (postfix_expression
, &args
,
7028 /*disallow_virtual=*/true,
7032 /* All other function calls. */
7034 = finish_call_expr (postfix_expression
, &args
,
7035 /*disallow_virtual=*/false,
7039 if (close_paren_loc
!= UNKNOWN_LOCATION
)
7041 location_t combined_loc
= make_location (token
->location
,
7044 postfix_expression
.set_location (combined_loc
);
7047 /* The POSTFIX_EXPRESSION is certainly no longer an id. */
7048 idk
= CP_ID_KIND_NONE
;
7050 release_tree_vector (args
);
7056 /* postfix-expression . template [opt] id-expression
7057 postfix-expression . pseudo-destructor-name
7058 postfix-expression -> template [opt] id-expression
7059 postfix-expression -> pseudo-destructor-name */
7061 /* Consume the `.' or `->' operator. */
7062 cp_lexer_consume_token (parser
->lexer
);
7065 = cp_parser_postfix_dot_deref_expression (parser
, token
->type
,
7069 is_member_access
= true;
7073 /* postfix-expression ++ */
7074 /* Consume the `++' token. */
7075 cp_lexer_consume_token (parser
->lexer
);
7076 /* Generate a representation for the complete expression. */
7078 = finish_increment_expr (postfix_expression
,
7079 POSTINCREMENT_EXPR
);
7080 /* Increments may not appear in constant-expressions. */
7081 if (cp_parser_non_integral_constant_expression (parser
, NIC_INC
))
7082 postfix_expression
= error_mark_node
;
7083 idk
= CP_ID_KIND_NONE
;
7084 is_member_access
= false;
7087 case CPP_MINUS_MINUS
:
7088 /* postfix-expression -- */
7089 /* Consume the `--' token. */
7090 cp_lexer_consume_token (parser
->lexer
);
7091 /* Generate a representation for the complete expression. */
7093 = finish_increment_expr (postfix_expression
,
7094 POSTDECREMENT_EXPR
);
7095 /* Decrements may not appear in constant-expressions. */
7096 if (cp_parser_non_integral_constant_expression (parser
, NIC_DEC
))
7097 postfix_expression
= error_mark_node
;
7098 idk
= CP_ID_KIND_NONE
;
7099 is_member_access
= false;
7103 if (pidk_return
!= NULL
)
7104 * pidk_return
= idk
;
7105 if (member_access_only_p
)
7106 return is_member_access
7107 ? postfix_expression
7108 : cp_expr (error_mark_node
);
7110 return postfix_expression
;
7114 /* We should never get here. */
7116 return error_mark_node
;
7119 /* This function parses Cilk Plus array notations. If a normal array expr. is
7120 parsed then the array index is passed back to the caller through *INIT_INDEX
7121 and the function returns a NULL_TREE. If array notation expr. is parsed,
7122 then *INIT_INDEX is ignored by the caller and the function returns
7123 a tree of type ARRAY_NOTATION_REF. If some error occurred it returns
7127 cp_parser_array_notation (location_t loc
, cp_parser
*parser
, tree
*init_index
,
7130 cp_token
*token
= NULL
;
7131 tree length_index
, stride
= NULL_TREE
, value_tree
, array_type
;
7132 if (!array_value
|| array_value
== error_mark_node
)
7134 cp_parser_skip_to_end_of_statement (parser
);
7135 return error_mark_node
;
7138 array_type
= TREE_TYPE (array_value
);
7140 bool saved_colon_corrects
= parser
->colon_corrects_to_scope_p
;
7141 parser
->colon_corrects_to_scope_p
= false;
7142 token
= cp_lexer_peek_token (parser
->lexer
);
7146 cp_parser_error (parser
, "expected %<:%> or numeral");
7147 return error_mark_node
;
7149 else if (token
->type
== CPP_COLON
)
7151 /* Consume the ':'. */
7152 cp_lexer_consume_token (parser
->lexer
);
7154 /* If we are here, then we have a case like this A[:]. */
7155 if (cp_lexer_peek_token (parser
->lexer
)->type
!= CPP_CLOSE_SQUARE
)
7157 cp_parser_error (parser
, "expected %<]%>");
7158 cp_parser_skip_to_end_of_statement (parser
);
7159 return error_mark_node
;
7161 *init_index
= NULL_TREE
;
7163 length_index
= NULL_TREE
;
7167 /* If we are here, then there are three valid possibilities:
7169 2. ARRAY [ EXP : EXP ]
7170 3. ARRAY [ EXP : EXP : EXP ] */
7172 *init_index
= cp_parser_expression (parser
);
7173 if (cp_lexer_peek_token (parser
->lexer
)->type
!= CPP_COLON
)
7175 /* This indicates that we have a normal array expression. */
7176 parser
->colon_corrects_to_scope_p
= saved_colon_corrects
;
7180 /* Consume the ':'. */
7181 cp_lexer_consume_token (parser
->lexer
);
7182 length_index
= cp_parser_expression (parser
);
7183 if (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_COLON
)
7185 cp_lexer_consume_token (parser
->lexer
);
7186 stride
= cp_parser_expression (parser
);
7189 parser
->colon_corrects_to_scope_p
= saved_colon_corrects
;
7191 if (*init_index
== error_mark_node
|| length_index
== error_mark_node
7192 || stride
== error_mark_node
|| array_type
== error_mark_node
)
7194 if (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_CLOSE_SQUARE
)
7195 cp_lexer_consume_token (parser
->lexer
);
7196 return error_mark_node
;
7198 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
7200 value_tree
= build_array_notation_ref (loc
, array_value
, *init_index
,
7201 length_index
, stride
, array_type
);
7205 /* A subroutine of cp_parser_postfix_expression that also gets hijacked
7206 by cp_parser_builtin_offsetof. We're looking for
7208 postfix-expression [ expression ]
7209 postfix-expression [ braced-init-list ] (C++11)
7211 FOR_OFFSETOF is set if we're being called in that context, which
7212 changes how we deal with integer constant expressions. */
7215 cp_parser_postfix_open_square_expression (cp_parser
*parser
,
7216 tree postfix_expression
,
7220 tree index
= NULL_TREE
;
7221 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
7222 bool saved_greater_than_is_operator_p
;
7224 /* Consume the `[' token. */
7225 cp_lexer_consume_token (parser
->lexer
);
7227 saved_greater_than_is_operator_p
= parser
->greater_than_is_operator_p
;
7228 parser
->greater_than_is_operator_p
= true;
7230 /* Parse the index expression. */
7231 /* ??? For offsetof, there is a question of what to allow here. If
7232 offsetof is not being used in an integral constant expression context,
7233 then we *could* get the right answer by computing the value at runtime.
7234 If we are in an integral constant expression context, then we might
7235 could accept any constant expression; hard to say without analysis.
7236 Rather than open the barn door too wide right away, allow only integer
7237 constant expressions here. */
7239 index
= cp_parser_constant_expression (parser
);
7242 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
7244 bool expr_nonconst_p
;
7245 cp_lexer_set_source_position (parser
->lexer
);
7246 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
7247 index
= cp_parser_braced_list (parser
, &expr_nonconst_p
);
7249 && cp_lexer_peek_token (parser
->lexer
)->type
== CPP_COLON
)
7251 error_at (cp_lexer_peek_token (parser
->lexer
)->location
,
7252 "braced list index is not allowed with array "
7254 cp_parser_skip_to_end_of_statement (parser
);
7255 return error_mark_node
;
7258 else if (flag_cilkplus
)
7260 /* Here are have these two options:
7261 ARRAY[EXP : EXP] - Array notation expr with default
7263 ARRAY[EXP : EXP : EXP] - Array Notation with user-defined
7265 tree an_exp
= cp_parser_array_notation (loc
, parser
, &index
,
7266 postfix_expression
);
7271 index
= cp_parser_expression (parser
);
7274 parser
->greater_than_is_operator_p
= saved_greater_than_is_operator_p
;
7276 /* Look for the closing `]'. */
7277 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
7279 /* Build the ARRAY_REF. */
7280 postfix_expression
= grok_array_decl (loc
, postfix_expression
,
7283 /* When not doing offsetof, array references are not permitted in
7284 constant-expressions. */
7286 && (cp_parser_non_integral_constant_expression (parser
, NIC_ARRAY_REF
)))
7287 postfix_expression
= error_mark_node
;
7289 return postfix_expression
;
7292 /* A subroutine of cp_parser_postfix_expression that also gets hijacked
7293 by cp_parser_builtin_offsetof. We're looking for
7295 postfix-expression . template [opt] id-expression
7296 postfix-expression . pseudo-destructor-name
7297 postfix-expression -> template [opt] id-expression
7298 postfix-expression -> pseudo-destructor-name
7300 FOR_OFFSETOF is set if we're being called in that context. That sorta
7301 limits what of the above we'll actually accept, but nevermind.
7302 TOKEN_TYPE is the "." or "->" token, which will already have been
7303 removed from the stream. */
7306 cp_parser_postfix_dot_deref_expression (cp_parser
*parser
,
7307 enum cpp_ttype token_type
,
7308 cp_expr postfix_expression
,
7309 bool for_offsetof
, cp_id_kind
*idk
,
7310 location_t location
)
7314 bool pseudo_destructor_p
;
7315 tree scope
= NULL_TREE
;
7316 location_t start_loc
= postfix_expression
.get_start ();
7318 /* If this is a `->' operator, dereference the pointer. */
7319 if (token_type
== CPP_DEREF
)
7320 postfix_expression
= build_x_arrow (location
, postfix_expression
,
7321 tf_warning_or_error
);
7322 /* Check to see whether or not the expression is type-dependent and
7323 not the current instantiation. */
7324 dependent_p
= type_dependent_object_expression_p (postfix_expression
);
7325 /* The identifier following the `->' or `.' is not qualified. */
7326 parser
->scope
= NULL_TREE
;
7327 parser
->qualifying_scope
= NULL_TREE
;
7328 parser
->object_scope
= NULL_TREE
;
7329 *idk
= CP_ID_KIND_NONE
;
7331 /* Enter the scope corresponding to the type of the object
7332 given by the POSTFIX_EXPRESSION. */
7335 scope
= TREE_TYPE (postfix_expression
);
7336 /* According to the standard, no expression should ever have
7337 reference type. Unfortunately, we do not currently match
7338 the standard in this respect in that our internal representation
7339 of an expression may have reference type even when the standard
7340 says it does not. Therefore, we have to manually obtain the
7341 underlying type here. */
7342 scope
= non_reference (scope
);
7343 /* The type of the POSTFIX_EXPRESSION must be complete. */
7344 /* Unlike the object expression in other contexts, *this is not
7345 required to be of complete type for purposes of class member
7346 access (5.2.5) outside the member function body. */
7347 if (postfix_expression
!= current_class_ref
7348 && scope
!= error_mark_node
7349 && !(processing_template_decl
7350 && current_class_type
7351 && (same_type_ignoring_top_level_qualifiers_p
7352 (scope
, current_class_type
))))
7354 scope
= complete_type (scope
);
7355 if (!COMPLETE_TYPE_P (scope
)
7356 /* Avoid clobbering e.g. OVERLOADs or DECLs. */
7357 && EXPR_P (postfix_expression
))
7359 /* In a template, be permissive by treating an object expression
7360 of incomplete type as dependent (after a pedwarn). */
7361 diagnostic_t kind
= (processing_template_decl
7364 cxx_incomplete_type_diagnostic
7365 (location_of (postfix_expression
),
7366 postfix_expression
, scope
, kind
);
7367 if (processing_template_decl
)
7370 scope
= TREE_TYPE (postfix_expression
) = NULL_TREE
;
7377 /* Let the name lookup machinery know that we are processing a
7378 class member access expression. */
7379 parser
->context
->object_type
= scope
;
7380 /* If something went wrong, we want to be able to discern that case,
7381 as opposed to the case where there was no SCOPE due to the type
7382 of expression being dependent. */
7384 scope
= error_mark_node
;
7385 /* If the SCOPE was erroneous, make the various semantic analysis
7386 functions exit quickly -- and without issuing additional error
7388 if (scope
== error_mark_node
)
7389 postfix_expression
= error_mark_node
;
7394 /* Tell cp_parser_lookup_name that there was an object, even though it's
7396 parser
->context
->object_type
= unknown_type_node
;
7398 /* Assume this expression is not a pseudo-destructor access. */
7399 pseudo_destructor_p
= false;
7401 /* If the SCOPE is a scalar type, then, if this is a valid program,
7402 we must be looking at a pseudo-destructor-name. If POSTFIX_EXPRESSION
7403 is type dependent, it can be pseudo-destructor-name or something else.
7404 Try to parse it as pseudo-destructor-name first. */
7405 if ((scope
&& SCALAR_TYPE_P (scope
)) || dependent_p
)
7410 cp_parser_parse_tentatively (parser
);
7411 /* Parse the pseudo-destructor-name. */
7413 cp_parser_pseudo_destructor_name (parser
, postfix_expression
,
7416 && (cp_parser_error_occurred (parser
)
7417 || !SCALAR_TYPE_P (type
)))
7418 cp_parser_abort_tentative_parse (parser
);
7419 else if (cp_parser_parse_definitely (parser
))
7421 pseudo_destructor_p
= true;
7423 = finish_pseudo_destructor_expr (postfix_expression
,
7428 if (!pseudo_destructor_p
)
7430 /* If the SCOPE is not a scalar type, we are looking at an
7431 ordinary class member access expression, rather than a
7432 pseudo-destructor-name. */
7434 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
7435 /* Parse the id-expression. */
7436 name
= (cp_parser_id_expression
7438 cp_parser_optional_template_keyword (parser
),
7439 /*check_dependency_p=*/true,
7441 /*declarator_p=*/false,
7442 /*optional_p=*/false));
7443 /* In general, build a SCOPE_REF if the member name is qualified.
7444 However, if the name was not dependent and has already been
7445 resolved; there is no need to build the SCOPE_REF. For example;
7447 struct X { void f(); };
7448 template <typename T> void f(T* t) { t->X::f(); }
7450 Even though "t" is dependent, "X::f" is not and has been resolved
7451 to a BASELINK; there is no need to include scope information. */
7453 /* But we do need to remember that there was an explicit scope for
7454 virtual function calls. */
7456 *idk
= CP_ID_KIND_QUALIFIED
;
7458 /* If the name is a template-id that names a type, we will get a
7459 TYPE_DECL here. That is invalid code. */
7460 if (TREE_CODE (name
) == TYPE_DECL
)
7462 error_at (token
->location
, "invalid use of %qD", name
);
7463 postfix_expression
= error_mark_node
;
7467 if (name
!= error_mark_node
&& !BASELINK_P (name
) && parser
->scope
)
7469 if (TREE_CODE (parser
->scope
) == NAMESPACE_DECL
)
7471 error_at (token
->location
, "%<%D::%D%> is not a class member",
7472 parser
->scope
, name
);
7473 postfix_expression
= error_mark_node
;
7476 name
= build_qualified_name (/*type=*/NULL_TREE
,
7480 parser
->scope
= NULL_TREE
;
7481 parser
->qualifying_scope
= NULL_TREE
;
7482 parser
->object_scope
= NULL_TREE
;
7484 if (parser
->scope
&& name
&& BASELINK_P (name
))
7485 adjust_result_of_qualified_name_lookup
7486 (name
, parser
->scope
, scope
);
7488 = finish_class_member_access_expr (postfix_expression
, name
,
7490 tf_warning_or_error
);
7491 /* Build a location e.g.:
7494 where the caret is at the deref token, ranging from
7495 the start of postfix_expression to the end of the access expr. */
7497 = get_finish (cp_lexer_previous_token (parser
->lexer
)->location
);
7498 location_t combined_loc
7499 = make_location (input_location
, start_loc
, end_loc
);
7500 protected_set_expr_location (postfix_expression
, combined_loc
);
7504 /* We no longer need to look up names in the scope of the object on
7505 the left-hand side of the `.' or `->' operator. */
7506 parser
->context
->object_type
= NULL_TREE
;
7508 /* Outside of offsetof, these operators may not appear in
7509 constant-expressions. */
7511 && (cp_parser_non_integral_constant_expression
7512 (parser
, token_type
== CPP_DEREF
? NIC_ARROW
: NIC_POINT
)))
7513 postfix_expression
= error_mark_node
;
7515 return postfix_expression
;
7518 /* Parse a parenthesized expression-list.
7521 assignment-expression
7522 expression-list, assignment-expression
7527 identifier, expression-list
7529 CAST_P is true if this expression is the target of a cast.
7531 ALLOW_EXPANSION_P is true if this expression allows expansion of an
7534 Returns a vector of trees. Each element is a representation of an
7535 assignment-expression. NULL is returned if the ( and or ) are
7536 missing. An empty, but allocated, vector is returned on no
7537 expressions. The parentheses are eaten. IS_ATTRIBUTE_LIST is id_attr
7538 if we are parsing an attribute list for an attribute that wants a
7539 plain identifier argument, normal_attr for an attribute that wants
7540 an expression, or non_attr if we aren't parsing an attribute list. If
7541 NON_CONSTANT_P is non-NULL, *NON_CONSTANT_P indicates whether or
7542 not all of the expressions in the list were constant.
7543 If CLOSE_PAREN_LOC is non-NULL, and no errors occur, then *CLOSE_PAREN_LOC
7544 will be written to with the location of the closing parenthesis. If
7545 an error occurs, it may or may not be written to. */
7547 static vec
<tree
, va_gc
> *
7548 cp_parser_parenthesized_expression_list (cp_parser
* parser
,
7549 int is_attribute_list
,
7551 bool allow_expansion_p
,
7552 bool *non_constant_p
,
7553 location_t
*close_paren_loc
)
7555 vec
<tree
, va_gc
> *expression_list
;
7556 bool fold_expr_p
= is_attribute_list
!= non_attr
;
7557 tree identifier
= NULL_TREE
;
7558 bool saved_greater_than_is_operator_p
;
7560 /* Assume all the expressions will be constant. */
7562 *non_constant_p
= false;
7564 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
7567 expression_list
= make_tree_vector ();
7569 /* Within a parenthesized expression, a `>' token is always
7570 the greater-than operator. */
7571 saved_greater_than_is_operator_p
7572 = parser
->greater_than_is_operator_p
;
7573 parser
->greater_than_is_operator_p
= true;
7575 /* Consume expressions until there are no more. */
7576 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_PAREN
))
7581 /* At the beginning of attribute lists, check to see if the
7582 next token is an identifier. */
7583 if (is_attribute_list
== id_attr
7584 && cp_lexer_peek_token (parser
->lexer
)->type
== CPP_NAME
)
7588 /* Consume the identifier. */
7589 token
= cp_lexer_consume_token (parser
->lexer
);
7590 /* Save the identifier. */
7591 identifier
= token
->u
.value
;
7595 bool expr_non_constant_p
;
7597 /* Parse the next assignment-expression. */
7598 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
7600 /* A braced-init-list. */
7601 cp_lexer_set_source_position (parser
->lexer
);
7602 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
7603 expr
= cp_parser_braced_list (parser
, &expr_non_constant_p
);
7604 if (non_constant_p
&& expr_non_constant_p
)
7605 *non_constant_p
= true;
7607 else if (non_constant_p
)
7609 expr
= (cp_parser_constant_expression
7610 (parser
, /*allow_non_constant_p=*/true,
7611 &expr_non_constant_p
));
7612 if (expr_non_constant_p
)
7613 *non_constant_p
= true;
7616 expr
= cp_parser_assignment_expression (parser
, /*pidk=*/NULL
,
7620 expr
= instantiate_non_dependent_expr (expr
);
7622 /* If we have an ellipsis, then this is an expression
7624 if (allow_expansion_p
7625 && cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
7627 /* Consume the `...'. */
7628 cp_lexer_consume_token (parser
->lexer
);
7630 /* Build the argument pack. */
7631 expr
= make_pack_expansion (expr
);
7634 /* Add it to the list. We add error_mark_node
7635 expressions to the list, so that we can still tell if
7636 the correct form for a parenthesized expression-list
7637 is found. That gives better errors. */
7638 vec_safe_push (expression_list
, expr
);
7640 if (expr
== error_mark_node
)
7644 /* After the first item, attribute lists look the same as
7645 expression lists. */
7646 is_attribute_list
= non_attr
;
7649 /* If the next token isn't a `,', then we are done. */
7650 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
7653 /* Otherwise, consume the `,' and keep going. */
7654 cp_lexer_consume_token (parser
->lexer
);
7657 if (close_paren_loc
)
7658 *close_paren_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
7660 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
7665 /* We try and resync to an unnested comma, as that will give the
7666 user better diagnostics. */
7667 ending
= cp_parser_skip_to_closing_parenthesis (parser
,
7668 /*recovering=*/true,
7670 /*consume_paren=*/true);
7675 parser
->greater_than_is_operator_p
7676 = saved_greater_than_is_operator_p
;
7681 parser
->greater_than_is_operator_p
7682 = saved_greater_than_is_operator_p
;
7685 vec_safe_insert (expression_list
, 0, identifier
);
7687 return expression_list
;
7690 /* Parse a pseudo-destructor-name.
7692 pseudo-destructor-name:
7693 :: [opt] nested-name-specifier [opt] type-name :: ~ type-name
7694 :: [opt] nested-name-specifier template template-id :: ~ type-name
7695 :: [opt] nested-name-specifier [opt] ~ type-name
7697 If either of the first two productions is used, sets *SCOPE to the
7698 TYPE specified before the final `::'. Otherwise, *SCOPE is set to
7699 NULL_TREE. *TYPE is set to the TYPE_DECL for the final type-name,
7700 or ERROR_MARK_NODE if the parse fails. */
7703 cp_parser_pseudo_destructor_name (cp_parser
* parser
,
7708 bool nested_name_specifier_p
;
7711 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMPL
)
7712 && cp_lexer_nth_token_is_keyword (parser
->lexer
, 2, RID_AUTO
)
7713 && !type_dependent_expression_p (object
))
7715 if (cxx_dialect
< cxx14
)
7716 pedwarn (input_location
, 0,
7717 "%<~auto%> only available with "
7718 "-std=c++14 or -std=gnu++14");
7719 cp_lexer_consume_token (parser
->lexer
);
7720 cp_lexer_consume_token (parser
->lexer
);
7722 *type
= TREE_TYPE (object
);
7726 /* Assume that things will not work out. */
7727 *type
= error_mark_node
;
7729 /* Look for the optional `::' operator. */
7730 cp_parser_global_scope_opt (parser
, /*current_scope_valid_p=*/true);
7731 /* Look for the optional nested-name-specifier. */
7732 nested_name_specifier_p
7733 = (cp_parser_nested_name_specifier_opt (parser
,
7734 /*typename_keyword_p=*/false,
7735 /*check_dependency_p=*/true,
7737 /*is_declaration=*/false)
7739 /* Now, if we saw a nested-name-specifier, we might be doing the
7740 second production. */
7741 if (nested_name_specifier_p
7742 && cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TEMPLATE
))
7744 /* Consume the `template' keyword. */
7745 cp_lexer_consume_token (parser
->lexer
);
7746 /* Parse the template-id. */
7747 cp_parser_template_id (parser
,
7748 /*template_keyword_p=*/true,
7749 /*check_dependency_p=*/false,
7751 /*is_declaration=*/true);
7752 /* Look for the `::' token. */
7753 cp_parser_require (parser
, CPP_SCOPE
, RT_SCOPE
);
7755 /* If the next token is not a `~', then there might be some
7756 additional qualification. */
7757 else if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMPL
))
7759 /* At this point, we're looking for "type-name :: ~". The type-name
7760 must not be a class-name, since this is a pseudo-destructor. So,
7761 it must be either an enum-name, or a typedef-name -- both of which
7762 are just identifiers. So, we peek ahead to check that the "::"
7763 and "~" tokens are present; if they are not, then we can avoid
7764 calling type_name. */
7765 if (cp_lexer_peek_token (parser
->lexer
)->type
!= CPP_NAME
7766 || cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
!= CPP_SCOPE
7767 || cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
!= CPP_COMPL
)
7769 cp_parser_error (parser
, "non-scalar type");
7773 /* Look for the type-name. */
7774 *scope
= TREE_TYPE (cp_parser_nonclass_name (parser
));
7775 if (*scope
== error_mark_node
)
7778 /* Look for the `::' token. */
7779 cp_parser_require (parser
, CPP_SCOPE
, RT_SCOPE
);
7784 /* Look for the `~'. */
7785 cp_parser_require (parser
, CPP_COMPL
, RT_COMPL
);
7787 /* Once we see the ~, this has to be a pseudo-destructor. */
7788 if (!processing_template_decl
&& !cp_parser_error_occurred (parser
))
7789 cp_parser_commit_to_topmost_tentative_parse (parser
);
7791 /* Look for the type-name again. We are not responsible for
7792 checking that it matches the first type-name. */
7793 *type
= TREE_TYPE (cp_parser_nonclass_name (parser
));
7796 /* Parse a unary-expression.
7802 unary-operator cast-expression
7803 sizeof unary-expression
7805 alignof ( type-id ) [C++0x]
7812 __extension__ cast-expression
7813 __alignof__ unary-expression
7814 __alignof__ ( type-id )
7815 alignof unary-expression [C++0x]
7816 __real__ cast-expression
7817 __imag__ cast-expression
7819 sizeof ( type-id ) { initializer-list , [opt] }
7820 alignof ( type-id ) { initializer-list , [opt] } [C++0x]
7821 __alignof__ ( type-id ) { initializer-list , [opt] }
7823 ADDRESS_P is true iff the unary-expression is appearing as the
7824 operand of the `&' operator. CAST_P is true if this expression is
7825 the target of a cast.
7827 Returns a representation of the expression. */
7830 cp_parser_unary_expression (cp_parser
*parser
, cp_id_kind
* pidk
,
7831 bool address_p
, bool cast_p
, bool decltype_p
)
7834 enum tree_code unary_operator
;
7836 /* Peek at the next token. */
7837 token
= cp_lexer_peek_token (parser
->lexer
);
7838 /* Some keywords give away the kind of expression. */
7839 if (token
->type
== CPP_KEYWORD
)
7841 enum rid keyword
= token
->keyword
;
7850 location_t start_loc
= token
->location
;
7852 op
= keyword
== RID_ALIGNOF
? ALIGNOF_EXPR
: SIZEOF_EXPR
;
7853 /* Consume the token. */
7854 cp_lexer_consume_token (parser
->lexer
);
7855 /* Parse the operand. */
7856 operand
= cp_parser_sizeof_operand (parser
, keyword
);
7858 if (TYPE_P (operand
))
7859 ret
= cxx_sizeof_or_alignof_type (operand
, op
, true);
7862 /* ISO C++ defines alignof only with types, not with
7863 expressions. So pedwarn if alignof is used with a non-
7864 type expression. However, __alignof__ is ok. */
7865 if (id_equal (token
->u
.value
, "alignof"))
7866 pedwarn (token
->location
, OPT_Wpedantic
,
7867 "ISO C++ does not allow %<alignof%> "
7870 ret
= cxx_sizeof_or_alignof_expr (operand
, op
, true);
7872 /* For SIZEOF_EXPR, just issue diagnostics, but keep
7873 SIZEOF_EXPR with the original operand. */
7874 if (op
== SIZEOF_EXPR
&& ret
!= error_mark_node
)
7876 if (TREE_CODE (ret
) != SIZEOF_EXPR
|| TYPE_P (operand
))
7878 if (!processing_template_decl
&& TYPE_P (operand
))
7880 ret
= build_min (SIZEOF_EXPR
, size_type_node
,
7881 build1 (NOP_EXPR
, operand
,
7883 SIZEOF_EXPR_TYPE_P (ret
) = 1;
7886 ret
= build_min (SIZEOF_EXPR
, size_type_node
, operand
);
7887 TREE_SIDE_EFFECTS (ret
) = 0;
7888 TREE_READONLY (ret
) = 1;
7892 /* Construct a location e.g. :
7895 with start == caret at the start of the "alignof"/"sizeof"
7896 token, with the endpoint at the final closing paren. */
7897 location_t finish_loc
7898 = cp_lexer_previous_token (parser
->lexer
)->location
;
7899 location_t compound_loc
7900 = make_location (start_loc
, start_loc
, finish_loc
);
7902 cp_expr
ret_expr (ret
);
7903 ret_expr
.set_location (compound_loc
);
7908 return cp_parser_new_expression (parser
);
7911 return cp_parser_delete_expression (parser
);
7915 /* The saved value of the PEDANTIC flag. */
7919 /* Save away the PEDANTIC flag. */
7920 cp_parser_extension_opt (parser
, &saved_pedantic
);
7921 /* Parse the cast-expression. */
7922 expr
= cp_parser_simple_cast_expression (parser
);
7923 /* Restore the PEDANTIC flag. */
7924 pedantic
= saved_pedantic
;
7934 /* Consume the `__real__' or `__imag__' token. */
7935 cp_lexer_consume_token (parser
->lexer
);
7936 /* Parse the cast-expression. */
7937 expression
= cp_parser_simple_cast_expression (parser
);
7938 /* Create the complete representation. */
7939 return build_x_unary_op (token
->location
,
7940 (keyword
== RID_REALPART
7941 ? REALPART_EXPR
: IMAGPART_EXPR
),
7943 tf_warning_or_error
);
7947 case RID_TRANSACTION_ATOMIC
:
7948 case RID_TRANSACTION_RELAXED
:
7949 return cp_parser_transaction_expression (parser
, keyword
);
7954 const char *saved_message
;
7955 bool saved_integral_constant_expression_p
;
7956 bool saved_non_integral_constant_expression_p
;
7957 bool saved_greater_than_is_operator_p
;
7959 cp_lexer_consume_token (parser
->lexer
);
7960 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
7962 saved_message
= parser
->type_definition_forbidden_message
;
7963 parser
->type_definition_forbidden_message
7964 = G_("types may not be defined in %<noexcept%> expressions");
7966 saved_integral_constant_expression_p
7967 = parser
->integral_constant_expression_p
;
7968 saved_non_integral_constant_expression_p
7969 = parser
->non_integral_constant_expression_p
;
7970 parser
->integral_constant_expression_p
= false;
7972 saved_greater_than_is_operator_p
7973 = parser
->greater_than_is_operator_p
;
7974 parser
->greater_than_is_operator_p
= true;
7976 ++cp_unevaluated_operand
;
7977 ++c_inhibit_evaluation_warnings
;
7978 ++cp_noexcept_operand
;
7979 expr
= cp_parser_expression (parser
);
7980 --cp_noexcept_operand
;
7981 --c_inhibit_evaluation_warnings
;
7982 --cp_unevaluated_operand
;
7984 parser
->greater_than_is_operator_p
7985 = saved_greater_than_is_operator_p
;
7987 parser
->integral_constant_expression_p
7988 = saved_integral_constant_expression_p
;
7989 parser
->non_integral_constant_expression_p
7990 = saved_non_integral_constant_expression_p
;
7992 parser
->type_definition_forbidden_message
= saved_message
;
7994 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
7995 return finish_noexcept_expr (expr
, tf_warning_or_error
);
8003 /* Look for the `:: new' and `:: delete', which also signal the
8004 beginning of a new-expression, or delete-expression,
8005 respectively. If the next token is `::', then it might be one of
8007 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SCOPE
))
8011 /* See if the token after the `::' is one of the keywords in
8012 which we're interested. */
8013 keyword
= cp_lexer_peek_nth_token (parser
->lexer
, 2)->keyword
;
8014 /* If it's `new', we have a new-expression. */
8015 if (keyword
== RID_NEW
)
8016 return cp_parser_new_expression (parser
);
8017 /* Similarly, for `delete'. */
8018 else if (keyword
== RID_DELETE
)
8019 return cp_parser_delete_expression (parser
);
8022 /* Look for a unary operator. */
8023 unary_operator
= cp_parser_unary_operator (token
);
8024 /* The `++' and `--' operators can be handled similarly, even though
8025 they are not technically unary-operators in the grammar. */
8026 if (unary_operator
== ERROR_MARK
)
8028 if (token
->type
== CPP_PLUS_PLUS
)
8029 unary_operator
= PREINCREMENT_EXPR
;
8030 else if (token
->type
== CPP_MINUS_MINUS
)
8031 unary_operator
= PREDECREMENT_EXPR
;
8032 /* Handle the GNU address-of-label extension. */
8033 else if (cp_parser_allow_gnu_extensions_p (parser
)
8034 && token
->type
== CPP_AND_AND
)
8038 location_t start_loc
= token
->location
;
8040 /* Consume the '&&' token. */
8041 cp_lexer_consume_token (parser
->lexer
);
8042 /* Look for the identifier. */
8043 location_t finish_loc
8044 = get_finish (cp_lexer_peek_token (parser
->lexer
)->location
);
8045 identifier
= cp_parser_identifier (parser
);
8046 /* Construct a location of the form:
8049 with caret==start at the "&&", finish at the end of the label. */
8050 location_t combined_loc
8051 = make_location (start_loc
, start_loc
, finish_loc
);
8052 /* Create an expression representing the address. */
8053 expression
= finish_label_address_expr (identifier
, combined_loc
);
8054 if (cp_parser_non_integral_constant_expression (parser
,
8056 expression
= error_mark_node
;
8060 if (unary_operator
!= ERROR_MARK
)
8062 cp_expr cast_expression
;
8063 cp_expr expression
= error_mark_node
;
8064 non_integral_constant non_constant_p
= NIC_NONE
;
8065 location_t loc
= token
->location
;
8066 tsubst_flags_t complain
= complain_flags (decltype_p
);
8068 /* Consume the operator token. */
8069 token
= cp_lexer_consume_token (parser
->lexer
);
8070 enum cpp_ttype op_ttype
= cp_lexer_peek_token (parser
->lexer
)->type
;
8072 /* Parse the cast-expression. */
8074 = cp_parser_cast_expression (parser
,
8075 unary_operator
== ADDR_EXPR
,
8081 OP_TOKEN CAST_EXPRESSION
8082 ^~~~~~~~~~~~~~~~~~~~~~~~~
8083 with start==caret at the operator token, and
8084 extending to the end of the cast_expression. */
8085 loc
= make_location (loc
, loc
, cast_expression
.get_finish ());
8087 /* Now, build an appropriate representation. */
8088 switch (unary_operator
)
8091 non_constant_p
= NIC_STAR
;
8092 expression
= build_x_indirect_ref (loc
, cast_expression
,
8095 /* TODO: build_x_indirect_ref does not always honor the
8096 location, so ensure it is set. */
8097 expression
.set_location (loc
);
8101 non_constant_p
= NIC_ADDR
;
8104 expression
= build_x_unary_op (loc
, unary_operator
,
8107 /* TODO: build_x_unary_op does not always honor the location,
8108 so ensure it is set. */
8109 expression
.set_location (loc
);
8112 case PREINCREMENT_EXPR
:
8113 case PREDECREMENT_EXPR
:
8114 non_constant_p
= unary_operator
== PREINCREMENT_EXPR
8115 ? NIC_PREINCREMENT
: NIC_PREDECREMENT
;
8118 /* Immediately fold negation of a constant, unless the constant is 0
8119 (since -0 == 0) or it would overflow. */
8120 if (unary_operator
== NEGATE_EXPR
&& op_ttype
== CPP_NUMBER
8121 && CONSTANT_CLASS_P (cast_expression
)
8122 && !integer_zerop (cast_expression
)
8123 && !TREE_OVERFLOW (cast_expression
))
8125 tree folded
= fold_build1 (unary_operator
,
8126 TREE_TYPE (cast_expression
),
8128 if (CONSTANT_CLASS_P (folded
) && !TREE_OVERFLOW (folded
))
8130 expression
= cp_expr (folded
, loc
);
8135 case UNARY_PLUS_EXPR
:
8136 case TRUTH_NOT_EXPR
:
8137 expression
= finish_unary_op_expr (loc
, unary_operator
,
8138 cast_expression
, complain
);
8145 if (non_constant_p
!= NIC_NONE
8146 && cp_parser_non_integral_constant_expression (parser
,
8148 expression
= error_mark_node
;
8153 return cp_parser_postfix_expression (parser
, address_p
, cast_p
,
8154 /*member_access_only_p=*/false,
8159 /* Returns ERROR_MARK if TOKEN is not a unary-operator. If TOKEN is a
8160 unary-operator, the corresponding tree code is returned. */
8162 static enum tree_code
8163 cp_parser_unary_operator (cp_token
* token
)
8165 switch (token
->type
)
8168 return INDIRECT_REF
;
8174 return UNARY_PLUS_EXPR
;
8180 return TRUTH_NOT_EXPR
;
8183 return BIT_NOT_EXPR
;
8190 /* Parse a new-expression.
8193 :: [opt] new new-placement [opt] new-type-id new-initializer [opt]
8194 :: [opt] new new-placement [opt] ( type-id ) new-initializer [opt]
8196 Returns a representation of the expression. */
8199 cp_parser_new_expression (cp_parser
* parser
)
8201 bool global_scope_p
;
8202 vec
<tree
, va_gc
> *placement
;
8204 vec
<tree
, va_gc
> *initializer
;
8205 tree nelts
= NULL_TREE
;
8208 location_t start_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
8210 /* Look for the optional `::' operator. */
8212 = (cp_parser_global_scope_opt (parser
,
8213 /*current_scope_valid_p=*/false)
8215 /* Look for the `new' operator. */
8216 cp_parser_require_keyword (parser
, RID_NEW
, RT_NEW
);
8217 /* There's no easy way to tell a new-placement from the
8218 `( type-id )' construct. */
8219 cp_parser_parse_tentatively (parser
);
8220 /* Look for a new-placement. */
8221 placement
= cp_parser_new_placement (parser
);
8222 /* If that didn't work out, there's no new-placement. */
8223 if (!cp_parser_parse_definitely (parser
))
8225 if (placement
!= NULL
)
8226 release_tree_vector (placement
);
8230 /* If the next token is a `(', then we have a parenthesized
8232 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
8235 const char *saved_message
= parser
->type_definition_forbidden_message
;
8237 /* Consume the `('. */
8238 cp_lexer_consume_token (parser
->lexer
);
8240 /* Parse the type-id. */
8241 parser
->type_definition_forbidden_message
8242 = G_("types may not be defined in a new-expression");
8244 type_id_in_expr_sentinel
s (parser
);
8245 type
= cp_parser_type_id (parser
);
8247 parser
->type_definition_forbidden_message
= saved_message
;
8249 /* Look for the closing `)'. */
8250 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
8251 token
= cp_lexer_peek_token (parser
->lexer
);
8252 /* There should not be a direct-new-declarator in this production,
8253 but GCC used to allowed this, so we check and emit a sensible error
8254 message for this case. */
8255 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_SQUARE
))
8257 error_at (token
->location
,
8258 "array bound forbidden after parenthesized type-id");
8259 inform (token
->location
,
8260 "try removing the parentheses around the type-id");
8261 cp_parser_direct_new_declarator (parser
);
8264 /* Otherwise, there must be a new-type-id. */
8266 type
= cp_parser_new_type_id (parser
, &nelts
);
8268 /* If the next token is a `(' or '{', then we have a new-initializer. */
8269 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
8270 if (token
->type
== CPP_OPEN_PAREN
8271 || token
->type
== CPP_OPEN_BRACE
)
8272 initializer
= cp_parser_new_initializer (parser
);
8276 /* A new-expression may not appear in an integral constant
8278 if (cp_parser_non_integral_constant_expression (parser
, NIC_NEW
))
8279 ret
= error_mark_node
;
8280 /* 5.3.4/2: "If the auto type-specifier appears in the type-specifier-seq
8281 of a new-type-id or type-id of a new-expression, the new-expression shall
8282 contain a new-initializer of the form ( assignment-expression )".
8283 Additionally, consistently with the spirit of DR 1467, we want to accept
8284 'new auto { 2 }' too. */
8285 else if ((ret
= type_uses_auto (type
))
8286 && !CLASS_PLACEHOLDER_TEMPLATE (ret
)
8287 && (vec_safe_length (initializer
) != 1
8288 || (BRACE_ENCLOSED_INITIALIZER_P ((*initializer
)[0])
8289 && CONSTRUCTOR_NELTS ((*initializer
)[0]) != 1)))
8291 error_at (token
->location
,
8292 "initialization of new-expression for type %<auto%> "
8293 "requires exactly one element");
8294 ret
= error_mark_node
;
8298 /* Construct a location e.g.:
8301 with caret == start at the start of the "new" token, and the end
8302 at the end of the final token we consumed. */
8303 cp_token
*end_tok
= cp_lexer_previous_token (parser
->lexer
);
8304 location_t end_loc
= get_finish (end_tok
->location
);
8305 location_t combined_loc
= make_location (start_loc
, start_loc
, end_loc
);
8307 /* Create a representation of the new-expression. */
8308 ret
= build_new (&placement
, type
, nelts
, &initializer
, global_scope_p
,
8309 tf_warning_or_error
);
8310 protected_set_expr_location (ret
, combined_loc
);
8313 if (placement
!= NULL
)
8314 release_tree_vector (placement
);
8315 if (initializer
!= NULL
)
8316 release_tree_vector (initializer
);
8321 /* Parse a new-placement.
8326 Returns the same representation as for an expression-list. */
8328 static vec
<tree
, va_gc
> *
8329 cp_parser_new_placement (cp_parser
* parser
)
8331 vec
<tree
, va_gc
> *expression_list
;
8333 /* Parse the expression-list. */
8334 expression_list
= (cp_parser_parenthesized_expression_list
8335 (parser
, non_attr
, /*cast_p=*/false,
8336 /*allow_expansion_p=*/true,
8337 /*non_constant_p=*/NULL
));
8339 if (expression_list
&& expression_list
->is_empty ())
8340 error ("expected expression-list or type-id");
8342 return expression_list
;
8345 /* Parse a new-type-id.
8348 type-specifier-seq new-declarator [opt]
8350 Returns the TYPE allocated. If the new-type-id indicates an array
8351 type, *NELTS is set to the number of elements in the last array
8352 bound; the TYPE will not include the last array bound. */
8355 cp_parser_new_type_id (cp_parser
* parser
, tree
*nelts
)
8357 cp_decl_specifier_seq type_specifier_seq
;
8358 cp_declarator
*new_declarator
;
8359 cp_declarator
*declarator
;
8360 cp_declarator
*outer_declarator
;
8361 const char *saved_message
;
8363 /* The type-specifier sequence must not contain type definitions.
8364 (It cannot contain declarations of new types either, but if they
8365 are not definitions we will catch that because they are not
8367 saved_message
= parser
->type_definition_forbidden_message
;
8368 parser
->type_definition_forbidden_message
8369 = G_("types may not be defined in a new-type-id");
8370 /* Parse the type-specifier-seq. */
8371 cp_parser_type_specifier_seq (parser
, /*is_declaration=*/false,
8372 /*is_trailing_return=*/false,
8373 &type_specifier_seq
);
8374 /* Restore the old message. */
8375 parser
->type_definition_forbidden_message
= saved_message
;
8377 if (type_specifier_seq
.type
== error_mark_node
)
8378 return error_mark_node
;
8380 /* Parse the new-declarator. */
8381 new_declarator
= cp_parser_new_declarator_opt (parser
);
8383 /* Determine the number of elements in the last array dimension, if
8386 /* Skip down to the last array dimension. */
8387 declarator
= new_declarator
;
8388 outer_declarator
= NULL
;
8389 while (declarator
&& (declarator
->kind
== cdk_pointer
8390 || declarator
->kind
== cdk_ptrmem
))
8392 outer_declarator
= declarator
;
8393 declarator
= declarator
->declarator
;
8396 && declarator
->kind
== cdk_array
8397 && declarator
->declarator
8398 && declarator
->declarator
->kind
== cdk_array
)
8400 outer_declarator
= declarator
;
8401 declarator
= declarator
->declarator
;
8404 if (declarator
&& declarator
->kind
== cdk_array
)
8406 *nelts
= declarator
->u
.array
.bounds
;
8407 if (*nelts
== error_mark_node
)
8408 *nelts
= integer_one_node
;
8410 if (outer_declarator
)
8411 outer_declarator
->declarator
= declarator
->declarator
;
8413 new_declarator
= NULL
;
8416 return groktypename (&type_specifier_seq
, new_declarator
, false);
8419 /* Parse an (optional) new-declarator.
8422 ptr-operator new-declarator [opt]
8423 direct-new-declarator
8425 Returns the declarator. */
8427 static cp_declarator
*
8428 cp_parser_new_declarator_opt (cp_parser
* parser
)
8430 enum tree_code code
;
8431 tree type
, std_attributes
= NULL_TREE
;
8432 cp_cv_quals cv_quals
;
8434 /* We don't know if there's a ptr-operator next, or not. */
8435 cp_parser_parse_tentatively (parser
);
8436 /* Look for a ptr-operator. */
8437 code
= cp_parser_ptr_operator (parser
, &type
, &cv_quals
, &std_attributes
);
8438 /* If that worked, look for more new-declarators. */
8439 if (cp_parser_parse_definitely (parser
))
8441 cp_declarator
*declarator
;
8443 /* Parse another optional declarator. */
8444 declarator
= cp_parser_new_declarator_opt (parser
);
8446 declarator
= cp_parser_make_indirect_declarator
8447 (code
, type
, cv_quals
, declarator
, std_attributes
);
8452 /* If the next token is a `[', there is a direct-new-declarator. */
8453 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_SQUARE
))
8454 return cp_parser_direct_new_declarator (parser
);
8459 /* Parse a direct-new-declarator.
8461 direct-new-declarator:
8463 direct-new-declarator [constant-expression]
8467 static cp_declarator
*
8468 cp_parser_direct_new_declarator (cp_parser
* parser
)
8470 cp_declarator
*declarator
= NULL
;
8477 /* Look for the opening `['. */
8478 cp_parser_require (parser
, CPP_OPEN_SQUARE
, RT_OPEN_SQUARE
);
8480 token
= cp_lexer_peek_token (parser
->lexer
);
8481 expression
= cp_parser_expression (parser
);
8482 /* The standard requires that the expression have integral
8483 type. DR 74 adds enumeration types. We believe that the
8484 real intent is that these expressions be handled like the
8485 expression in a `switch' condition, which also allows
8486 classes with a single conversion to integral or
8487 enumeration type. */
8488 if (!processing_template_decl
)
8491 = build_expr_type_conversion (WANT_INT
| WANT_ENUM
,
8496 error_at (token
->location
,
8497 "expression in new-declarator must have integral "
8498 "or enumeration type");
8499 expression
= error_mark_node
;
8503 /* Look for the closing `]'. */
8504 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
8506 /* Add this bound to the declarator. */
8507 declarator
= make_array_declarator (declarator
, expression
);
8509 /* If the next token is not a `[', then there are no more
8511 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_SQUARE
))
8518 /* Parse a new-initializer.
8521 ( expression-list [opt] )
8524 Returns a representation of the expression-list. */
8526 static vec
<tree
, va_gc
> *
8527 cp_parser_new_initializer (cp_parser
* parser
)
8529 vec
<tree
, va_gc
> *expression_list
;
8531 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
8534 bool expr_non_constant_p
;
8535 cp_lexer_set_source_position (parser
->lexer
);
8536 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
8537 t
= cp_parser_braced_list (parser
, &expr_non_constant_p
);
8538 CONSTRUCTOR_IS_DIRECT_INIT (t
) = 1;
8539 expression_list
= make_tree_vector_single (t
);
8542 expression_list
= (cp_parser_parenthesized_expression_list
8543 (parser
, non_attr
, /*cast_p=*/false,
8544 /*allow_expansion_p=*/true,
8545 /*non_constant_p=*/NULL
));
8547 return expression_list
;
8550 /* Parse a delete-expression.
8553 :: [opt] delete cast-expression
8554 :: [opt] delete [ ] cast-expression
8556 Returns a representation of the expression. */
8559 cp_parser_delete_expression (cp_parser
* parser
)
8561 bool global_scope_p
;
8565 /* Look for the optional `::' operator. */
8567 = (cp_parser_global_scope_opt (parser
,
8568 /*current_scope_valid_p=*/false)
8570 /* Look for the `delete' keyword. */
8571 cp_parser_require_keyword (parser
, RID_DELETE
, RT_DELETE
);
8572 /* See if the array syntax is in use. */
8573 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_SQUARE
))
8575 /* Consume the `[' token. */
8576 cp_lexer_consume_token (parser
->lexer
);
8577 /* Look for the `]' token. */
8578 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
8579 /* Remember that this is the `[]' construct. */
8585 /* Parse the cast-expression. */
8586 expression
= cp_parser_simple_cast_expression (parser
);
8588 /* A delete-expression may not appear in an integral constant
8590 if (cp_parser_non_integral_constant_expression (parser
, NIC_DEL
))
8591 return error_mark_node
;
8593 return delete_sanity (expression
, NULL_TREE
, array_p
, global_scope_p
,
8594 tf_warning_or_error
);
8597 /* Returns 1 if TOKEN may start a cast-expression and isn't '++', '--',
8598 neither '[' in C++11; -1 if TOKEN is '++', '--', or '[' in C++11;
8602 cp_parser_tokens_start_cast_expression (cp_parser
*parser
)
8604 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
8605 switch (token
->type
)
8611 case CPP_CLOSE_SQUARE
:
8612 case CPP_CLOSE_PAREN
:
8613 case CPP_CLOSE_BRACE
:
8614 case CPP_OPEN_BRACE
:
8618 case CPP_DEREF_STAR
:
8626 case CPP_GREATER_EQ
:
8647 case CPP_OPEN_PAREN
:
8648 /* In ((type ()) () the last () isn't a valid cast-expression,
8649 so the whole must be parsed as postfix-expression. */
8650 return cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
8653 case CPP_OPEN_SQUARE
:
8654 /* '[' may start a primary-expression in obj-c++ and in C++11,
8655 as a lambda-expression, eg, '(void)[]{}'. */
8656 if (cxx_dialect
>= cxx11
)
8658 return c_dialect_objc ();
8661 case CPP_MINUS_MINUS
:
8662 /* '++' and '--' may or may not start a cast-expression:
8664 struct T { void operator++(int); };
8665 void f() { (T())++; }
8678 /* Try to find a legal C++-style cast to DST_TYPE for ORIG_EXPR, trying them
8679 in the order: const_cast, static_cast, reinterpret_cast.
8681 Don't suggest dynamic_cast.
8683 Return the first legal cast kind found, or NULL otherwise. */
8686 get_cast_suggestion (tree dst_type
, tree orig_expr
)
8690 /* Reuse the parser logic by attempting to build the various kinds of
8691 cast, with "complain" disabled.
8692 Identify the first such cast that is valid. */
8694 /* Don't attempt to run such logic within template processing. */
8695 if (processing_template_decl
)
8698 /* First try const_cast. */
8699 trial
= build_const_cast (dst_type
, orig_expr
, tf_none
);
8700 if (trial
!= error_mark_node
)
8701 return "const_cast";
8703 /* If that fails, try static_cast. */
8704 trial
= build_static_cast (dst_type
, orig_expr
, tf_none
);
8705 if (trial
!= error_mark_node
)
8706 return "static_cast";
8708 /* Finally, try reinterpret_cast. */
8709 trial
= build_reinterpret_cast (dst_type
, orig_expr
, tf_none
);
8710 if (trial
!= error_mark_node
)
8711 return "reinterpret_cast";
8713 /* No such cast possible. */
8717 /* If -Wold-style-cast is enabled, add fix-its to RICHLOC,
8718 suggesting how to convert a C-style cast of the form:
8722 to a C++-style cast.
8724 The primary range of RICHLOC is asssumed to be that of the original
8725 expression. OPEN_PAREN_LOC and CLOSE_PAREN_LOC give the locations
8726 of the parens in the C-style cast. */
8729 maybe_add_cast_fixit (rich_location
*rich_loc
, location_t open_paren_loc
,
8730 location_t close_paren_loc
, tree orig_expr
,
8733 /* This function is non-trivial, so bail out now if the warning isn't
8734 going to be emitted. */
8735 if (!warn_old_style_cast
)
8738 /* Try to find a legal C++ cast, trying them in order:
8739 const_cast, static_cast, reinterpret_cast. */
8740 const char *cast_suggestion
= get_cast_suggestion (dst_type
, orig_expr
);
8741 if (!cast_suggestion
)
8744 /* Replace the open paren with "CAST_SUGGESTION<". */
8746 pp_printf (&pp
, "%s<", cast_suggestion
);
8747 rich_loc
->add_fixit_replace (open_paren_loc
, pp_formatted_text (&pp
));
8749 /* Replace the close paren with "> (". */
8750 rich_loc
->add_fixit_replace (close_paren_loc
, "> (");
8752 /* Add a closing paren after the expr (the primary range of RICH_LOC). */
8753 rich_loc
->add_fixit_insert_after (")");
8757 /* Parse a cast-expression.
8761 ( type-id ) cast-expression
8763 ADDRESS_P is true iff the unary-expression is appearing as the
8764 operand of the `&' operator. CAST_P is true if this expression is
8765 the target of a cast.
8767 Returns a representation of the expression. */
8770 cp_parser_cast_expression (cp_parser
*parser
, bool address_p
, bool cast_p
,
8771 bool decltype_p
, cp_id_kind
* pidk
)
8773 /* If it's a `(', then we might be looking at a cast. */
8774 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
8776 tree type
= NULL_TREE
;
8777 cp_expr
expr (NULL_TREE
);
8778 int cast_expression
= 0;
8779 const char *saved_message
;
8781 /* There's no way to know yet whether or not this is a cast.
8782 For example, `(int (3))' is a unary-expression, while `(int)
8783 3' is a cast. So, we resort to parsing tentatively. */
8784 cp_parser_parse_tentatively (parser
);
8785 /* Types may not be defined in a cast. */
8786 saved_message
= parser
->type_definition_forbidden_message
;
8787 parser
->type_definition_forbidden_message
8788 = G_("types may not be defined in casts");
8789 /* Consume the `('. */
8790 cp_token
*open_paren
= cp_lexer_consume_token (parser
->lexer
);
8791 location_t open_paren_loc
= open_paren
->location
;
8792 location_t close_paren_loc
= UNKNOWN_LOCATION
;
8794 /* A very tricky bit is that `(struct S) { 3 }' is a
8795 compound-literal (which we permit in C++ as an extension).
8796 But, that construct is not a cast-expression -- it is a
8797 postfix-expression. (The reason is that `(struct S) { 3 }.i'
8798 is legal; if the compound-literal were a cast-expression,
8799 you'd need an extra set of parentheses.) But, if we parse
8800 the type-id, and it happens to be a class-specifier, then we
8801 will commit to the parse at that point, because we cannot
8802 undo the action that is done when creating a new class. So,
8803 then we cannot back up and do a postfix-expression.
8805 Another tricky case is the following (c++/29234):
8807 struct S { void operator () (); };
8814 As a type-id we parse the parenthesized S()() as a function
8815 returning a function, groktypename complains and we cannot
8816 back up in this case either.
8818 Therefore, we scan ahead to the closing `)', and check to see
8819 if the tokens after the `)' can start a cast-expression. Otherwise
8820 we are dealing with an unary-expression, a postfix-expression
8823 Yet another tricky case, in C++11, is the following (c++/54891):
8827 The issue is that usually, besides the case of lambda-expressions,
8828 the parenthesized type-id cannot be followed by '[', and, eg, we
8829 want to parse '(C ())[2];' in parse/pr26997.C as unary-expression.
8830 Thus, if cp_parser_tokens_start_cast_expression returns -1, below
8831 we don't commit, we try a cast-expression, then an unary-expression.
8833 Save tokens so that we can put them back. */
8834 cp_lexer_save_tokens (parser
->lexer
);
8836 /* We may be looking at a cast-expression. */
8837 if (cp_parser_skip_to_closing_parenthesis (parser
, false, false,
8838 /*consume_paren=*/true))
8840 = cp_parser_tokens_start_cast_expression (parser
);
8842 /* Roll back the tokens we skipped. */
8843 cp_lexer_rollback_tokens (parser
->lexer
);
8844 /* If we aren't looking at a cast-expression, simulate an error so
8845 that the call to cp_parser_error_occurred below returns true. */
8846 if (!cast_expression
)
8847 cp_parser_simulate_error (parser
);
8850 bool saved_in_type_id_in_expr_p
= parser
->in_type_id_in_expr_p
;
8851 parser
->in_type_id_in_expr_p
= true;
8852 /* Look for the type-id. */
8853 type
= cp_parser_type_id (parser
);
8854 /* Look for the closing `)'. */
8855 cp_token
*close_paren
8856 = cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
8858 close_paren_loc
= close_paren
->location
;
8859 parser
->in_type_id_in_expr_p
= saved_in_type_id_in_expr_p
;
8862 /* Restore the saved message. */
8863 parser
->type_definition_forbidden_message
= saved_message
;
8865 /* At this point this can only be either a cast or a
8866 parenthesized ctor such as `(T ())' that looks like a cast to
8867 function returning T. */
8868 if (!cp_parser_error_occurred (parser
))
8870 /* Only commit if the cast-expression doesn't start with
8871 '++', '--', or '[' in C++11. */
8872 if (cast_expression
> 0)
8873 cp_parser_commit_to_topmost_tentative_parse (parser
);
8875 expr
= cp_parser_cast_expression (parser
,
8876 /*address_p=*/false,
8878 /*decltype_p=*/false,
8881 if (cp_parser_parse_definitely (parser
))
8883 /* Warn about old-style casts, if so requested. */
8884 if (warn_old_style_cast
8885 && !in_system_header_at (input_location
)
8886 && !VOID_TYPE_P (type
)
8887 && current_lang_name
!= lang_name_c
)
8889 gcc_rich_location
rich_loc (input_location
);
8890 maybe_add_cast_fixit (&rich_loc
, open_paren_loc
, close_paren_loc
,
8892 warning_at_rich_loc (&rich_loc
, OPT_Wold_style_cast
,
8893 "use of old-style cast to %qT", type
);
8896 /* Only type conversions to integral or enumeration types
8897 can be used in constant-expressions. */
8898 if (!cast_valid_in_integral_constant_expression_p (type
)
8899 && cp_parser_non_integral_constant_expression (parser
,
8901 return error_mark_node
;
8903 /* Perform the cast. */
8907 with start==caret at the open paren, extending to the
8909 location_t cast_loc
= make_location (open_paren_loc
,
8911 expr
.get_finish ());
8912 expr
= build_c_cast (cast_loc
, type
, expr
);
8917 cp_parser_abort_tentative_parse (parser
);
8920 /* If we get here, then it's not a cast, so it must be a
8921 unary-expression. */
8922 return cp_parser_unary_expression (parser
, pidk
, address_p
,
8923 cast_p
, decltype_p
);
8926 /* Parse a binary expression of the general form:
8930 pm-expression .* cast-expression
8931 pm-expression ->* cast-expression
8933 multiplicative-expression:
8935 multiplicative-expression * pm-expression
8936 multiplicative-expression / pm-expression
8937 multiplicative-expression % pm-expression
8939 additive-expression:
8940 multiplicative-expression
8941 additive-expression + multiplicative-expression
8942 additive-expression - multiplicative-expression
8946 shift-expression << additive-expression
8947 shift-expression >> additive-expression
8949 relational-expression:
8951 relational-expression < shift-expression
8952 relational-expression > shift-expression
8953 relational-expression <= shift-expression
8954 relational-expression >= shift-expression
8958 relational-expression:
8959 relational-expression <? shift-expression
8960 relational-expression >? shift-expression
8962 equality-expression:
8963 relational-expression
8964 equality-expression == relational-expression
8965 equality-expression != relational-expression
8969 and-expression & equality-expression
8971 exclusive-or-expression:
8973 exclusive-or-expression ^ and-expression
8975 inclusive-or-expression:
8976 exclusive-or-expression
8977 inclusive-or-expression | exclusive-or-expression
8979 logical-and-expression:
8980 inclusive-or-expression
8981 logical-and-expression && inclusive-or-expression
8983 logical-or-expression:
8984 logical-and-expression
8985 logical-or-expression || logical-and-expression
8987 All these are implemented with a single function like:
8990 simple-cast-expression
8991 binary-expression <token> binary-expression
8993 CAST_P is true if this expression is the target of a cast.
8995 The binops_by_token map is used to get the tree codes for each <token> type.
8996 binary-expressions are associated according to a precedence table. */
8998 #define TOKEN_PRECEDENCE(token) \
8999 (((token->type == CPP_GREATER \
9000 || ((cxx_dialect != cxx98) && token->type == CPP_RSHIFT)) \
9001 && !parser->greater_than_is_operator_p) \
9002 ? PREC_NOT_OPERATOR \
9003 : binops_by_token[token->type].prec)
9006 cp_parser_binary_expression (cp_parser
* parser
, bool cast_p
,
9007 bool no_toplevel_fold_p
,
9009 enum cp_parser_prec prec
,
9012 cp_parser_expression_stack stack
;
9013 cp_parser_expression_stack_entry
*sp
= &stack
[0];
9014 cp_parser_expression_stack_entry current
;
9017 enum tree_code rhs_type
;
9018 enum cp_parser_prec new_prec
, lookahead_prec
;
9021 /* Parse the first expression. */
9022 current
.lhs_type
= (cp_lexer_next_token_is (parser
->lexer
, CPP_NOT
)
9023 ? TRUTH_NOT_EXPR
: ERROR_MARK
);
9024 current
.lhs
= cp_parser_cast_expression (parser
, /*address_p=*/false,
9025 cast_p
, decltype_p
, pidk
);
9026 current
.prec
= prec
;
9028 if (cp_parser_error_occurred (parser
))
9029 return error_mark_node
;
9033 /* Get an operator token. */
9034 token
= cp_lexer_peek_token (parser
->lexer
);
9036 if (warn_cxx11_compat
9037 && token
->type
== CPP_RSHIFT
9038 && !parser
->greater_than_is_operator_p
)
9040 if (warning_at (token
->location
, OPT_Wc__11_compat
,
9041 "%<>>%> operator is treated"
9042 " as two right angle brackets in C++11"))
9043 inform (token
->location
,
9044 "suggest parentheses around %<>>%> expression");
9047 new_prec
= TOKEN_PRECEDENCE (token
);
9048 if (new_prec
!= PREC_NOT_OPERATOR
9049 && cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_ELLIPSIS
))
9050 /* This is a fold-expression; handle it later. */
9051 new_prec
= PREC_NOT_OPERATOR
;
9053 /* Popping an entry off the stack means we completed a subexpression:
9054 - either we found a token which is not an operator (`>' where it is not
9055 an operator, or prec == PREC_NOT_OPERATOR), in which case popping
9056 will happen repeatedly;
9057 - or, we found an operator which has lower priority. This is the case
9058 where the recursive descent *ascends*, as in `3 * 4 + 5' after
9060 if (new_prec
<= current
.prec
)
9069 current
.tree_type
= binops_by_token
[token
->type
].tree_type
;
9070 current
.loc
= token
->location
;
9072 /* We used the operator token. */
9073 cp_lexer_consume_token (parser
->lexer
);
9075 /* For "false && x" or "true || x", x will never be executed;
9076 disable warnings while evaluating it. */
9077 if (current
.tree_type
== TRUTH_ANDIF_EXPR
)
9078 c_inhibit_evaluation_warnings
+=
9079 cp_fully_fold (current
.lhs
) == truthvalue_false_node
;
9080 else if (current
.tree_type
== TRUTH_ORIF_EXPR
)
9081 c_inhibit_evaluation_warnings
+=
9082 cp_fully_fold (current
.lhs
) == truthvalue_true_node
;
9084 /* Extract another operand. It may be the RHS of this expression
9085 or the LHS of a new, higher priority expression. */
9086 rhs_type
= (cp_lexer_next_token_is (parser
->lexer
, CPP_NOT
)
9087 ? TRUTH_NOT_EXPR
: ERROR_MARK
);
9088 rhs
= cp_parser_simple_cast_expression (parser
);
9090 /* Get another operator token. Look up its precedence to avoid
9091 building a useless (immediately popped) stack entry for common
9092 cases such as 3 + 4 + 5 or 3 * 4 + 5. */
9093 token
= cp_lexer_peek_token (parser
->lexer
);
9094 lookahead_prec
= TOKEN_PRECEDENCE (token
);
9095 if (lookahead_prec
!= PREC_NOT_OPERATOR
9096 && cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_ELLIPSIS
))
9097 lookahead_prec
= PREC_NOT_OPERATOR
;
9098 if (lookahead_prec
> new_prec
)
9100 /* ... and prepare to parse the RHS of the new, higher priority
9101 expression. Since precedence levels on the stack are
9102 monotonically increasing, we do not have to care about
9107 current
.lhs_type
= rhs_type
;
9108 current
.prec
= new_prec
;
9109 new_prec
= lookahead_prec
;
9113 lookahead_prec
= new_prec
;
9114 /* If the stack is not empty, we have parsed into LHS the right side
9115 (`4' in the example above) of an expression we had suspended.
9116 We can use the information on the stack to recover the LHS (`3')
9117 from the stack together with the tree code (`MULT_EXPR'), and
9118 the precedence of the higher level subexpression
9119 (`PREC_ADDITIVE_EXPRESSION'). TOKEN is the CPP_PLUS token,
9120 which will be used to actually build the additive expression. */
9122 rhs_type
= current
.lhs_type
;
9127 /* Undo the disabling of warnings done above. */
9128 if (current
.tree_type
== TRUTH_ANDIF_EXPR
)
9129 c_inhibit_evaluation_warnings
-=
9130 cp_fully_fold (current
.lhs
) == truthvalue_false_node
;
9131 else if (current
.tree_type
== TRUTH_ORIF_EXPR
)
9132 c_inhibit_evaluation_warnings
-=
9133 cp_fully_fold (current
.lhs
) == truthvalue_true_node
;
9135 if (warn_logical_not_paren
9136 && TREE_CODE_CLASS (current
.tree_type
) == tcc_comparison
9137 && current
.lhs_type
== TRUTH_NOT_EXPR
9138 /* Avoid warning for !!x == y. */
9139 && (TREE_CODE (current
.lhs
) != NE_EXPR
9140 || !integer_zerop (TREE_OPERAND (current
.lhs
, 1)))
9141 && (TREE_CODE (current
.lhs
) != TRUTH_NOT_EXPR
9142 || (TREE_CODE (TREE_OPERAND (current
.lhs
, 0)) != TRUTH_NOT_EXPR
9143 /* Avoid warning for !b == y where b is boolean. */
9144 && (TREE_TYPE (TREE_OPERAND (current
.lhs
, 0)) == NULL_TREE
9145 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (current
.lhs
, 0)))
9147 /* Avoid warning for !!b == y where b is boolean. */
9148 && (!DECL_P (current
.lhs
)
9149 || TREE_TYPE (current
.lhs
) == NULL_TREE
9150 || TREE_CODE (TREE_TYPE (current
.lhs
)) != BOOLEAN_TYPE
))
9151 warn_logical_not_parentheses (current
.loc
, current
.tree_type
,
9152 current
.lhs
, maybe_constant_value (rhs
));
9156 location_t combined_loc
= make_location (current
.loc
,
9157 current
.lhs
.get_start (),
9160 /* ??? Currently we pass lhs_type == ERROR_MARK and rhs_type ==
9161 ERROR_MARK for everything that is not a binary expression.
9162 This makes warn_about_parentheses miss some warnings that
9163 involve unary operators. For unary expressions we should
9164 pass the correct tree_code unless the unary expression was
9165 surrounded by parentheses.
9167 if (no_toplevel_fold_p
9168 && lookahead_prec
<= current
.prec
9170 current
.lhs
= build2_loc (combined_loc
,
9172 TREE_CODE_CLASS (current
.tree_type
)
9174 ? boolean_type_node
: TREE_TYPE (current
.lhs
),
9178 current
.lhs
= build_x_binary_op (combined_loc
, current
.tree_type
,
9179 current
.lhs
, current
.lhs_type
,
9180 rhs
, rhs_type
, &overload
,
9181 complain_flags (decltype_p
));
9182 /* TODO: build_x_binary_op doesn't always honor the location. */
9183 current
.lhs
.set_location (combined_loc
);
9185 current
.lhs_type
= current
.tree_type
;
9187 /* If the binary operator required the use of an overloaded operator,
9188 then this expression cannot be an integral constant-expression.
9189 An overloaded operator can be used even if both operands are
9190 otherwise permissible in an integral constant-expression if at
9191 least one of the operands is of enumeration type. */
9194 && cp_parser_non_integral_constant_expression (parser
,
9196 return error_mark_node
;
9203 cp_parser_binary_expression (cp_parser
* parser
, bool cast_p
,
9204 bool no_toplevel_fold_p
,
9205 enum cp_parser_prec prec
,
9208 return cp_parser_binary_expression (parser
, cast_p
, no_toplevel_fold_p
,
9209 /*decltype*/false, prec
, pidk
);
9212 /* Parse the `? expression : assignment-expression' part of a
9213 conditional-expression. The LOGICAL_OR_EXPR is the
9214 logical-or-expression that started the conditional-expression.
9215 Returns a representation of the entire conditional-expression.
9217 This routine is used by cp_parser_assignment_expression.
9219 ? expression : assignment-expression
9223 ? : assignment-expression */
9226 cp_parser_question_colon_clause (cp_parser
* parser
, cp_expr logical_or_expr
)
9228 tree expr
, folded_logical_or_expr
= cp_fully_fold (logical_or_expr
);
9229 cp_expr assignment_expr
;
9230 struct cp_token
*token
;
9231 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
9233 /* Consume the `?' token. */
9234 cp_lexer_consume_token (parser
->lexer
);
9235 token
= cp_lexer_peek_token (parser
->lexer
);
9236 if (cp_parser_allow_gnu_extensions_p (parser
)
9237 && token
->type
== CPP_COLON
)
9239 pedwarn (token
->location
, OPT_Wpedantic
,
9240 "ISO C++ does not allow ?: with omitted middle operand");
9241 /* Implicit true clause. */
9243 c_inhibit_evaluation_warnings
+=
9244 folded_logical_or_expr
== truthvalue_true_node
;
9245 warn_for_omitted_condop (token
->location
, logical_or_expr
);
9249 bool saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
9250 parser
->colon_corrects_to_scope_p
= false;
9251 /* Parse the expression. */
9252 c_inhibit_evaluation_warnings
+=
9253 folded_logical_or_expr
== truthvalue_false_node
;
9254 expr
= cp_parser_expression (parser
);
9255 c_inhibit_evaluation_warnings
+=
9256 ((folded_logical_or_expr
== truthvalue_true_node
)
9257 - (folded_logical_or_expr
== truthvalue_false_node
));
9258 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
9261 /* The next token should be a `:'. */
9262 cp_parser_require (parser
, CPP_COLON
, RT_COLON
);
9263 /* Parse the assignment-expression. */
9264 assignment_expr
= cp_parser_assignment_expression (parser
);
9265 c_inhibit_evaluation_warnings
-=
9266 folded_logical_or_expr
== truthvalue_true_node
;
9269 LOGICAL_OR_EXPR ? EXPR : ASSIGNMENT_EXPR
9270 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
9271 with the caret at the "?", ranging from the start of
9272 the logical_or_expr to the end of the assignment_expr. */
9273 loc
= make_location (loc
,
9274 logical_or_expr
.get_start (),
9275 assignment_expr
.get_finish ());
9277 /* Build the conditional-expression. */
9278 return build_x_conditional_expr (loc
, logical_or_expr
,
9281 tf_warning_or_error
);
9284 /* Parse an assignment-expression.
9286 assignment-expression:
9287 conditional-expression
9288 logical-or-expression assignment-operator assignment_expression
9291 CAST_P is true if this expression is the target of a cast.
9292 DECLTYPE_P is true if this expression is the operand of decltype.
9294 Returns a representation for the expression. */
9297 cp_parser_assignment_expression (cp_parser
* parser
, cp_id_kind
* pidk
,
9298 bool cast_p
, bool decltype_p
)
9302 /* If the next token is the `throw' keyword, then we're looking at
9303 a throw-expression. */
9304 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_THROW
))
9305 expr
= cp_parser_throw_expression (parser
);
9306 /* Otherwise, it must be that we are looking at a
9307 logical-or-expression. */
9310 /* Parse the binary expressions (logical-or-expression). */
9311 expr
= cp_parser_binary_expression (parser
, cast_p
, false,
9313 PREC_NOT_OPERATOR
, pidk
);
9314 /* If the next token is a `?' then we're actually looking at a
9315 conditional-expression. */
9316 if (cp_lexer_next_token_is (parser
->lexer
, CPP_QUERY
))
9317 return cp_parser_question_colon_clause (parser
, expr
);
9320 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
9322 /* If it's an assignment-operator, we're using the second
9324 enum tree_code assignment_operator
9325 = cp_parser_assignment_operator_opt (parser
);
9326 if (assignment_operator
!= ERROR_MARK
)
9328 bool non_constant_p
;
9330 /* Parse the right-hand side of the assignment. */
9331 cp_expr rhs
= cp_parser_initializer_clause (parser
,
9334 if (BRACE_ENCLOSED_INITIALIZER_P (rhs
))
9335 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
9337 /* An assignment may not appear in a
9338 constant-expression. */
9339 if (cp_parser_non_integral_constant_expression (parser
,
9341 return error_mark_node
;
9342 /* Build the assignment expression. Its default
9346 is the location of the '=' token as the
9347 caret, ranging from the start of the lhs to the
9349 loc
= make_location (loc
,
9352 expr
= build_x_modify_expr (loc
, expr
,
9353 assignment_operator
,
9355 complain_flags (decltype_p
));
9356 /* TODO: build_x_modify_expr doesn't honor the location,
9357 so we must set it here. */
9358 expr
.set_location (loc
);
9366 /* Parse an (optional) assignment-operator.
9368 assignment-operator: one of
9369 = *= /= %= += -= >>= <<= &= ^= |=
9373 assignment-operator: one of
9376 If the next token is an assignment operator, the corresponding tree
9377 code is returned, and the token is consumed. For example, for
9378 `+=', PLUS_EXPR is returned. For `=' itself, the code returned is
9379 NOP_EXPR. For `/', TRUNC_DIV_EXPR is returned; for `%',
9380 TRUNC_MOD_EXPR is returned. If TOKEN is not an assignment
9381 operator, ERROR_MARK is returned. */
9383 static enum tree_code
9384 cp_parser_assignment_operator_opt (cp_parser
* parser
)
9389 /* Peek at the next token. */
9390 token
= cp_lexer_peek_token (parser
->lexer
);
9392 switch (token
->type
)
9403 op
= TRUNC_DIV_EXPR
;
9407 op
= TRUNC_MOD_EXPR
;
9439 /* Nothing else is an assignment operator. */
9443 /* An operator followed by ... is a fold-expression, handled elsewhere. */
9444 if (op
!= ERROR_MARK
9445 && cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_ELLIPSIS
))
9448 /* If it was an assignment operator, consume it. */
9449 if (op
!= ERROR_MARK
)
9450 cp_lexer_consume_token (parser
->lexer
);
9455 /* Parse an expression.
9458 assignment-expression
9459 expression , assignment-expression
9461 CAST_P is true if this expression is the target of a cast.
9462 DECLTYPE_P is true if this expression is the immediate operand of decltype,
9463 except possibly parenthesized or on the RHS of a comma (N3276).
9465 Returns a representation of the expression. */
9468 cp_parser_expression (cp_parser
* parser
, cp_id_kind
* pidk
,
9469 bool cast_p
, bool decltype_p
)
9471 cp_expr expression
= NULL_TREE
;
9472 location_t loc
= UNKNOWN_LOCATION
;
9476 cp_expr assignment_expression
;
9478 /* Parse the next assignment-expression. */
9479 assignment_expression
9480 = cp_parser_assignment_expression (parser
, pidk
, cast_p
, decltype_p
);
9482 /* We don't create a temporary for a call that is the immediate operand
9483 of decltype or on the RHS of a comma. But when we see a comma, we
9484 need to create a temporary for a call on the LHS. */
9485 if (decltype_p
&& !processing_template_decl
9486 && TREE_CODE (assignment_expression
) == CALL_EXPR
9487 && CLASS_TYPE_P (TREE_TYPE (assignment_expression
))
9488 && cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
9489 assignment_expression
9490 = build_cplus_new (TREE_TYPE (assignment_expression
),
9491 assignment_expression
, tf_warning_or_error
);
9493 /* If this is the first assignment-expression, we can just
9496 expression
= assignment_expression
;
9499 /* Create a location with caret at the comma, ranging
9500 from the start of the LHS to the end of the RHS. */
9501 loc
= make_location (loc
,
9502 expression
.get_start (),
9503 assignment_expression
.get_finish ());
9504 expression
= build_x_compound_expr (loc
, expression
,
9505 assignment_expression
,
9506 complain_flags (decltype_p
));
9507 expression
.set_location (loc
);
9509 /* If the next token is not a comma, or we're in a fold-expression, then
9510 we are done with the expression. */
9511 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
)
9512 || cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_ELLIPSIS
))
9514 /* Consume the `,'. */
9515 loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
9516 cp_lexer_consume_token (parser
->lexer
);
9517 /* A comma operator cannot appear in a constant-expression. */
9518 if (cp_parser_non_integral_constant_expression (parser
, NIC_COMMA
))
9519 expression
= error_mark_node
;
9525 /* Parse a constant-expression.
9527 constant-expression:
9528 conditional-expression
9530 If ALLOW_NON_CONSTANT_P a non-constant expression is silently
9531 accepted. If ALLOW_NON_CONSTANT_P is true and the expression is not
9532 constant, *NON_CONSTANT_P is set to TRUE. If ALLOW_NON_CONSTANT_P
9533 is false, NON_CONSTANT_P should be NULL. */
9536 cp_parser_constant_expression (cp_parser
* parser
,
9537 bool allow_non_constant_p
,
9538 bool *non_constant_p
)
9540 bool saved_integral_constant_expression_p
;
9541 bool saved_allow_non_integral_constant_expression_p
;
9542 bool saved_non_integral_constant_expression_p
;
9545 /* It might seem that we could simply parse the
9546 conditional-expression, and then check to see if it were
9547 TREE_CONSTANT. However, an expression that is TREE_CONSTANT is
9548 one that the compiler can figure out is constant, possibly after
9549 doing some simplifications or optimizations. The standard has a
9550 precise definition of constant-expression, and we must honor
9551 that, even though it is somewhat more restrictive.
9557 is not a legal declaration, because `(2, 3)' is not a
9558 constant-expression. The `,' operator is forbidden in a
9559 constant-expression. However, GCC's constant-folding machinery
9560 will fold this operation to an INTEGER_CST for `3'. */
9562 /* Save the old settings. */
9563 saved_integral_constant_expression_p
= parser
->integral_constant_expression_p
;
9564 saved_allow_non_integral_constant_expression_p
9565 = parser
->allow_non_integral_constant_expression_p
;
9566 saved_non_integral_constant_expression_p
= parser
->non_integral_constant_expression_p
;
9567 /* We are now parsing a constant-expression. */
9568 parser
->integral_constant_expression_p
= true;
9569 parser
->allow_non_integral_constant_expression_p
9570 = (allow_non_constant_p
|| cxx_dialect
>= cxx11
);
9571 parser
->non_integral_constant_expression_p
= false;
9572 /* Although the grammar says "conditional-expression", we parse an
9573 "assignment-expression", which also permits "throw-expression"
9574 and the use of assignment operators. In the case that
9575 ALLOW_NON_CONSTANT_P is false, we get better errors than we would
9576 otherwise. In the case that ALLOW_NON_CONSTANT_P is true, it is
9577 actually essential that we look for an assignment-expression.
9578 For example, cp_parser_initializer_clauses uses this function to
9579 determine whether a particular assignment-expression is in fact
9581 expression
= cp_parser_assignment_expression (parser
);
9582 /* Restore the old settings. */
9583 parser
->integral_constant_expression_p
9584 = saved_integral_constant_expression_p
;
9585 parser
->allow_non_integral_constant_expression_p
9586 = saved_allow_non_integral_constant_expression_p
;
9587 if (cxx_dialect
>= cxx11
)
9589 /* Require an rvalue constant expression here; that's what our
9590 callers expect. Reference constant expressions are handled
9591 separately in e.g. cp_parser_template_argument. */
9592 tree decay
= expression
;
9593 if (TREE_TYPE (expression
)
9594 && TREE_CODE (TREE_TYPE (expression
)) == ARRAY_TYPE
)
9595 decay
= build_address (expression
);
9596 bool is_const
= potential_rvalue_constant_expression (decay
);
9597 parser
->non_integral_constant_expression_p
= !is_const
;
9598 if (!is_const
&& !allow_non_constant_p
)
9599 require_potential_rvalue_constant_expression (decay
);
9601 if (allow_non_constant_p
)
9602 *non_constant_p
= parser
->non_integral_constant_expression_p
;
9603 parser
->non_integral_constant_expression_p
9604 = saved_non_integral_constant_expression_p
;
9609 /* Parse __builtin_offsetof.
9611 offsetof-expression:
9612 "__builtin_offsetof" "(" type-id "," offsetof-member-designator ")"
9614 offsetof-member-designator:
9616 | offsetof-member-designator "." id-expression
9617 | offsetof-member-designator "[" expression "]"
9618 | offsetof-member-designator "->" id-expression */
9621 cp_parser_builtin_offsetof (cp_parser
*parser
)
9623 int save_ice_p
, save_non_ice_p
;
9628 location_t finish_loc
;
9630 /* We're about to accept non-integral-constant things, but will
9631 definitely yield an integral constant expression. Save and
9632 restore these values around our local parsing. */
9633 save_ice_p
= parser
->integral_constant_expression_p
;
9634 save_non_ice_p
= parser
->non_integral_constant_expression_p
;
9636 location_t start_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
9638 /* Consume the "__builtin_offsetof" token. */
9639 cp_lexer_consume_token (parser
->lexer
);
9640 /* Consume the opening `('. */
9641 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
9642 /* Parse the type-id. */
9643 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
9644 type
= cp_parser_type_id (parser
);
9645 /* Look for the `,'. */
9646 cp_parser_require (parser
, CPP_COMMA
, RT_COMMA
);
9647 token
= cp_lexer_peek_token (parser
->lexer
);
9649 /* Build the (type *)null that begins the traditional offsetof macro. */
9651 = build_static_cast (build_pointer_type (type
), null_pointer_node
,
9652 tf_warning_or_error
);
9654 /* Parse the offsetof-member-designator. We begin as if we saw "expr->". */
9655 expr
= cp_parser_postfix_dot_deref_expression (parser
, CPP_DEREF
, object_ptr
,
9656 true, &dummy
, token
->location
);
9659 token
= cp_lexer_peek_token (parser
->lexer
);
9660 switch (token
->type
)
9662 case CPP_OPEN_SQUARE
:
9663 /* offsetof-member-designator "[" expression "]" */
9664 expr
= cp_parser_postfix_open_square_expression (parser
, expr
,
9669 /* offsetof-member-designator "->" identifier */
9670 expr
= grok_array_decl (token
->location
, expr
,
9671 integer_zero_node
, false);
9675 /* offsetof-member-designator "." identifier */
9676 cp_lexer_consume_token (parser
->lexer
);
9677 expr
= cp_parser_postfix_dot_deref_expression (parser
, CPP_DOT
,
9682 case CPP_CLOSE_PAREN
:
9683 /* Consume the ")" token. */
9684 finish_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
9685 cp_lexer_consume_token (parser
->lexer
);
9689 /* Error. We know the following require will fail, but
9690 that gives the proper error message. */
9691 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
9692 cp_parser_skip_to_closing_parenthesis (parser
, true, false, true);
9693 expr
= error_mark_node
;
9699 /* Make a location of the form:
9700 __builtin_offsetof (struct s, f)
9701 ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
9702 with caret at the type-id, ranging from the start of the
9703 "_builtin_offsetof" token to the close paren. */
9704 loc
= make_location (loc
, start_loc
, finish_loc
);
9705 /* The result will be an INTEGER_CST, so we need to explicitly
9706 preserve the location. */
9707 expr
= cp_expr (finish_offsetof (object_ptr
, expr
, loc
), loc
);
9710 parser
->integral_constant_expression_p
= save_ice_p
;
9711 parser
->non_integral_constant_expression_p
= save_non_ice_p
;
9716 /* Parse a trait expression.
9718 Returns a representation of the expression, the underlying type
9719 of the type at issue when KEYWORD is RID_UNDERLYING_TYPE. */
9722 cp_parser_trait_expr (cp_parser
* parser
, enum rid keyword
)
9725 tree type1
, type2
= NULL_TREE
;
9726 bool binary
= false;
9727 bool variadic
= false;
9731 case RID_HAS_NOTHROW_ASSIGN
:
9732 kind
= CPTK_HAS_NOTHROW_ASSIGN
;
9734 case RID_HAS_NOTHROW_CONSTRUCTOR
:
9735 kind
= CPTK_HAS_NOTHROW_CONSTRUCTOR
;
9737 case RID_HAS_NOTHROW_COPY
:
9738 kind
= CPTK_HAS_NOTHROW_COPY
;
9740 case RID_HAS_TRIVIAL_ASSIGN
:
9741 kind
= CPTK_HAS_TRIVIAL_ASSIGN
;
9743 case RID_HAS_TRIVIAL_CONSTRUCTOR
:
9744 kind
= CPTK_HAS_TRIVIAL_CONSTRUCTOR
;
9746 case RID_HAS_TRIVIAL_COPY
:
9747 kind
= CPTK_HAS_TRIVIAL_COPY
;
9749 case RID_HAS_TRIVIAL_DESTRUCTOR
:
9750 kind
= CPTK_HAS_TRIVIAL_DESTRUCTOR
;
9752 case RID_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9753 kind
= CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
;
9755 case RID_HAS_VIRTUAL_DESTRUCTOR
:
9756 kind
= CPTK_HAS_VIRTUAL_DESTRUCTOR
;
9758 case RID_IS_ABSTRACT
:
9759 kind
= CPTK_IS_ABSTRACT
;
9761 case RID_IS_AGGREGATE
:
9762 kind
= CPTK_IS_AGGREGATE
;
9764 case RID_IS_BASE_OF
:
9765 kind
= CPTK_IS_BASE_OF
;
9769 kind
= CPTK_IS_CLASS
;
9772 kind
= CPTK_IS_EMPTY
;
9775 kind
= CPTK_IS_ENUM
;
9778 kind
= CPTK_IS_FINAL
;
9780 case RID_IS_LITERAL_TYPE
:
9781 kind
= CPTK_IS_LITERAL_TYPE
;
9786 case RID_IS_POLYMORPHIC
:
9787 kind
= CPTK_IS_POLYMORPHIC
;
9789 case RID_IS_SAME_AS
:
9790 kind
= CPTK_IS_SAME_AS
;
9793 case RID_IS_STD_LAYOUT
:
9794 kind
= CPTK_IS_STD_LAYOUT
;
9796 case RID_IS_TRIVIAL
:
9797 kind
= CPTK_IS_TRIVIAL
;
9799 case RID_IS_TRIVIALLY_ASSIGNABLE
:
9800 kind
= CPTK_IS_TRIVIALLY_ASSIGNABLE
;
9803 case RID_IS_TRIVIALLY_CONSTRUCTIBLE
:
9804 kind
= CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
;
9807 case RID_IS_TRIVIALLY_COPYABLE
:
9808 kind
= CPTK_IS_TRIVIALLY_COPYABLE
;
9811 kind
= CPTK_IS_UNION
;
9813 case RID_UNDERLYING_TYPE
:
9814 kind
= CPTK_UNDERLYING_TYPE
;
9819 case RID_DIRECT_BASES
:
9820 kind
= CPTK_DIRECT_BASES
;
9822 case RID_IS_ASSIGNABLE
:
9823 kind
= CPTK_IS_ASSIGNABLE
;
9826 case RID_IS_CONSTRUCTIBLE
:
9827 kind
= CPTK_IS_CONSTRUCTIBLE
;
9834 /* Consume the token. */
9835 cp_lexer_consume_token (parser
->lexer
);
9837 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
9840 type_id_in_expr_sentinel
s (parser
);
9841 type1
= cp_parser_type_id (parser
);
9844 if (type1
== error_mark_node
)
9845 return error_mark_node
;
9849 cp_parser_require (parser
, CPP_COMMA
, RT_COMMA
);
9852 type_id_in_expr_sentinel
s (parser
);
9853 type2
= cp_parser_type_id (parser
);
9856 if (type2
== error_mark_node
)
9857 return error_mark_node
;
9861 while (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
9863 cp_lexer_consume_token (parser
->lexer
);
9864 tree elt
= cp_parser_type_id (parser
);
9865 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
9867 cp_lexer_consume_token (parser
->lexer
);
9868 elt
= make_pack_expansion (elt
);
9870 if (elt
== error_mark_node
)
9871 return error_mark_node
;
9872 type2
= tree_cons (NULL_TREE
, elt
, type2
);
9876 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
9878 /* Complete the trait expression, which may mean either processing
9879 the trait expr now or saving it for template instantiation. */
9882 case CPTK_UNDERLYING_TYPE
:
9883 return finish_underlying_type (type1
);
9885 return finish_bases (type1
, false);
9886 case CPTK_DIRECT_BASES
:
9887 return finish_bases (type1
, true);
9889 return finish_trait_expr (kind
, type1
, type2
);
9893 /* Lambdas that appear in variable initializer or default argument scope
9894 get that in their mangling, so we need to record it. We might as well
9895 use the count for function and namespace scopes as well. */
9896 static GTY(()) tree lambda_scope
;
9897 static GTY(()) int lambda_count
;
9898 struct GTY(()) tree_int
9903 static GTY(()) vec
<tree_int
, va_gc
> *lambda_scope_stack
;
9906 start_lambda_scope (tree decl
)
9910 /* Once we're inside a function, we ignore other scopes and just push
9911 the function again so that popping works properly. */
9912 if (current_function_decl
&& TREE_CODE (decl
) != FUNCTION_DECL
)
9913 decl
= current_function_decl
;
9914 ti
.t
= lambda_scope
;
9915 ti
.i
= lambda_count
;
9916 vec_safe_push (lambda_scope_stack
, ti
);
9917 if (lambda_scope
!= decl
)
9919 /* Don't reset the count if we're still in the same function. */
9920 lambda_scope
= decl
;
9926 record_lambda_scope (tree lambda
)
9928 LAMBDA_EXPR_EXTRA_SCOPE (lambda
) = lambda_scope
;
9929 LAMBDA_EXPR_DISCRIMINATOR (lambda
) = lambda_count
++;
9933 finish_lambda_scope (void)
9935 tree_int
*p
= &lambda_scope_stack
->last ();
9936 if (lambda_scope
!= p
->t
)
9938 lambda_scope
= p
->t
;
9939 lambda_count
= p
->i
;
9941 lambda_scope_stack
->pop ();
9944 /* Parse a lambda expression.
9947 lambda-introducer lambda-declarator [opt] compound-statement
9949 Returns a representation of the expression. */
9952 cp_parser_lambda_expression (cp_parser
* parser
)
9954 tree lambda_expr
= build_lambda_expr ();
9957 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
9958 cp_token_position start
= 0;
9960 LAMBDA_EXPR_LOCATION (lambda_expr
) = token
->location
;
9962 if (cp_unevaluated_operand
)
9964 if (!token
->error_reported
)
9966 error_at (LAMBDA_EXPR_LOCATION (lambda_expr
),
9967 "lambda-expression in unevaluated context");
9968 token
->error_reported
= true;
9972 else if (parser
->in_template_argument_list_p
)
9974 if (!token
->error_reported
)
9976 error_at (token
->location
, "lambda-expression in template-argument");
9977 token
->error_reported
= true;
9982 /* We may be in the middle of deferred access check. Disable
9984 push_deferring_access_checks (dk_no_deferred
);
9986 cp_parser_lambda_introducer (parser
, lambda_expr
);
9988 type
= begin_lambda_type (lambda_expr
);
9989 if (type
== error_mark_node
)
9990 return error_mark_node
;
9992 record_lambda_scope (lambda_expr
);
9994 /* Do this again now that LAMBDA_EXPR_EXTRA_SCOPE is set. */
9995 determine_visibility (TYPE_NAME (type
));
9997 /* Now that we've started the type, add the capture fields for any
9998 explicit captures. */
9999 register_capture_members (LAMBDA_EXPR_CAPTURE_LIST (lambda_expr
));
10002 /* Inside the class, surrounding template-parameter-lists do not apply. */
10003 unsigned int saved_num_template_parameter_lists
10004 = parser
->num_template_parameter_lists
;
10005 unsigned char in_statement
= parser
->in_statement
;
10006 bool in_switch_statement_p
= parser
->in_switch_statement_p
;
10007 bool fully_implicit_function_template_p
10008 = parser
->fully_implicit_function_template_p
;
10009 tree implicit_template_parms
= parser
->implicit_template_parms
;
10010 cp_binding_level
* implicit_template_scope
= parser
->implicit_template_scope
;
10011 bool auto_is_implicit_function_template_parm_p
10012 = parser
->auto_is_implicit_function_template_parm_p
;
10014 parser
->num_template_parameter_lists
= 0;
10015 parser
->in_statement
= 0;
10016 parser
->in_switch_statement_p
= false;
10017 parser
->fully_implicit_function_template_p
= false;
10018 parser
->implicit_template_parms
= 0;
10019 parser
->implicit_template_scope
= 0;
10020 parser
->auto_is_implicit_function_template_parm_p
= false;
10022 /* By virtue of defining a local class, a lambda expression has access to
10023 the private variables of enclosing classes. */
10025 ok
&= cp_parser_lambda_declarator_opt (parser
, lambda_expr
);
10027 if (ok
&& cp_parser_error_occurred (parser
))
10032 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
)
10033 && cp_parser_start_tentative_firewall (parser
))
10035 cp_parser_lambda_body (parser
, lambda_expr
);
10037 else if (cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
))
10039 if (cp_parser_skip_to_closing_brace (parser
))
10040 cp_lexer_consume_token (parser
->lexer
);
10043 /* The capture list was built up in reverse order; fix that now. */
10044 LAMBDA_EXPR_CAPTURE_LIST (lambda_expr
)
10045 = nreverse (LAMBDA_EXPR_CAPTURE_LIST (lambda_expr
));
10048 maybe_add_lambda_conv_op (type
);
10050 type
= finish_struct (type
, /*attributes=*/NULL_TREE
);
10052 parser
->num_template_parameter_lists
= saved_num_template_parameter_lists
;
10053 parser
->in_statement
= in_statement
;
10054 parser
->in_switch_statement_p
= in_switch_statement_p
;
10055 parser
->fully_implicit_function_template_p
10056 = fully_implicit_function_template_p
;
10057 parser
->implicit_template_parms
= implicit_template_parms
;
10058 parser
->implicit_template_scope
= implicit_template_scope
;
10059 parser
->auto_is_implicit_function_template_parm_p
10060 = auto_is_implicit_function_template_parm_p
;
10063 /* This field is only used during parsing of the lambda. */
10064 LAMBDA_EXPR_THIS_CAPTURE (lambda_expr
) = NULL_TREE
;
10066 /* This lambda shouldn't have any proxies left at this point. */
10067 gcc_assert (LAMBDA_EXPR_PENDING_PROXIES (lambda_expr
) == NULL
);
10068 /* And now that we're done, push proxies for an enclosing lambda. */
10069 insert_pending_capture_proxies ();
10072 lambda_expr
= build_lambda_object (lambda_expr
);
10074 lambda_expr
= error_mark_node
;
10076 cp_parser_end_tentative_firewall (parser
, start
, lambda_expr
);
10078 pop_deferring_access_checks ();
10080 return lambda_expr
;
10083 /* Parse the beginning of a lambda expression.
10086 [ lambda-capture [opt] ]
10088 LAMBDA_EXPR is the current representation of the lambda expression. */
10091 cp_parser_lambda_introducer (cp_parser
* parser
, tree lambda_expr
)
10093 /* Need commas after the first capture. */
10096 /* Eat the leading `['. */
10097 cp_parser_require (parser
, CPP_OPEN_SQUARE
, RT_OPEN_SQUARE
);
10099 /* Record default capture mode. "[&" "[=" "[&," "[=," */
10100 if (cp_lexer_next_token_is (parser
->lexer
, CPP_AND
)
10101 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
!= CPP_NAME
)
10102 LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) = CPLD_REFERENCE
;
10103 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
))
10104 LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) = CPLD_COPY
;
10106 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) != CPLD_NONE
)
10108 cp_lexer_consume_token (parser
->lexer
);
10112 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_SQUARE
))
10114 cp_token
* capture_token
;
10116 tree capture_init_expr
;
10117 cp_id_kind idk
= CP_ID_KIND_NONE
;
10118 bool explicit_init_p
= false;
10120 enum capture_kind_type
10125 enum capture_kind_type capture_kind
= BY_COPY
;
10127 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EOF
))
10129 error ("expected end of capture-list");
10136 cp_parser_require (parser
, CPP_COMMA
, RT_COMMA
);
10138 /* Possibly capture `this'. */
10139 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_THIS
))
10141 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
10142 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_COPY
)
10143 pedwarn (loc
, 0, "explicit by-copy capture of %<this%> redundant "
10144 "with by-copy capture default");
10145 cp_lexer_consume_token (parser
->lexer
);
10146 add_capture (lambda_expr
,
10147 /*id=*/this_identifier
,
10148 /*initializer=*/finish_this_expr (),
10149 /*by_reference_p=*/true,
10154 /* Possibly capture `*this'. */
10155 if (cp_lexer_next_token_is (parser
->lexer
, CPP_MULT
)
10156 && cp_lexer_nth_token_is_keyword (parser
->lexer
, 2, RID_THIS
))
10158 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
10159 if (cxx_dialect
< cxx1z
)
10160 pedwarn (loc
, 0, "%<*this%> capture only available with "
10161 "-std=c++1z or -std=gnu++1z");
10162 cp_lexer_consume_token (parser
->lexer
);
10163 cp_lexer_consume_token (parser
->lexer
);
10164 add_capture (lambda_expr
,
10165 /*id=*/this_identifier
,
10166 /*initializer=*/finish_this_expr (),
10167 /*by_reference_p=*/false,
10172 /* Remember whether we want to capture as a reference or not. */
10173 if (cp_lexer_next_token_is (parser
->lexer
, CPP_AND
))
10175 capture_kind
= BY_REFERENCE
;
10176 cp_lexer_consume_token (parser
->lexer
);
10179 /* Get the identifier. */
10180 capture_token
= cp_lexer_peek_token (parser
->lexer
);
10181 capture_id
= cp_parser_identifier (parser
);
10183 if (capture_id
== error_mark_node
)
10184 /* Would be nice to have a cp_parser_skip_to_closing_x for general
10185 delimiters, but I modified this to stop on unnested ']' as well. It
10186 was already changed to stop on unnested '}', so the
10187 "closing_parenthesis" name is no more misleading with my change. */
10189 cp_parser_skip_to_closing_parenthesis (parser
,
10190 /*recovering=*/true,
10192 /*consume_paren=*/true);
10196 /* Find the initializer for this capture. */
10197 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
)
10198 || cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
)
10199 || cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
10201 bool direct
, non_constant
;
10202 /* An explicit initializer exists. */
10203 if (cxx_dialect
< cxx14
)
10204 pedwarn (input_location
, 0,
10205 "lambda capture initializers "
10206 "only available with -std=c++14 or -std=gnu++14");
10207 capture_init_expr
= cp_parser_initializer (parser
, &direct
,
10209 explicit_init_p
= true;
10210 if (capture_init_expr
== NULL_TREE
)
10212 error ("empty initializer for lambda init-capture");
10213 capture_init_expr
= error_mark_node
;
10218 const char* error_msg
;
10220 /* Turn the identifier into an id-expression. */
10222 = cp_parser_lookup_name_simple (parser
, capture_id
,
10223 capture_token
->location
);
10225 if (capture_init_expr
== error_mark_node
)
10227 unqualified_name_lookup_error (capture_id
);
10230 else if (DECL_P (capture_init_expr
)
10231 && (!VAR_P (capture_init_expr
)
10232 && TREE_CODE (capture_init_expr
) != PARM_DECL
))
10234 error_at (capture_token
->location
,
10235 "capture of non-variable %qD ",
10236 capture_init_expr
);
10237 inform (DECL_SOURCE_LOCATION (capture_init_expr
),
10238 "%q#D declared here", capture_init_expr
);
10241 if (VAR_P (capture_init_expr
)
10242 && decl_storage_duration (capture_init_expr
) != dk_auto
)
10244 if (pedwarn (capture_token
->location
, 0, "capture of variable "
10245 "%qD with non-automatic storage duration",
10246 capture_init_expr
))
10247 inform (DECL_SOURCE_LOCATION (capture_init_expr
),
10248 "%q#D declared here", capture_init_expr
);
10253 = finish_id_expression
10258 /*integral_constant_expression_p=*/false,
10259 /*allow_non_integral_constant_expression_p=*/false,
10260 /*non_integral_constant_expression_p=*/NULL
,
10261 /*template_p=*/false,
10263 /*address_p=*/false,
10264 /*template_arg_p=*/false,
10266 capture_token
->location
);
10268 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
10270 cp_lexer_consume_token (parser
->lexer
);
10271 capture_init_expr
= make_pack_expansion (capture_init_expr
);
10274 check_for_bare_parameter_packs (capture_init_expr
);
10277 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) != CPLD_NONE
10278 && !explicit_init_p
)
10280 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_COPY
10281 && capture_kind
== BY_COPY
)
10282 pedwarn (capture_token
->location
, 0, "explicit by-copy capture "
10283 "of %qD redundant with by-copy capture default",
10285 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_REFERENCE
10286 && capture_kind
== BY_REFERENCE
)
10287 pedwarn (capture_token
->location
, 0, "explicit by-reference "
10288 "capture of %qD redundant with by-reference capture "
10289 "default", capture_id
);
10292 add_capture (lambda_expr
,
10295 /*by_reference_p=*/capture_kind
== BY_REFERENCE
,
10299 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
10302 /* Parse the (optional) middle of a lambda expression.
10305 < template-parameter-list [opt] >
10306 ( parameter-declaration-clause [opt] )
10307 attribute-specifier [opt]
10308 decl-specifier-seq [opt]
10309 exception-specification [opt]
10310 lambda-return-type-clause [opt]
10312 LAMBDA_EXPR is the current representation of the lambda expression. */
10315 cp_parser_lambda_declarator_opt (cp_parser
* parser
, tree lambda_expr
)
10317 /* 5.1.1.4 of the standard says:
10318 If a lambda-expression does not include a lambda-declarator, it is as if
10319 the lambda-declarator were ().
10320 This means an empty parameter list, no attributes, and no exception
10322 tree param_list
= void_list_node
;
10323 tree attributes
= NULL_TREE
;
10324 tree exception_spec
= NULL_TREE
;
10325 tree template_param_list
= NULL_TREE
;
10326 tree tx_qual
= NULL_TREE
;
10327 cp_decl_specifier_seq lambda_specs
;
10328 clear_decl_specs (&lambda_specs
);
10330 /* The template-parameter-list is optional, but must begin with
10331 an opening angle if present. */
10332 if (cp_lexer_next_token_is (parser
->lexer
, CPP_LESS
))
10334 if (cxx_dialect
< cxx14
)
10335 pedwarn (parser
->lexer
->next_token
->location
, 0,
10336 "lambda templates are only available with "
10337 "-std=c++14 or -std=gnu++14");
10339 pedwarn (parser
->lexer
->next_token
->location
, OPT_Wpedantic
,
10340 "ISO C++ does not support lambda templates");
10342 cp_lexer_consume_token (parser
->lexer
);
10344 template_param_list
= cp_parser_template_parameter_list (parser
);
10346 cp_parser_skip_to_end_of_template_parameter_list (parser
);
10348 /* We just processed one more parameter list. */
10349 ++parser
->num_template_parameter_lists
;
10352 /* The parameter-declaration-clause is optional (unless
10353 template-parameter-list was given), but must begin with an
10354 opening parenthesis if present. */
10355 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
10357 cp_lexer_consume_token (parser
->lexer
);
10359 begin_scope (sk_function_parms
, /*entity=*/NULL_TREE
);
10361 /* Parse parameters. */
10362 param_list
= cp_parser_parameter_declaration_clause (parser
);
10364 /* Default arguments shall not be specified in the
10365 parameter-declaration-clause of a lambda-declarator. */
10366 if (cxx_dialect
< cxx14
)
10367 for (tree t
= param_list
; t
; t
= TREE_CHAIN (t
))
10368 if (TREE_PURPOSE (t
) && DECL_P (TREE_VALUE (t
)))
10369 pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t
)), OPT_Wpedantic
,
10370 "default argument specified for lambda parameter");
10372 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
10374 attributes
= cp_parser_attributes_opt (parser
);
10376 /* In the decl-specifier-seq of the lambda-declarator, each
10377 decl-specifier shall either be mutable or constexpr. */
10378 int declares_class_or_enum
;
10379 if (cp_lexer_next_token_is_decl_specifier_keyword (parser
->lexer
))
10380 cp_parser_decl_specifier_seq (parser
,
10381 CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR
,
10382 &lambda_specs
, &declares_class_or_enum
);
10383 if (lambda_specs
.storage_class
== sc_mutable
)
10385 LAMBDA_EXPR_MUTABLE_P (lambda_expr
) = 1;
10386 if (lambda_specs
.conflicting_specifiers_p
)
10387 error_at (lambda_specs
.locations
[ds_storage_class
],
10388 "duplicate %<mutable%>");
10391 tx_qual
= cp_parser_tx_qualifier_opt (parser
);
10393 /* Parse optional exception specification. */
10394 exception_spec
= cp_parser_exception_specification_opt (parser
);
10396 /* Parse optional trailing return type. */
10397 if (cp_lexer_next_token_is (parser
->lexer
, CPP_DEREF
))
10399 cp_lexer_consume_token (parser
->lexer
);
10400 LAMBDA_EXPR_RETURN_TYPE (lambda_expr
)
10401 = cp_parser_trailing_type_id (parser
);
10404 /* The function parameters must be in scope all the way until after the
10405 trailing-return-type in case of decltype. */
10406 pop_bindings_and_leave_scope ();
10408 else if (template_param_list
!= NULL_TREE
) // generate diagnostic
10409 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
10411 /* Create the function call operator.
10413 Messing with declarators like this is no uglier than building up the
10414 FUNCTION_DECL by hand, and this is less likely to get out of sync with
10417 cp_decl_specifier_seq return_type_specs
;
10418 cp_declarator
* declarator
;
10423 clear_decl_specs (&return_type_specs
);
10424 if (LAMBDA_EXPR_RETURN_TYPE (lambda_expr
))
10425 return_type_specs
.type
= LAMBDA_EXPR_RETURN_TYPE (lambda_expr
);
10427 /* Maybe we will deduce the return type later. */
10428 return_type_specs
.type
= make_auto ();
10430 if (lambda_specs
.locations
[ds_constexpr
])
10432 if (cxx_dialect
>= cxx1z
)
10433 return_type_specs
.locations
[ds_constexpr
]
10434 = lambda_specs
.locations
[ds_constexpr
];
10436 error_at (lambda_specs
.locations
[ds_constexpr
], "%<constexpr%> "
10437 "lambda only available with -std=c++1z or -std=gnu++1z");
10440 p
= obstack_alloc (&declarator_obstack
, 0);
10442 declarator
= make_id_declarator (NULL_TREE
, cp_operator_id (CALL_EXPR
),
10445 quals
= (LAMBDA_EXPR_MUTABLE_P (lambda_expr
)
10446 ? TYPE_UNQUALIFIED
: TYPE_QUAL_CONST
);
10447 declarator
= make_call_declarator (declarator
, param_list
, quals
,
10448 VIRT_SPEC_UNSPECIFIED
,
10452 /*late_return_type=*/NULL_TREE
,
10453 /*requires_clause*/NULL_TREE
);
10454 declarator
->id_loc
= LAMBDA_EXPR_LOCATION (lambda_expr
);
10456 fco
= grokmethod (&return_type_specs
,
10459 if (fco
!= error_mark_node
)
10461 DECL_INITIALIZED_IN_CLASS_P (fco
) = 1;
10462 DECL_ARTIFICIAL (fco
) = 1;
10463 /* Give the object parameter a different name. */
10464 DECL_NAME (DECL_ARGUMENTS (fco
)) = get_identifier ("__closure");
10465 if (LAMBDA_EXPR_RETURN_TYPE (lambda_expr
))
10466 TYPE_HAS_LATE_RETURN_TYPE (TREE_TYPE (fco
)) = 1;
10468 if (template_param_list
)
10470 fco
= finish_member_template_decl (fco
);
10471 finish_template_decl (template_param_list
);
10472 --parser
->num_template_parameter_lists
;
10474 else if (parser
->fully_implicit_function_template_p
)
10475 fco
= finish_fully_implicit_template (parser
, fco
);
10477 finish_member_declaration (fco
);
10479 obstack_free (&declarator_obstack
, p
);
10481 return (fco
!= error_mark_node
);
10485 /* Parse the body of a lambda expression, which is simply
10489 but which requires special handling.
10490 LAMBDA_EXPR is the current representation of the lambda expression. */
10493 cp_parser_lambda_body (cp_parser
* parser
, tree lambda_expr
)
10495 bool nested
= (current_function_decl
!= NULL_TREE
);
10496 bool local_variables_forbidden_p
= parser
->local_variables_forbidden_p
;
10498 push_function_context ();
10500 /* Still increment function_depth so that we don't GC in the
10501 middle of an expression. */
10503 vec
<tree
> omp_privatization_save
;
10504 save_omp_privatization_clauses (omp_privatization_save
);
10505 /* Clear this in case we're in the middle of a default argument. */
10506 parser
->local_variables_forbidden_p
= false;
10508 /* Finish the function call operator
10510 + late_parsing_for_member
10511 + function_definition_after_declarator
10512 + ctor_initializer_opt_and_function_body */
10514 tree fco
= lambda_function (lambda_expr
);
10517 tree compound_stmt
;
10520 /* Let the front end know that we are going to be defining this
10522 start_preparsed_function (fco
,
10524 SF_PRE_PARSED
| SF_INCLASS_INLINE
);
10526 start_lambda_scope (fco
);
10527 body
= begin_function_body ();
10529 if (!cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
))
10532 /* Push the proxies for any explicit captures. */
10533 for (cap
= LAMBDA_EXPR_CAPTURE_LIST (lambda_expr
); cap
;
10534 cap
= TREE_CHAIN (cap
))
10535 build_capture_proxy (TREE_PURPOSE (cap
));
10537 compound_stmt
= begin_compound_stmt (0);
10539 /* 5.1.1.4 of the standard says:
10540 If a lambda-expression does not include a trailing-return-type, it
10541 is as if the trailing-return-type denotes the following type:
10542 * if the compound-statement is of the form
10543 { return attribute-specifier [opt] expression ; }
10544 the type of the returned expression after lvalue-to-rvalue
10545 conversion (_conv.lval_ 4.1), array-to-pointer conversion
10546 (_conv.array_ 4.2), and function-to-pointer conversion
10548 * otherwise, void. */
10550 /* In a lambda that has neither a lambda-return-type-clause
10551 nor a deducible form, errors should be reported for return statements
10552 in the body. Since we used void as the placeholder return type, parsing
10553 the body as usual will give such desired behavior. */
10554 if (!LAMBDA_EXPR_RETURN_TYPE (lambda_expr
)
10555 && cp_lexer_peek_nth_token (parser
->lexer
, 1)->keyword
== RID_RETURN
10556 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
!= CPP_SEMICOLON
)
10558 tree expr
= NULL_TREE
;
10559 cp_id_kind idk
= CP_ID_KIND_NONE
;
10561 /* Parse tentatively in case there's more after the initial return
10563 cp_parser_parse_tentatively (parser
);
10565 cp_parser_require_keyword (parser
, RID_RETURN
, RT_RETURN
);
10567 expr
= cp_parser_expression (parser
, &idk
);
10569 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
10570 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
10572 if (cp_parser_parse_definitely (parser
))
10574 if (!processing_template_decl
)
10576 tree type
= lambda_return_type (expr
);
10577 apply_deduced_return_type (fco
, type
);
10578 if (type
== error_mark_node
)
10579 expr
= error_mark_node
;
10582 /* Will get error here if type not deduced yet. */
10583 finish_return_stmt (expr
);
10591 while (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_LABEL
))
10592 cp_parser_label_declaration (parser
);
10593 cp_parser_statement_seq_opt (parser
, NULL_TREE
);
10594 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
10597 finish_compound_stmt (compound_stmt
);
10600 finish_function_body (body
);
10601 finish_lambda_scope ();
10603 /* Finish the function and generate code for it if necessary. */
10604 tree fn
= finish_function (/*inline*/2);
10606 /* Only expand if the call op is not a template. */
10607 if (!DECL_TEMPLATE_INFO (fco
))
10608 expand_or_defer_fn (fn
);
10611 restore_omp_privatization_clauses (omp_privatization_save
);
10612 parser
->local_variables_forbidden_p
= local_variables_forbidden_p
;
10614 pop_function_context();
10619 /* Statements [gram.stmt.stmt] */
10621 /* Parse a statement.
10625 expression-statement
10627 selection-statement
10628 iteration-statement
10630 declaration-statement
10637 attribute-specifier-seq (opt) expression-statement
10638 attribute-specifier-seq (opt) compound-statement
10639 attribute-specifier-seq (opt) selection-statement
10640 attribute-specifier-seq (opt) iteration-statement
10641 attribute-specifier-seq (opt) jump-statement
10642 declaration-statement
10643 attribute-specifier-seq (opt) try-block
10646 expression-statement
10654 IN_COMPOUND is true when the statement is nested inside a
10655 cp_parser_compound_statement; this matters for certain pragmas.
10657 If IF_P is not NULL, *IF_P is set to indicate whether the statement
10658 is a (possibly labeled) if statement which is not enclosed in braces
10659 and has an else clause. This is used to implement -Wparentheses.
10661 CHAIN is a vector of if-else-if conditions. */
10664 cp_parser_statement (cp_parser
* parser
, tree in_statement_expr
,
10665 bool in_compound
, bool *if_p
, vec
<tree
> *chain
,
10666 location_t
*loc_after_labels
)
10668 tree statement
, std_attrs
= NULL_TREE
;
10670 location_t statement_location
, attrs_location
;
10675 /* There is no statement yet. */
10676 statement
= NULL_TREE
;
10678 saved_token_sentinel
saved_tokens (parser
->lexer
);
10679 attrs_location
= cp_lexer_peek_token (parser
->lexer
)->location
;
10680 if (c_dialect_objc ())
10681 /* In obj-c++, seeing '[[' might be the either the beginning of
10682 c++11 attributes, or a nested objc-message-expression. So
10683 let's parse the c++11 attributes tentatively. */
10684 cp_parser_parse_tentatively (parser
);
10685 std_attrs
= cp_parser_std_attribute_spec_seq (parser
);
10686 if (c_dialect_objc ())
10688 if (!cp_parser_parse_definitely (parser
))
10689 std_attrs
= NULL_TREE
;
10692 /* Peek at the next token. */
10693 token
= cp_lexer_peek_token (parser
->lexer
);
10694 /* Remember the location of the first token in the statement. */
10695 statement_location
= token
->location
;
10696 /* If this is a keyword, then that will often determine what kind of
10697 statement we have. */
10698 if (token
->type
== CPP_KEYWORD
)
10700 enum rid keyword
= token
->keyword
;
10706 /* Looks like a labeled-statement with a case label.
10707 Parse the label, and then use tail recursion to parse
10709 cp_parser_label_for_labeled_statement (parser
, std_attrs
);
10710 in_compound
= false;
10715 statement
= cp_parser_selection_statement (parser
, if_p
, chain
);
10721 statement
= cp_parser_iteration_statement (parser
, if_p
, false);
10725 if (!flag_cilkplus
)
10727 error_at (cp_lexer_peek_token (parser
->lexer
)->location
,
10728 "-fcilkplus must be enabled to use %<_Cilk_for%>");
10729 cp_lexer_consume_token (parser
->lexer
);
10730 statement
= error_mark_node
;
10733 statement
= cp_parser_cilk_for (parser
, integer_zero_node
, if_p
);
10740 statement
= cp_parser_jump_statement (parser
);
10743 case RID_CILK_SYNC
:
10744 cp_lexer_consume_token (parser
->lexer
);
10747 tree sync_expr
= build_cilk_sync ();
10748 SET_EXPR_LOCATION (sync_expr
,
10750 statement
= finish_expr_stmt (sync_expr
);
10754 error_at (token
->location
, "-fcilkplus must be enabled to use"
10755 " %<_Cilk_sync%>");
10756 statement
= error_mark_node
;
10758 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
10761 /* Objective-C++ exception-handling constructs. */
10764 case RID_AT_FINALLY
:
10765 case RID_AT_SYNCHRONIZED
:
10767 statement
= cp_parser_objc_statement (parser
);
10771 statement
= cp_parser_try_block (parser
);
10774 case RID_NAMESPACE
:
10775 /* This must be a namespace alias definition. */
10776 cp_parser_declaration_statement (parser
);
10779 case RID_TRANSACTION_ATOMIC
:
10780 case RID_TRANSACTION_RELAXED
:
10781 case RID_SYNCHRONIZED
:
10782 case RID_ATOMIC_NOEXCEPT
:
10783 case RID_ATOMIC_CANCEL
:
10784 statement
= cp_parser_transaction (parser
, token
);
10786 case RID_TRANSACTION_CANCEL
:
10787 statement
= cp_parser_transaction_cancel (parser
);
10791 /* It might be a keyword like `int' that can start a
10792 declaration-statement. */
10796 else if (token
->type
== CPP_NAME
)
10798 /* If the next token is a `:', then we are looking at a
10799 labeled-statement. */
10800 token
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
10801 if (token
->type
== CPP_COLON
)
10803 /* Looks like a labeled-statement with an ordinary label.
10804 Parse the label, and then use tail recursion to parse
10807 cp_parser_label_for_labeled_statement (parser
, std_attrs
);
10808 in_compound
= false;
10812 /* Anything that starts with a `{' must be a compound-statement. */
10813 else if (token
->type
== CPP_OPEN_BRACE
)
10814 statement
= cp_parser_compound_statement (parser
, NULL
, BCS_NORMAL
, false);
10815 /* CPP_PRAGMA is a #pragma inside a function body, which constitutes
10816 a statement all its own. */
10817 else if (token
->type
== CPP_PRAGMA
)
10819 /* Only certain OpenMP pragmas are attached to statements, and thus
10820 are considered statements themselves. All others are not. In
10821 the context of a compound, accept the pragma as a "statement" and
10822 return so that we can check for a close brace. Otherwise we
10823 require a real statement and must go back and read one. */
10825 cp_parser_pragma (parser
, pragma_compound
, if_p
);
10826 else if (!cp_parser_pragma (parser
, pragma_stmt
, if_p
))
10830 else if (token
->type
== CPP_EOF
)
10832 cp_parser_error (parser
, "expected statement");
10836 /* Everything else must be a declaration-statement or an
10837 expression-statement. Try for the declaration-statement
10838 first, unless we are looking at a `;', in which case we know that
10839 we have an expression-statement. */
10842 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
10844 if (std_attrs
!= NULL_TREE
)
10846 /* Attributes should be parsed as part of the the
10847 declaration, so let's un-parse them. */
10848 saved_tokens
.rollback();
10849 std_attrs
= NULL_TREE
;
10852 cp_parser_parse_tentatively (parser
);
10853 /* Try to parse the declaration-statement. */
10854 cp_parser_declaration_statement (parser
);
10855 /* If that worked, we're done. */
10856 if (cp_parser_parse_definitely (parser
))
10859 /* All preceding labels have been parsed at this point. */
10860 if (loc_after_labels
!= NULL
)
10861 *loc_after_labels
= statement_location
;
10863 /* Look for an expression-statement instead. */
10864 statement
= cp_parser_expression_statement (parser
, in_statement_expr
);
10866 /* Handle [[fallthrough]];. */
10867 if (attribute_fallthrough_p (std_attrs
))
10869 /* The next token after the fallthrough attribute is ';'. */
10870 if (statement
== NULL_TREE
)
10872 /* Turn [[fallthrough]]; into FALLTHROUGH ();. */
10873 statement
= build_call_expr_internal_loc (statement_location
,
10875 void_type_node
, 0);
10876 finish_expr_stmt (statement
);
10879 warning_at (statement_location
, OPT_Wattributes
,
10880 "%<fallthrough%> attribute not followed by %<;%>");
10881 std_attrs
= NULL_TREE
;
10885 /* Set the line number for the statement. */
10886 if (statement
&& STATEMENT_CODE_P (TREE_CODE (statement
)))
10887 SET_EXPR_LOCATION (statement
, statement_location
);
10889 /* Allow "[[fallthrough]];", but warn otherwise. */
10890 if (std_attrs
!= NULL_TREE
)
10891 warning_at (attrs_location
,
10893 "attributes at the beginning of statement are ignored");
10896 /* Parse the label for a labeled-statement, i.e.
10899 case constant-expression :
10903 case constant-expression ... constant-expression : statement
10905 When a label is parsed without errors, the label is added to the
10906 parse tree by the finish_* functions, so this function doesn't
10907 have to return the label. */
10910 cp_parser_label_for_labeled_statement (cp_parser
* parser
, tree attributes
)
10913 tree label
= NULL_TREE
;
10914 bool saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
10916 /* The next token should be an identifier. */
10917 token
= cp_lexer_peek_token (parser
->lexer
);
10918 if (token
->type
!= CPP_NAME
10919 && token
->type
!= CPP_KEYWORD
)
10921 cp_parser_error (parser
, "expected labeled-statement");
10925 /* Remember whether this case or a user-defined label is allowed to fall
10927 bool fallthrough_p
= token
->flags
& PREV_FALLTHROUGH
;
10929 parser
->colon_corrects_to_scope_p
= false;
10930 switch (token
->keyword
)
10934 tree expr
, expr_hi
;
10935 cp_token
*ellipsis
;
10937 /* Consume the `case' token. */
10938 cp_lexer_consume_token (parser
->lexer
);
10939 /* Parse the constant-expression. */
10940 expr
= cp_parser_constant_expression (parser
);
10941 if (check_for_bare_parameter_packs (expr
))
10942 expr
= error_mark_node
;
10944 ellipsis
= cp_lexer_peek_token (parser
->lexer
);
10945 if (ellipsis
->type
== CPP_ELLIPSIS
)
10947 /* Consume the `...' token. */
10948 cp_lexer_consume_token (parser
->lexer
);
10949 expr_hi
= cp_parser_constant_expression (parser
);
10950 if (check_for_bare_parameter_packs (expr_hi
))
10951 expr_hi
= error_mark_node
;
10953 /* We don't need to emit warnings here, as the common code
10954 will do this for us. */
10957 expr_hi
= NULL_TREE
;
10959 if (parser
->in_switch_statement_p
)
10961 tree l
= finish_case_label (token
->location
, expr
, expr_hi
);
10962 if (l
&& TREE_CODE (l
) == CASE_LABEL_EXPR
)
10963 FALLTHROUGH_LABEL_P (CASE_LABEL (l
)) = fallthrough_p
;
10966 error_at (token
->location
,
10967 "case label %qE not within a switch statement",
10973 /* Consume the `default' token. */
10974 cp_lexer_consume_token (parser
->lexer
);
10976 if (parser
->in_switch_statement_p
)
10978 tree l
= finish_case_label (token
->location
, NULL_TREE
, NULL_TREE
);
10979 if (l
&& TREE_CODE (l
) == CASE_LABEL_EXPR
)
10980 FALLTHROUGH_LABEL_P (CASE_LABEL (l
)) = fallthrough_p
;
10983 error_at (token
->location
, "case label not within a switch statement");
10987 /* Anything else must be an ordinary label. */
10988 label
= finish_label_stmt (cp_parser_identifier (parser
));
10989 if (label
&& TREE_CODE (label
) == LABEL_DECL
)
10990 FALLTHROUGH_LABEL_P (label
) = fallthrough_p
;
10994 /* Require the `:' token. */
10995 cp_parser_require (parser
, CPP_COLON
, RT_COLON
);
10997 /* An ordinary label may optionally be followed by attributes.
10998 However, this is only permitted if the attributes are then
10999 followed by a semicolon. This is because, for backward
11000 compatibility, when parsing
11001 lab: __attribute__ ((unused)) int i;
11002 we want the attribute to attach to "i", not "lab". */
11003 if (label
!= NULL_TREE
11004 && cp_next_tokens_can_be_gnu_attribute_p (parser
))
11007 cp_parser_parse_tentatively (parser
);
11008 attrs
= cp_parser_gnu_attributes_opt (parser
);
11009 if (attrs
== NULL_TREE
11010 || cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
11011 cp_parser_abort_tentative_parse (parser
);
11012 else if (!cp_parser_parse_definitely (parser
))
11015 attributes
= chainon (attributes
, attrs
);
11018 if (attributes
!= NULL_TREE
)
11019 cplus_decl_attributes (&label
, attributes
, 0);
11021 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
11024 /* Parse an expression-statement.
11026 expression-statement:
11029 Returns the new EXPR_STMT -- or NULL_TREE if the expression
11030 statement consists of nothing more than an `;'. IN_STATEMENT_EXPR_P
11031 indicates whether this expression-statement is part of an
11032 expression statement. */
11035 cp_parser_expression_statement (cp_parser
* parser
, tree in_statement_expr
)
11037 tree statement
= NULL_TREE
;
11038 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
11039 location_t loc
= token
->location
;
11041 /* There might be attribute fallthrough. */
11042 tree attr
= cp_parser_gnu_attributes_opt (parser
);
11044 /* If the next token is a ';', then there is no expression
11046 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
11048 statement
= cp_parser_expression (parser
);
11049 if (statement
== error_mark_node
11050 && !cp_parser_uncommitted_to_tentative_parse_p (parser
))
11052 cp_parser_skip_to_end_of_block_or_statement (parser
);
11053 return error_mark_node
;
11057 /* Handle [[fallthrough]];. */
11058 if (attribute_fallthrough_p (attr
))
11060 /* The next token after the fallthrough attribute is ';'. */
11061 if (statement
== NULL_TREE
)
11062 /* Turn [[fallthrough]]; into FALLTHROUGH ();. */
11063 statement
= build_call_expr_internal_loc (loc
, IFN_FALLTHROUGH
,
11064 void_type_node
, 0);
11066 warning_at (loc
, OPT_Wattributes
,
11067 "%<fallthrough%> attribute not followed by %<;%>");
11071 /* Allow "[[fallthrough]];", but warn otherwise. */
11072 if (attr
!= NULL_TREE
)
11073 warning_at (loc
, OPT_Wattributes
,
11074 "attributes at the beginning of statement are ignored");
11076 /* Give a helpful message for "A<T>::type t;" and the like. */
11077 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
)
11078 && !cp_parser_uncommitted_to_tentative_parse_p (parser
))
11080 if (TREE_CODE (statement
) == SCOPE_REF
)
11081 error_at (token
->location
, "need %<typename%> before %qE because "
11082 "%qT is a dependent scope",
11083 statement
, TREE_OPERAND (statement
, 0));
11084 else if (is_overloaded_fn (statement
)
11085 && DECL_CONSTRUCTOR_P (get_first_fn (statement
)))
11088 tree fn
= get_first_fn (statement
);
11089 error_at (token
->location
,
11090 "%<%T::%D%> names the constructor, not the type",
11091 DECL_CONTEXT (fn
), DECL_NAME (fn
));
11095 /* Consume the final `;'. */
11096 cp_parser_consume_semicolon_at_end_of_statement (parser
);
11098 if (in_statement_expr
11099 && cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_BRACE
))
11100 /* This is the final expression statement of a statement
11102 statement
= finish_stmt_expr_expr (statement
, in_statement_expr
);
11103 else if (statement
)
11104 statement
= finish_expr_stmt (statement
);
11109 /* Parse a compound-statement.
11111 compound-statement:
11112 { statement-seq [opt] }
11116 compound-statement:
11117 { label-declaration-seq [opt] statement-seq [opt] }
11119 label-declaration-seq:
11121 label-declaration-seq label-declaration
11123 Returns a tree representing the statement. */
11126 cp_parser_compound_statement (cp_parser
*parser
, tree in_statement_expr
,
11127 int bcs_flags
, bool function_body
)
11129 tree compound_stmt
;
11131 /* Consume the `{'. */
11132 if (!cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
))
11133 return error_mark_node
;
11134 if (DECL_DECLARED_CONSTEXPR_P (current_function_decl
)
11135 && !function_body
&& cxx_dialect
< cxx14
)
11136 pedwarn (input_location
, OPT_Wpedantic
,
11137 "compound-statement in constexpr function");
11138 /* Begin the compound-statement. */
11139 compound_stmt
= begin_compound_stmt (bcs_flags
);
11140 /* If the next keyword is `__label__' we have a label declaration. */
11141 while (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_LABEL
))
11142 cp_parser_label_declaration (parser
);
11143 /* Parse an (optional) statement-seq. */
11144 cp_parser_statement_seq_opt (parser
, in_statement_expr
);
11145 /* Finish the compound-statement. */
11146 finish_compound_stmt (compound_stmt
);
11147 /* Consume the `}'. */
11148 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
11150 return compound_stmt
;
11153 /* Parse an (optional) statement-seq.
11157 statement-seq [opt] statement */
11160 cp_parser_statement_seq_opt (cp_parser
* parser
, tree in_statement_expr
)
11162 /* Scan statements until there aren't any more. */
11165 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
11167 /* If we are looking at a `}', then we have run out of
11168 statements; the same is true if we have reached the end
11169 of file, or have stumbled upon a stray '@end'. */
11170 if (token
->type
== CPP_CLOSE_BRACE
11171 || token
->type
== CPP_EOF
11172 || token
->type
== CPP_PRAGMA_EOL
11173 || (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_AT_END
))
11176 /* If we are in a compound statement and find 'else' then
11177 something went wrong. */
11178 else if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_ELSE
)
11180 if (parser
->in_statement
& IN_IF_STMT
)
11184 token
= cp_lexer_consume_token (parser
->lexer
);
11185 error_at (token
->location
, "%<else%> without a previous %<if%>");
11189 /* Parse the statement. */
11190 cp_parser_statement (parser
, in_statement_expr
, true, NULL
);
11194 /* Return true if we're looking at (init; cond), false otherwise. */
11197 cp_parser_init_statement_p (cp_parser
*parser
)
11199 /* Save tokens so that we can put them back. */
11200 cp_lexer_save_tokens (parser
->lexer
);
11202 /* Look for ';' that is not nested in () or {}. */
11203 int ret
= cp_parser_skip_to_closing_parenthesis_1 (parser
,
11204 /*recovering=*/false,
11206 /*consume_paren=*/false);
11208 /* Roll back the tokens we skipped. */
11209 cp_lexer_rollback_tokens (parser
->lexer
);
11214 /* Parse a selection-statement.
11216 selection-statement:
11217 if ( init-statement [opt] condition ) statement
11218 if ( init-statement [opt] condition ) statement else statement
11219 switch ( init-statement [opt] condition ) statement
11221 Returns the new IF_STMT or SWITCH_STMT.
11223 If IF_P is not NULL, *IF_P is set to indicate whether the statement
11224 is a (possibly labeled) if statement which is not enclosed in
11225 braces and has an else clause. This is used to implement
11228 CHAIN is a vector of if-else-if conditions. This is used to implement
11229 -Wduplicated-cond. */
11232 cp_parser_selection_statement (cp_parser
* parser
, bool *if_p
,
11237 token_indent_info guard_tinfo
;
11242 /* Peek at the next token. */
11243 token
= cp_parser_require (parser
, CPP_KEYWORD
, RT_SELECT
);
11244 guard_tinfo
= get_token_indent_info (token
);
11246 /* See what kind of keyword it is. */
11247 keyword
= token
->keyword
;
11257 if (keyword
== RID_IF
11258 && cp_lexer_next_token_is_keyword (parser
->lexer
,
11262 cp_token
*tok
= cp_lexer_consume_token (parser
->lexer
);
11263 if (cxx_dialect
< cxx1z
&& !in_system_header_at (tok
->location
))
11264 pedwarn (tok
->location
, 0, "%<if constexpr%> only available "
11265 "with -std=c++1z or -std=gnu++1z");
11268 /* Look for the `('. */
11269 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
11271 cp_parser_skip_to_end_of_statement (parser
);
11272 return error_mark_node
;
11275 /* Begin the selection-statement. */
11276 if (keyword
== RID_IF
)
11278 statement
= begin_if_stmt ();
11279 IF_STMT_CONSTEXPR_P (statement
) = cx
;
11282 statement
= begin_switch_stmt ();
11284 /* Parse the optional init-statement. */
11285 if (cp_parser_init_statement_p (parser
))
11288 if (cxx_dialect
< cxx1z
)
11289 pedwarn (cp_lexer_peek_token (parser
->lexer
)->location
, 0,
11290 "init-statement in selection statements only available "
11291 "with -std=c++1z or -std=gnu++1z");
11292 cp_parser_init_statement (parser
, &decl
);
11295 /* Parse the condition. */
11296 condition
= cp_parser_condition (parser
);
11297 /* Look for the `)'. */
11298 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
11299 cp_parser_skip_to_closing_parenthesis (parser
, true, false,
11300 /*consume_paren=*/true);
11302 if (keyword
== RID_IF
)
11305 unsigned char in_statement
;
11307 /* Add the condition. */
11308 condition
= finish_if_stmt_cond (condition
, statement
);
11310 if (warn_duplicated_cond
)
11311 warn_duplicated_cond_add_or_warn (token
->location
, condition
,
11314 /* Parse the then-clause. */
11315 in_statement
= parser
->in_statement
;
11316 parser
->in_statement
|= IN_IF_STMT
;
11318 /* Outside a template, the non-selected branch of a constexpr
11319 if is a 'discarded statement', i.e. unevaluated. */
11320 bool was_discarded
= in_discarded_stmt
;
11321 bool discard_then
= (cx
&& !processing_template_decl
11322 && integer_zerop (condition
));
11325 in_discarded_stmt
= true;
11326 ++c_inhibit_evaluation_warnings
;
11329 cp_parser_implicitly_scoped_statement (parser
, &nested_if
,
11332 parser
->in_statement
= in_statement
;
11334 finish_then_clause (statement
);
11338 THEN_CLAUSE (statement
) = NULL_TREE
;
11339 in_discarded_stmt
= was_discarded
;
11340 --c_inhibit_evaluation_warnings
;
11343 /* If the next token is `else', parse the else-clause. */
11344 if (cp_lexer_next_token_is_keyword (parser
->lexer
,
11347 bool discard_else
= (cx
&& !processing_template_decl
11348 && integer_nonzerop (condition
));
11351 in_discarded_stmt
= true;
11352 ++c_inhibit_evaluation_warnings
;
11356 = get_token_indent_info (cp_lexer_peek_token (parser
->lexer
));
11357 /* Consume the `else' keyword. */
11358 cp_lexer_consume_token (parser
->lexer
);
11359 if (warn_duplicated_cond
)
11361 if (cp_lexer_next_token_is_keyword (parser
->lexer
,
11365 /* We've got "if (COND) else if (COND2)". Start
11366 the condition chain and add COND as the first
11368 chain
= new vec
<tree
> ();
11369 if (!CONSTANT_CLASS_P (condition
)
11370 && !TREE_SIDE_EFFECTS (condition
))
11372 /* Wrap it in a NOP_EXPR so that we can set the
11373 location of the condition. */
11374 tree e
= build1 (NOP_EXPR
, TREE_TYPE (condition
),
11376 SET_EXPR_LOCATION (e
, token
->location
);
11377 chain
->safe_push (e
);
11380 else if (!cp_lexer_next_token_is_keyword (parser
->lexer
,
11383 /* This is if-else without subsequent if. Zap the
11384 condition chain; we would have already warned at
11390 begin_else_clause (statement
);
11391 /* Parse the else-clause. */
11392 cp_parser_implicitly_scoped_statement (parser
, NULL
,
11393 guard_tinfo
, chain
);
11395 finish_else_clause (statement
);
11397 /* If we are currently parsing a then-clause, then
11398 IF_P will not be NULL. We set it to true to
11399 indicate that this if statement has an else clause.
11400 This may trigger the Wparentheses warning below
11401 when we get back up to the parent if statement. */
11407 ELSE_CLAUSE (statement
) = NULL_TREE
;
11408 in_discarded_stmt
= was_discarded
;
11409 --c_inhibit_evaluation_warnings
;
11414 /* This if statement does not have an else clause. If
11415 NESTED_IF is true, then the then-clause has an if
11416 statement which does have an else clause. We warn
11417 about the potential ambiguity. */
11419 warning_at (EXPR_LOCATION (statement
), OPT_Wdangling_else
,
11420 "suggest explicit braces to avoid ambiguous"
11422 if (warn_duplicated_cond
)
11424 /* We don't need the condition chain anymore. */
11430 /* Now we're all done with the if-statement. */
11431 finish_if_stmt (statement
);
11435 bool in_switch_statement_p
;
11436 unsigned char in_statement
;
11438 /* Add the condition. */
11439 finish_switch_cond (condition
, statement
);
11441 /* Parse the body of the switch-statement. */
11442 in_switch_statement_p
= parser
->in_switch_statement_p
;
11443 in_statement
= parser
->in_statement
;
11444 parser
->in_switch_statement_p
= true;
11445 parser
->in_statement
|= IN_SWITCH_STMT
;
11446 cp_parser_implicitly_scoped_statement (parser
, if_p
,
11448 parser
->in_switch_statement_p
= in_switch_statement_p
;
11449 parser
->in_statement
= in_statement
;
11451 /* Now we're all done with the switch-statement. */
11452 finish_switch_stmt (statement
);
11460 cp_parser_error (parser
, "expected selection-statement");
11461 return error_mark_node
;
11465 /* Parse a condition.
11469 type-specifier-seq declarator = initializer-clause
11470 type-specifier-seq declarator braced-init-list
11475 type-specifier-seq declarator asm-specification [opt]
11476 attributes [opt] = assignment-expression
11478 Returns the expression that should be tested. */
11481 cp_parser_condition (cp_parser
* parser
)
11483 cp_decl_specifier_seq type_specifiers
;
11484 const char *saved_message
;
11485 int declares_class_or_enum
;
11487 /* Try the declaration first. */
11488 cp_parser_parse_tentatively (parser
);
11489 /* New types are not allowed in the type-specifier-seq for a
11491 saved_message
= parser
->type_definition_forbidden_message
;
11492 parser
->type_definition_forbidden_message
11493 = G_("types may not be defined in conditions");
11494 /* Parse the type-specifier-seq. */
11495 cp_parser_decl_specifier_seq (parser
,
11496 CP_PARSER_FLAGS_ONLY_TYPE_OR_CONSTEXPR
,
11498 &declares_class_or_enum
);
11499 /* Restore the saved message. */
11500 parser
->type_definition_forbidden_message
= saved_message
;
11501 /* If all is well, we might be looking at a declaration. */
11502 if (!cp_parser_error_occurred (parser
))
11505 tree asm_specification
;
11507 cp_declarator
*declarator
;
11508 tree initializer
= NULL_TREE
;
11510 /* Parse the declarator. */
11511 declarator
= cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_NAMED
,
11512 /*ctor_dtor_or_conv_p=*/NULL
,
11513 /*parenthesized_p=*/NULL
,
11514 /*member_p=*/false,
11515 /*friend_p=*/false);
11516 /* Parse the attributes. */
11517 attributes
= cp_parser_attributes_opt (parser
);
11518 /* Parse the asm-specification. */
11519 asm_specification
= cp_parser_asm_specification_opt (parser
);
11520 /* If the next token is not an `=' or '{', then we might still be
11521 looking at an expression. For example:
11525 looks like a decl-specifier-seq and a declarator -- but then
11526 there is no `=', so this is an expression. */
11527 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_EQ
)
11528 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_BRACE
))
11529 cp_parser_simulate_error (parser
);
11531 /* If we did see an `=' or '{', then we are looking at a declaration
11533 if (cp_parser_parse_definitely (parser
))
11536 bool non_constant_p
;
11537 int flags
= LOOKUP_ONLYCONVERTING
;
11539 /* Create the declaration. */
11540 decl
= start_decl (declarator
, &type_specifiers
,
11541 /*initialized_p=*/true,
11542 attributes
, /*prefix_attributes=*/NULL_TREE
,
11545 /* Parse the initializer. */
11546 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
11548 initializer
= cp_parser_braced_list (parser
, &non_constant_p
);
11549 CONSTRUCTOR_IS_DIRECT_INIT (initializer
) = 1;
11554 /* Consume the `='. */
11555 cp_parser_require (parser
, CPP_EQ
, RT_EQ
);
11556 initializer
= cp_parser_initializer_clause (parser
, &non_constant_p
);
11558 if (BRACE_ENCLOSED_INITIALIZER_P (initializer
))
11559 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
11561 /* Process the initializer. */
11562 cp_finish_decl (decl
,
11563 initializer
, !non_constant_p
,
11568 pop_scope (pushed_scope
);
11570 return convert_from_reference (decl
);
11573 /* If we didn't even get past the declarator successfully, we are
11574 definitely not looking at a declaration. */
11576 cp_parser_abort_tentative_parse (parser
);
11578 /* Otherwise, we are looking at an expression. */
11579 return cp_parser_expression (parser
);
11582 /* Parses a for-statement or range-for-statement until the closing ')',
11586 cp_parser_for (cp_parser
*parser
, bool ivdep
)
11588 tree init
, scope
, decl
;
11591 /* Begin the for-statement. */
11592 scope
= begin_for_scope (&init
);
11594 /* Parse the initialization. */
11595 is_range_for
= cp_parser_init_statement (parser
, &decl
);
11598 return cp_parser_range_for (parser
, scope
, init
, decl
, ivdep
);
11600 return cp_parser_c_for (parser
, scope
, init
, ivdep
);
11604 cp_parser_c_for (cp_parser
*parser
, tree scope
, tree init
, bool ivdep
)
11606 /* Normal for loop */
11607 tree condition
= NULL_TREE
;
11608 tree expression
= NULL_TREE
;
11611 stmt
= begin_for_stmt (scope
, init
);
11612 /* The init-statement has already been parsed in
11613 cp_parser_init_statement, so no work is needed here. */
11614 finish_init_stmt (stmt
);
11616 /* If there's a condition, process it. */
11617 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
11618 condition
= cp_parser_condition (parser
);
11621 cp_parser_error (parser
, "missing loop condition in loop with "
11622 "%<GCC ivdep%> pragma");
11623 condition
= error_mark_node
;
11625 finish_for_cond (condition
, stmt
, ivdep
);
11626 /* Look for the `;'. */
11627 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
11629 /* If there's an expression, process it. */
11630 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_PAREN
))
11631 expression
= cp_parser_expression (parser
);
11632 finish_for_expr (expression
, stmt
);
11637 /* Tries to parse a range-based for-statement:
11640 decl-specifier-seq declarator : expression
11642 The decl-specifier-seq declarator and the `:' are already parsed by
11643 cp_parser_init_statement. If processing_template_decl it returns a
11644 newly created RANGE_FOR_STMT; if not, it is converted to a
11645 regular FOR_STMT. */
11648 cp_parser_range_for (cp_parser
*parser
, tree scope
, tree init
, tree range_decl
,
11651 tree stmt
, range_expr
;
11652 auto_vec
<cxx_binding
*, 16> bindings
;
11653 auto_vec
<tree
, 16> names
;
11654 tree decomp_first_name
= NULL_TREE
;
11655 unsigned int decomp_cnt
= 0;
11657 /* Get the range declaration momentarily out of the way so that
11658 the range expression doesn't clash with it. */
11659 if (range_decl
!= error_mark_node
)
11661 if (DECL_HAS_VALUE_EXPR_P (range_decl
))
11663 tree v
= DECL_VALUE_EXPR (range_decl
);
11664 /* For decomposition declaration get all of the corresponding
11665 declarations out of the way. */
11666 if (TREE_CODE (v
) == ARRAY_REF
11667 && VAR_P (TREE_OPERAND (v
, 0))
11668 && DECL_DECOMPOSITION_P (TREE_OPERAND (v
, 0)))
11670 tree d
= range_decl
;
11671 range_decl
= TREE_OPERAND (v
, 0);
11672 decomp_cnt
= tree_to_uhwi (TREE_OPERAND (v
, 1)) + 1;
11673 decomp_first_name
= d
;
11674 for (unsigned int i
= 0; i
< decomp_cnt
; i
++, d
= DECL_CHAIN (d
))
11676 tree name
= DECL_NAME (d
);
11677 names
.safe_push (name
);
11678 bindings
.safe_push (IDENTIFIER_BINDING (name
));
11679 IDENTIFIER_BINDING (name
)
11680 = IDENTIFIER_BINDING (name
)->previous
;
11684 if (names
.is_empty ())
11686 tree name
= DECL_NAME (range_decl
);
11687 names
.safe_push (name
);
11688 bindings
.safe_push (IDENTIFIER_BINDING (name
));
11689 IDENTIFIER_BINDING (name
) = IDENTIFIER_BINDING (name
)->previous
;
11693 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
11695 bool expr_non_constant_p
;
11696 range_expr
= cp_parser_braced_list (parser
, &expr_non_constant_p
);
11699 range_expr
= cp_parser_expression (parser
);
11701 /* Put the range declaration(s) back into scope. */
11702 for (unsigned int i
= 0; i
< names
.length (); i
++)
11704 cxx_binding
*binding
= bindings
[i
];
11705 binding
->previous
= IDENTIFIER_BINDING (names
[i
]);
11706 IDENTIFIER_BINDING (names
[i
]) = binding
;
11709 /* If in template, STMT is converted to a normal for-statement
11710 at instantiation. If not, it is done just ahead. */
11711 if (processing_template_decl
)
11713 if (check_for_bare_parameter_packs (range_expr
))
11714 range_expr
= error_mark_node
;
11715 stmt
= begin_range_for_stmt (scope
, init
);
11717 RANGE_FOR_IVDEP (stmt
) = 1;
11718 finish_range_for_decl (stmt
, range_decl
, range_expr
);
11719 if (!type_dependent_expression_p (range_expr
)
11720 /* do_auto_deduction doesn't mess with template init-lists. */
11721 && !BRACE_ENCLOSED_INITIALIZER_P (range_expr
))
11722 do_range_for_auto_deduction (range_decl
, range_expr
);
11726 stmt
= begin_for_stmt (scope
, init
);
11727 stmt
= cp_convert_range_for (stmt
, range_decl
, range_expr
,
11728 decomp_first_name
, decomp_cnt
, ivdep
);
11733 /* Subroutine of cp_convert_range_for: given the initializer expression,
11734 builds up the range temporary. */
11737 build_range_temp (tree range_expr
)
11739 tree range_type
, range_temp
;
11741 /* Find out the type deduced by the declaration
11742 `auto &&__range = range_expr'. */
11743 range_type
= cp_build_reference_type (make_auto (), true);
11744 range_type
= do_auto_deduction (range_type
, range_expr
,
11745 type_uses_auto (range_type
));
11747 /* Create the __range variable. */
11748 range_temp
= build_decl (input_location
, VAR_DECL
,
11749 get_identifier ("__for_range"), range_type
);
11750 TREE_USED (range_temp
) = 1;
11751 DECL_ARTIFICIAL (range_temp
) = 1;
11756 /* Used by cp_parser_range_for in template context: we aren't going to
11757 do a full conversion yet, but we still need to resolve auto in the
11758 type of the for-range-declaration if present. This is basically
11759 a shortcut version of cp_convert_range_for. */
11762 do_range_for_auto_deduction (tree decl
, tree range_expr
)
11764 tree auto_node
= type_uses_auto (TREE_TYPE (decl
));
11767 tree begin_dummy
, end_dummy
, range_temp
, iter_type
, iter_decl
;
11768 range_temp
= convert_from_reference (build_range_temp (range_expr
));
11769 iter_type
= (cp_parser_perform_range_for_lookup
11770 (range_temp
, &begin_dummy
, &end_dummy
));
11773 iter_decl
= build_decl (input_location
, VAR_DECL
, NULL_TREE
,
11775 iter_decl
= build_x_indirect_ref (input_location
, iter_decl
, RO_NULL
,
11776 tf_warning_or_error
);
11777 TREE_TYPE (decl
) = do_auto_deduction (TREE_TYPE (decl
),
11778 iter_decl
, auto_node
);
11783 /* Converts a range-based for-statement into a normal
11784 for-statement, as per the definition.
11786 for (RANGE_DECL : RANGE_EXPR)
11789 should be equivalent to:
11792 auto &&__range = RANGE_EXPR;
11793 for (auto __begin = BEGIN_EXPR, end = END_EXPR;
11797 RANGE_DECL = *__begin;
11802 If RANGE_EXPR is an array:
11803 BEGIN_EXPR = __range
11804 END_EXPR = __range + ARRAY_SIZE(__range)
11805 Else if RANGE_EXPR has a member 'begin' or 'end':
11806 BEGIN_EXPR = __range.begin()
11807 END_EXPR = __range.end()
11809 BEGIN_EXPR = begin(__range)
11810 END_EXPR = end(__range);
11812 If __range has a member 'begin' but not 'end', or vice versa, we must
11813 still use the second alternative (it will surely fail, however).
11814 When calling begin()/end() in the third alternative we must use
11815 argument dependent lookup, but always considering 'std' as an associated
11819 cp_convert_range_for (tree statement
, tree range_decl
, tree range_expr
,
11820 tree decomp_first_name
, unsigned int decomp_cnt
,
11824 tree iter_type
, begin_expr
, end_expr
;
11825 tree condition
, expression
;
11827 if (range_decl
== error_mark_node
|| range_expr
== error_mark_node
)
11828 /* If an error happened previously do nothing or else a lot of
11829 unhelpful errors would be issued. */
11830 begin_expr
= end_expr
= iter_type
= error_mark_node
;
11835 if (VAR_P (range_expr
)
11836 && array_of_runtime_bound_p (TREE_TYPE (range_expr
)))
11837 /* Can't bind a reference to an array of runtime bound. */
11838 range_temp
= range_expr
;
11841 range_temp
= build_range_temp (range_expr
);
11842 pushdecl (range_temp
);
11843 cp_finish_decl (range_temp
, range_expr
,
11844 /*is_constant_init*/false, NULL_TREE
,
11845 LOOKUP_ONLYCONVERTING
);
11846 range_temp
= convert_from_reference (range_temp
);
11848 iter_type
= cp_parser_perform_range_for_lookup (range_temp
,
11849 &begin_expr
, &end_expr
);
11852 /* The new for initialization statement. */
11853 begin
= build_decl (input_location
, VAR_DECL
,
11854 get_identifier ("__for_begin"), iter_type
);
11855 TREE_USED (begin
) = 1;
11856 DECL_ARTIFICIAL (begin
) = 1;
11858 cp_finish_decl (begin
, begin_expr
,
11859 /*is_constant_init*/false, NULL_TREE
,
11860 LOOKUP_ONLYCONVERTING
);
11862 if (cxx_dialect
>= cxx1z
)
11863 iter_type
= cv_unqualified (TREE_TYPE (end_expr
));
11864 end
= build_decl (input_location
, VAR_DECL
,
11865 get_identifier ("__for_end"), iter_type
);
11866 TREE_USED (end
) = 1;
11867 DECL_ARTIFICIAL (end
) = 1;
11869 cp_finish_decl (end
, end_expr
,
11870 /*is_constant_init*/false, NULL_TREE
,
11871 LOOKUP_ONLYCONVERTING
);
11873 finish_init_stmt (statement
);
11875 /* The new for condition. */
11876 condition
= build_x_binary_op (input_location
, NE_EXPR
,
11879 NULL
, tf_warning_or_error
);
11880 finish_for_cond (condition
, statement
, ivdep
);
11882 /* The new increment expression. */
11883 expression
= finish_unary_op_expr (input_location
,
11884 PREINCREMENT_EXPR
, begin
,
11885 tf_warning_or_error
);
11886 finish_for_expr (expression
, statement
);
11888 /* The declaration is initialized with *__begin inside the loop body. */
11889 cp_finish_decl (range_decl
,
11890 build_x_indirect_ref (input_location
, begin
, RO_NULL
,
11891 tf_warning_or_error
),
11892 /*is_constant_init*/false, NULL_TREE
,
11893 LOOKUP_ONLYCONVERTING
);
11894 if (VAR_P (range_decl
) && DECL_DECOMPOSITION_P (range_decl
))
11895 cp_finish_decomp (range_decl
, decomp_first_name
, decomp_cnt
);
11900 /* Solves BEGIN_EXPR and END_EXPR as described in cp_convert_range_for.
11901 We need to solve both at the same time because the method used
11902 depends on the existence of members begin or end.
11903 Returns the type deduced for the iterator expression. */
11906 cp_parser_perform_range_for_lookup (tree range
, tree
*begin
, tree
*end
)
11908 if (error_operand_p (range
))
11910 *begin
= *end
= error_mark_node
;
11911 return error_mark_node
;
11914 if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (range
))))
11916 error ("range-based %<for%> expression of type %qT "
11917 "has incomplete type", TREE_TYPE (range
));
11918 *begin
= *end
= error_mark_node
;
11919 return error_mark_node
;
11921 if (TREE_CODE (TREE_TYPE (range
)) == ARRAY_TYPE
)
11923 /* If RANGE is an array, we will use pointer arithmetic. */
11924 *begin
= decay_conversion (range
, tf_warning_or_error
);
11925 *end
= build_binary_op (input_location
, PLUS_EXPR
,
11927 array_type_nelts_top (TREE_TYPE (range
)),
11929 return TREE_TYPE (*begin
);
11933 /* If it is not an array, we must do a bit of magic. */
11934 tree id_begin
, id_end
;
11935 tree member_begin
, member_end
;
11937 *begin
= *end
= error_mark_node
;
11939 id_begin
= get_identifier ("begin");
11940 id_end
= get_identifier ("end");
11941 member_begin
= lookup_member (TREE_TYPE (range
), id_begin
,
11942 /*protect=*/2, /*want_type=*/false,
11943 tf_warning_or_error
);
11944 member_end
= lookup_member (TREE_TYPE (range
), id_end
,
11945 /*protect=*/2, /*want_type=*/false,
11946 tf_warning_or_error
);
11948 if (member_begin
!= NULL_TREE
|| member_end
!= NULL_TREE
)
11950 /* Use the member functions. */
11951 if (member_begin
!= NULL_TREE
)
11952 *begin
= cp_parser_range_for_member_function (range
, id_begin
);
11954 error ("range-based %<for%> expression of type %qT has an "
11955 "%<end%> member but not a %<begin%>", TREE_TYPE (range
));
11957 if (member_end
!= NULL_TREE
)
11958 *end
= cp_parser_range_for_member_function (range
, id_end
);
11960 error ("range-based %<for%> expression of type %qT has a "
11961 "%<begin%> member but not an %<end%>", TREE_TYPE (range
));
11965 /* Use global functions with ADL. */
11966 vec
<tree
, va_gc
> *vec
;
11967 vec
= make_tree_vector ();
11969 vec_safe_push (vec
, range
);
11971 member_begin
= perform_koenig_lookup (id_begin
, vec
,
11972 tf_warning_or_error
);
11973 *begin
= finish_call_expr (member_begin
, &vec
, false, true,
11974 tf_warning_or_error
);
11975 member_end
= perform_koenig_lookup (id_end
, vec
,
11976 tf_warning_or_error
);
11977 *end
= finish_call_expr (member_end
, &vec
, false, true,
11978 tf_warning_or_error
);
11980 release_tree_vector (vec
);
11983 /* Last common checks. */
11984 if (*begin
== error_mark_node
|| *end
== error_mark_node
)
11986 /* If one of the expressions is an error do no more checks. */
11987 *begin
= *end
= error_mark_node
;
11988 return error_mark_node
;
11990 else if (type_dependent_expression_p (*begin
)
11991 || type_dependent_expression_p (*end
))
11992 /* Can happen, when, eg, in a template context, Koenig lookup
11993 can't resolve begin/end (c++/58503). */
11997 tree iter_type
= cv_unqualified (TREE_TYPE (*begin
));
11998 /* The unqualified type of the __begin and __end temporaries should
11999 be the same, as required by the multiple auto declaration. */
12000 if (!same_type_p (iter_type
, cv_unqualified (TREE_TYPE (*end
))))
12002 if (cxx_dialect
>= cxx1z
12003 && (build_x_binary_op (input_location
, NE_EXPR
,
12004 *begin
, ERROR_MARK
,
12007 != error_mark_node
))
12008 /* P0184R0 allows __begin and __end to have different types,
12009 but make sure they are comparable so we can give a better
12012 error ("inconsistent begin/end types in range-based %<for%> "
12013 "statement: %qT and %qT",
12014 TREE_TYPE (*begin
), TREE_TYPE (*end
));
12021 /* Helper function for cp_parser_perform_range_for_lookup.
12022 Builds a tree for RANGE.IDENTIFIER(). */
12025 cp_parser_range_for_member_function (tree range
, tree identifier
)
12028 vec
<tree
, va_gc
> *vec
;
12030 member
= finish_class_member_access_expr (range
, identifier
,
12031 false, tf_warning_or_error
);
12032 if (member
== error_mark_node
)
12033 return error_mark_node
;
12035 vec
= make_tree_vector ();
12036 res
= finish_call_expr (member
, &vec
,
12037 /*disallow_virtual=*/false,
12038 /*koenig_p=*/false,
12039 tf_warning_or_error
);
12040 release_tree_vector (vec
);
12044 /* Parse an iteration-statement.
12046 iteration-statement:
12047 while ( condition ) statement
12048 do statement while ( expression ) ;
12049 for ( init-statement condition [opt] ; expression [opt] )
12052 Returns the new WHILE_STMT, DO_STMT, FOR_STMT or RANGE_FOR_STMT. */
12055 cp_parser_iteration_statement (cp_parser
* parser
, bool *if_p
, bool ivdep
)
12060 unsigned char in_statement
;
12061 token_indent_info guard_tinfo
;
12063 /* Peek at the next token. */
12064 token
= cp_parser_require (parser
, CPP_KEYWORD
, RT_ITERATION
);
12066 return error_mark_node
;
12068 guard_tinfo
= get_token_indent_info (token
);
12070 /* Remember whether or not we are already within an iteration
12072 in_statement
= parser
->in_statement
;
12074 /* See what kind of keyword it is. */
12075 keyword
= token
->keyword
;
12082 /* Begin the while-statement. */
12083 statement
= begin_while_stmt ();
12084 /* Look for the `('. */
12085 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
12086 /* Parse the condition. */
12087 condition
= cp_parser_condition (parser
);
12088 finish_while_stmt_cond (condition
, statement
, ivdep
);
12089 /* Look for the `)'. */
12090 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
12091 /* Parse the dependent statement. */
12092 parser
->in_statement
= IN_ITERATION_STMT
;
12093 cp_parser_already_scoped_statement (parser
, if_p
, guard_tinfo
);
12094 parser
->in_statement
= in_statement
;
12095 /* We're done with the while-statement. */
12096 finish_while_stmt (statement
);
12104 /* Begin the do-statement. */
12105 statement
= begin_do_stmt ();
12106 /* Parse the body of the do-statement. */
12107 parser
->in_statement
= IN_ITERATION_STMT
;
12108 cp_parser_implicitly_scoped_statement (parser
, NULL
, guard_tinfo
);
12109 parser
->in_statement
= in_statement
;
12110 finish_do_body (statement
);
12111 /* Look for the `while' keyword. */
12112 cp_parser_require_keyword (parser
, RID_WHILE
, RT_WHILE
);
12113 /* Look for the `('. */
12114 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
12115 /* Parse the expression. */
12116 expression
= cp_parser_expression (parser
);
12117 /* We're done with the do-statement. */
12118 finish_do_stmt (expression
, statement
, ivdep
);
12119 /* Look for the `)'. */
12120 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
12121 /* Look for the `;'. */
12122 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
12128 /* Look for the `('. */
12129 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
12131 statement
= cp_parser_for (parser
, ivdep
);
12133 /* Look for the `)'. */
12134 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
12136 /* Parse the body of the for-statement. */
12137 parser
->in_statement
= IN_ITERATION_STMT
;
12138 cp_parser_already_scoped_statement (parser
, if_p
, guard_tinfo
);
12139 parser
->in_statement
= in_statement
;
12141 /* We're done with the for-statement. */
12142 finish_for_stmt (statement
);
12147 cp_parser_error (parser
, "expected iteration-statement");
12148 statement
= error_mark_node
;
12155 /* Parse a init-statement or the declarator of a range-based-for.
12156 Returns true if a range-based-for declaration is seen.
12159 expression-statement
12160 simple-declaration */
12163 cp_parser_init_statement (cp_parser
* parser
, tree
*decl
)
12165 /* If the next token is a `;', then we have an empty
12166 expression-statement. Grammatically, this is also a
12167 simple-declaration, but an invalid one, because it does not
12168 declare anything. Therefore, if we did not handle this case
12169 specially, we would issue an error message about an invalid
12171 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
12173 bool is_range_for
= false;
12174 bool saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
12176 /* A colon is used in range-based for. */
12177 parser
->colon_corrects_to_scope_p
= false;
12179 /* We're going to speculatively look for a declaration, falling back
12180 to an expression, if necessary. */
12181 cp_parser_parse_tentatively (parser
);
12182 /* Parse the declaration. */
12183 cp_parser_simple_declaration (parser
,
12184 /*function_definition_allowed_p=*/false,
12186 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
12187 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
12189 /* It is a range-for, consume the ':' */
12190 cp_lexer_consume_token (parser
->lexer
);
12191 is_range_for
= true;
12192 if (cxx_dialect
< cxx11
)
12194 pedwarn (cp_lexer_peek_token (parser
->lexer
)->location
, 0,
12195 "range-based %<for%> loops only available with "
12196 "-std=c++11 or -std=gnu++11");
12197 *decl
= error_mark_node
;
12201 /* The ';' is not consumed yet because we told
12202 cp_parser_simple_declaration not to. */
12203 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
12205 if (cp_parser_parse_definitely (parser
))
12206 return is_range_for
;
12207 /* If the tentative parse failed, then we shall need to look for an
12208 expression-statement. */
12210 /* If we are here, it is an expression-statement. */
12211 cp_parser_expression_statement (parser
, NULL_TREE
);
12215 /* Parse a jump-statement.
12220 return expression [opt] ;
12221 return braced-init-list ;
12227 goto * expression ;
12229 Returns the new BREAK_STMT, CONTINUE_STMT, RETURN_EXPR, or GOTO_EXPR. */
12232 cp_parser_jump_statement (cp_parser
* parser
)
12234 tree statement
= error_mark_node
;
12237 unsigned char in_statement
;
12239 /* Peek at the next token. */
12240 token
= cp_parser_require (parser
, CPP_KEYWORD
, RT_JUMP
);
12242 return error_mark_node
;
12244 /* See what kind of keyword it is. */
12245 keyword
= token
->keyword
;
12249 in_statement
= parser
->in_statement
& ~IN_IF_STMT
;
12250 switch (in_statement
)
12253 error_at (token
->location
, "break statement not within loop or switch");
12256 gcc_assert ((in_statement
& IN_SWITCH_STMT
)
12257 || in_statement
== IN_ITERATION_STMT
);
12258 statement
= finish_break_stmt ();
12259 if (in_statement
== IN_ITERATION_STMT
)
12260 break_maybe_infinite_loop ();
12263 error_at (token
->location
, "invalid exit from OpenMP structured block");
12266 error_at (token
->location
, "break statement used with OpenMP for loop");
12268 case IN_CILK_SIMD_FOR
:
12269 error_at (token
->location
, "break statement used with Cilk Plus for loop");
12272 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
12276 switch (parser
->in_statement
& ~(IN_SWITCH_STMT
| IN_IF_STMT
))
12279 error_at (token
->location
, "continue statement not within a loop");
12281 case IN_CILK_SIMD_FOR
:
12282 error_at (token
->location
,
12283 "continue statement within %<#pragma simd%> loop body");
12284 /* Fall through. */
12285 case IN_ITERATION_STMT
:
12287 statement
= finish_continue_stmt ();
12290 error_at (token
->location
, "invalid exit from OpenMP structured block");
12293 gcc_unreachable ();
12295 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
12301 bool expr_non_constant_p
;
12303 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
12305 cp_lexer_set_source_position (parser
->lexer
);
12306 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
12307 expr
= cp_parser_braced_list (parser
, &expr_non_constant_p
);
12309 else if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
12310 expr
= cp_parser_expression (parser
);
12312 /* If the next token is a `;', then there is no
12315 /* Build the return-statement. */
12316 if (current_function_auto_return_pattern
&& in_discarded_stmt
)
12317 /* Don't deduce from a discarded return statement. */;
12319 statement
= finish_return_stmt (expr
);
12320 /* Look for the final `;'. */
12321 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
12326 if (parser
->in_function_body
12327 && DECL_DECLARED_CONSTEXPR_P (current_function_decl
))
12329 error ("%<goto%> in %<constexpr%> function");
12330 cp_function_chain
->invalid_constexpr
= true;
12333 /* Create the goto-statement. */
12334 if (cp_lexer_next_token_is (parser
->lexer
, CPP_MULT
))
12336 /* Issue a warning about this use of a GNU extension. */
12337 pedwarn (token
->location
, OPT_Wpedantic
, "ISO C++ forbids computed gotos");
12338 /* Consume the '*' token. */
12339 cp_lexer_consume_token (parser
->lexer
);
12340 /* Parse the dependent expression. */
12341 finish_goto_stmt (cp_parser_expression (parser
));
12344 finish_goto_stmt (cp_parser_identifier (parser
));
12345 /* Look for the final `;'. */
12346 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
12350 cp_parser_error (parser
, "expected jump-statement");
12357 /* Parse a declaration-statement.
12359 declaration-statement:
12360 block-declaration */
12363 cp_parser_declaration_statement (cp_parser
* parser
)
12367 /* Get the high-water mark for the DECLARATOR_OBSTACK. */
12368 p
= obstack_alloc (&declarator_obstack
, 0);
12370 /* Parse the block-declaration. */
12371 cp_parser_block_declaration (parser
, /*statement_p=*/true);
12373 /* Free any declarators allocated. */
12374 obstack_free (&declarator_obstack
, p
);
12377 /* Some dependent statements (like `if (cond) statement'), are
12378 implicitly in their own scope. In other words, if the statement is
12379 a single statement (as opposed to a compound-statement), it is
12380 none-the-less treated as if it were enclosed in braces. Any
12381 declarations appearing in the dependent statement are out of scope
12382 after control passes that point. This function parses a statement,
12383 but ensures that is in its own scope, even if it is not a
12384 compound-statement.
12386 If IF_P is not NULL, *IF_P is set to indicate whether the statement
12387 is a (possibly labeled) if statement which is not enclosed in
12388 braces and has an else clause. This is used to implement
12391 CHAIN is a vector of if-else-if conditions. This is used to implement
12394 Returns the new statement. */
12397 cp_parser_implicitly_scoped_statement (cp_parser
* parser
, bool *if_p
,
12398 const token_indent_info
&guard_tinfo
,
12402 location_t body_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
12403 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
12404 token_indent_info body_tinfo
12405 = get_token_indent_info (cp_lexer_peek_token (parser
->lexer
));
12410 /* Mark if () ; with a special NOP_EXPR. */
12411 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
12413 cp_lexer_consume_token (parser
->lexer
);
12414 statement
= add_stmt (build_empty_stmt (body_loc
));
12416 if (guard_tinfo
.keyword
== RID_IF
12417 && !cp_lexer_next_token_is_keyword (parser
->lexer
, RID_ELSE
))
12418 warning_at (body_loc
, OPT_Wempty_body
,
12419 "suggest braces around empty body in an %<if%> statement");
12420 else if (guard_tinfo
.keyword
== RID_ELSE
)
12421 warning_at (body_loc
, OPT_Wempty_body
,
12422 "suggest braces around empty body in an %<else%> statement");
12424 /* if a compound is opened, we simply parse the statement directly. */
12425 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
12426 statement
= cp_parser_compound_statement (parser
, NULL
, BCS_NORMAL
, false);
12427 /* If the token is not a `{', then we must take special action. */
12430 /* Create a compound-statement. */
12431 statement
= begin_compound_stmt (0);
12432 /* Parse the dependent-statement. */
12433 cp_parser_statement (parser
, NULL_TREE
, false, if_p
, chain
,
12434 &body_loc_after_labels
);
12435 /* Finish the dummy compound-statement. */
12436 finish_compound_stmt (statement
);
12439 token_indent_info next_tinfo
12440 = get_token_indent_info (cp_lexer_peek_token (parser
->lexer
));
12441 warn_for_misleading_indentation (guard_tinfo
, body_tinfo
, next_tinfo
);
12443 if (body_loc_after_labels
!= UNKNOWN_LOCATION
12444 && next_tinfo
.type
!= CPP_SEMICOLON
)
12445 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
12446 guard_tinfo
.location
, guard_tinfo
.keyword
);
12448 /* Return the statement. */
12452 /* For some dependent statements (like `while (cond) statement'), we
12453 have already created a scope. Therefore, even if the dependent
12454 statement is a compound-statement, we do not want to create another
12458 cp_parser_already_scoped_statement (cp_parser
* parser
, bool *if_p
,
12459 const token_indent_info
&guard_tinfo
)
12461 /* If the token is a `{', then we must take special action. */
12462 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_BRACE
))
12464 token_indent_info body_tinfo
12465 = get_token_indent_info (cp_lexer_peek_token (parser
->lexer
));
12466 location_t loc_after_labels
= UNKNOWN_LOCATION
;
12468 cp_parser_statement (parser
, NULL_TREE
, false, if_p
, NULL
,
12469 &loc_after_labels
);
12470 token_indent_info next_tinfo
12471 = get_token_indent_info (cp_lexer_peek_token (parser
->lexer
));
12472 warn_for_misleading_indentation (guard_tinfo
, body_tinfo
, next_tinfo
);
12474 if (loc_after_labels
!= UNKNOWN_LOCATION
12475 && next_tinfo
.type
!= CPP_SEMICOLON
)
12476 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
12477 guard_tinfo
.location
,
12478 guard_tinfo
.keyword
);
12482 /* Avoid calling cp_parser_compound_statement, so that we
12483 don't create a new scope. Do everything else by hand. */
12484 cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
);
12485 /* If the next keyword is `__label__' we have a label declaration. */
12486 while (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_LABEL
))
12487 cp_parser_label_declaration (parser
);
12488 /* Parse an (optional) statement-seq. */
12489 cp_parser_statement_seq_opt (parser
, NULL_TREE
);
12490 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
12494 /* Declarations [gram.dcl.dcl] */
12496 /* Parse an optional declaration-sequence.
12500 declaration-seq declaration */
12503 cp_parser_declaration_seq_opt (cp_parser
* parser
)
12509 token
= cp_lexer_peek_token (parser
->lexer
);
12511 if (token
->type
== CPP_CLOSE_BRACE
12512 || token
->type
== CPP_EOF
12513 || token
->type
== CPP_PRAGMA_EOL
)
12516 if (token
->type
== CPP_SEMICOLON
)
12518 /* A declaration consisting of a single semicolon is
12519 invalid. Allow it unless we're being pedantic. */
12520 cp_lexer_consume_token (parser
->lexer
);
12521 if (!in_system_header_at (input_location
))
12522 pedwarn (input_location
, OPT_Wpedantic
, "extra %<;%>");
12526 /* If we're entering or exiting a region that's implicitly
12527 extern "C", modify the lang context appropriately. */
12528 if (!parser
->implicit_extern_c
&& token
->implicit_extern_c
)
12530 push_lang_context (lang_name_c
);
12531 parser
->implicit_extern_c
= true;
12533 else if (parser
->implicit_extern_c
&& !token
->implicit_extern_c
)
12535 pop_lang_context ();
12536 parser
->implicit_extern_c
= false;
12539 if (token
->type
== CPP_PRAGMA
)
12541 /* A top-level declaration can consist solely of a #pragma.
12542 A nested declaration cannot, so this is done here and not
12543 in cp_parser_declaration. (A #pragma at block scope is
12544 handled in cp_parser_statement.) */
12545 cp_parser_pragma (parser
, pragma_external
, NULL
);
12549 /* Parse the declaration itself. */
12550 cp_parser_declaration (parser
);
12554 /* Parse a declaration.
12558 function-definition
12559 template-declaration
12560 explicit-instantiation
12561 explicit-specialization
12562 linkage-specification
12563 namespace-definition
12571 __extension__ declaration */
12574 cp_parser_declaration (cp_parser
* parser
)
12578 int saved_pedantic
;
12580 tree attributes
= NULL_TREE
;
12582 /* Check for the `__extension__' keyword. */
12583 if (cp_parser_extension_opt (parser
, &saved_pedantic
))
12585 /* Parse the qualified declaration. */
12586 cp_parser_declaration (parser
);
12587 /* Restore the PEDANTIC flag. */
12588 pedantic
= saved_pedantic
;
12593 /* Try to figure out what kind of declaration is present. */
12594 token1
= *cp_lexer_peek_token (parser
->lexer
);
12596 if (token1
.type
!= CPP_EOF
)
12597 token2
= *cp_lexer_peek_nth_token (parser
->lexer
, 2);
12600 token2
.type
= CPP_EOF
;
12601 token2
.keyword
= RID_MAX
;
12604 /* Get the high-water mark for the DECLARATOR_OBSTACK. */
12605 p
= obstack_alloc (&declarator_obstack
, 0);
12607 /* If the next token is `extern' and the following token is a string
12608 literal, then we have a linkage specification. */
12609 if (token1
.keyword
== RID_EXTERN
12610 && cp_parser_is_pure_string_literal (&token2
))
12611 cp_parser_linkage_specification (parser
);
12612 /* If the next token is `template', then we have either a template
12613 declaration, an explicit instantiation, or an explicit
12615 else if (token1
.keyword
== RID_TEMPLATE
)
12617 /* `template <>' indicates a template specialization. */
12618 if (token2
.type
== CPP_LESS
12619 && cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
== CPP_GREATER
)
12620 cp_parser_explicit_specialization (parser
);
12621 /* `template <' indicates a template declaration. */
12622 else if (token2
.type
== CPP_LESS
)
12623 cp_parser_template_declaration (parser
, /*member_p=*/false);
12624 /* Anything else must be an explicit instantiation. */
12626 cp_parser_explicit_instantiation (parser
);
12628 /* If the next token is `export', then we have a template
12630 else if (token1
.keyword
== RID_EXPORT
)
12631 cp_parser_template_declaration (parser
, /*member_p=*/false);
12632 /* If the next token is `extern', 'static' or 'inline' and the one
12633 after that is `template', we have a GNU extended explicit
12634 instantiation directive. */
12635 else if (cp_parser_allow_gnu_extensions_p (parser
)
12636 && (token1
.keyword
== RID_EXTERN
12637 || token1
.keyword
== RID_STATIC
12638 || token1
.keyword
== RID_INLINE
)
12639 && token2
.keyword
== RID_TEMPLATE
)
12640 cp_parser_explicit_instantiation (parser
);
12641 /* If the next token is `namespace', check for a named or unnamed
12642 namespace definition. */
12643 else if (token1
.keyword
== RID_NAMESPACE
12644 && (/* A named namespace definition. */
12645 (token2
.type
== CPP_NAME
12646 && (cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
12648 || (token2
.type
== CPP_OPEN_SQUARE
12649 && cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
12650 == CPP_OPEN_SQUARE
)
12651 /* An unnamed namespace definition. */
12652 || token2
.type
== CPP_OPEN_BRACE
12653 || token2
.keyword
== RID_ATTRIBUTE
))
12654 cp_parser_namespace_definition (parser
);
12655 /* An inline (associated) namespace definition. */
12656 else if (token1
.keyword
== RID_INLINE
12657 && token2
.keyword
== RID_NAMESPACE
)
12658 cp_parser_namespace_definition (parser
);
12659 /* Objective-C++ declaration/definition. */
12660 else if (c_dialect_objc () && OBJC_IS_AT_KEYWORD (token1
.keyword
))
12661 cp_parser_objc_declaration (parser
, NULL_TREE
);
12662 else if (c_dialect_objc ()
12663 && token1
.keyword
== RID_ATTRIBUTE
12664 && cp_parser_objc_valid_prefix_attributes (parser
, &attributes
))
12665 cp_parser_objc_declaration (parser
, attributes
);
12666 /* At this point we may have a template declared by a concept
12668 else if (flag_concepts
12669 && cp_parser_template_declaration_after_export (parser
,
12670 /*member_p=*/false))
12673 /* Try to parse a block-declaration, or a function-definition. */
12674 cp_parser_block_declaration (parser
, /*statement_p=*/false);
12676 /* Free any declarators allocated. */
12677 obstack_free (&declarator_obstack
, p
);
12680 /* Parse a block-declaration.
12685 namespace-alias-definition
12692 __extension__ block-declaration
12697 static_assert-declaration
12699 If STATEMENT_P is TRUE, then this block-declaration is occurring as
12700 part of a declaration-statement. */
12703 cp_parser_block_declaration (cp_parser
*parser
,
12707 int saved_pedantic
;
12709 /* Check for the `__extension__' keyword. */
12710 if (cp_parser_extension_opt (parser
, &saved_pedantic
))
12712 /* Parse the qualified declaration. */
12713 cp_parser_block_declaration (parser
, statement_p
);
12714 /* Restore the PEDANTIC flag. */
12715 pedantic
= saved_pedantic
;
12720 /* Peek at the next token to figure out which kind of declaration is
12722 token1
= cp_lexer_peek_token (parser
->lexer
);
12724 /* If the next keyword is `asm', we have an asm-definition. */
12725 if (token1
->keyword
== RID_ASM
)
12728 cp_parser_commit_to_tentative_parse (parser
);
12729 cp_parser_asm_definition (parser
);
12731 /* If the next keyword is `namespace', we have a
12732 namespace-alias-definition. */
12733 else if (token1
->keyword
== RID_NAMESPACE
)
12734 cp_parser_namespace_alias_definition (parser
);
12735 /* If the next keyword is `using', we have a
12736 using-declaration, a using-directive, or an alias-declaration. */
12737 else if (token1
->keyword
== RID_USING
)
12742 cp_parser_commit_to_tentative_parse (parser
);
12743 /* If the token after `using' is `namespace', then we have a
12744 using-directive. */
12745 token2
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
12746 if (token2
->keyword
== RID_NAMESPACE
)
12747 cp_parser_using_directive (parser
);
12748 /* If the second token after 'using' is '=', then we have an
12749 alias-declaration. */
12750 else if (cxx_dialect
>= cxx11
12751 && token2
->type
== CPP_NAME
12752 && ((cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
== CPP_EQ
)
12753 || (cp_nth_tokens_can_be_attribute_p (parser
, 3))))
12754 cp_parser_alias_declaration (parser
);
12755 /* Otherwise, it's a using-declaration. */
12757 cp_parser_using_declaration (parser
,
12758 /*access_declaration_p=*/false);
12760 /* If the next keyword is `__label__' we have a misplaced label
12762 else if (token1
->keyword
== RID_LABEL
)
12764 cp_lexer_consume_token (parser
->lexer
);
12765 error_at (token1
->location
, "%<__label__%> not at the beginning of a block");
12766 cp_parser_skip_to_end_of_statement (parser
);
12767 /* If the next token is now a `;', consume it. */
12768 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
12769 cp_lexer_consume_token (parser
->lexer
);
12771 /* If the next token is `static_assert' we have a static assertion. */
12772 else if (token1
->keyword
== RID_STATIC_ASSERT
)
12773 cp_parser_static_assert (parser
, /*member_p=*/false);
12774 /* Anything else must be a simple-declaration. */
12776 cp_parser_simple_declaration (parser
, !statement_p
,
12777 /*maybe_range_for_decl*/NULL
);
12780 /* Parse a simple-declaration.
12782 simple-declaration:
12783 decl-specifier-seq [opt] init-declarator-list [opt] ;
12784 decl-specifier-seq ref-qualifier [opt] [ identifier-list ]
12785 brace-or-equal-initializer ;
12787 init-declarator-list:
12789 init-declarator-list , init-declarator
12791 If FUNCTION_DEFINITION_ALLOWED_P is TRUE, then we also recognize a
12792 function-definition as a simple-declaration.
12794 If MAYBE_RANGE_FOR_DECL is not NULL, the pointed tree will be set to the
12795 parsed declaration if it is an uninitialized single declarator not followed
12796 by a `;', or to error_mark_node otherwise. Either way, the trailing `;',
12797 if present, will not be consumed. */
12800 cp_parser_simple_declaration (cp_parser
* parser
,
12801 bool function_definition_allowed_p
,
12802 tree
*maybe_range_for_decl
)
12804 cp_decl_specifier_seq decl_specifiers
;
12805 int declares_class_or_enum
;
12806 bool saw_declarator
;
12807 location_t comma_loc
= UNKNOWN_LOCATION
;
12808 location_t init_loc
= UNKNOWN_LOCATION
;
12810 if (maybe_range_for_decl
)
12811 *maybe_range_for_decl
= NULL_TREE
;
12813 /* Defer access checks until we know what is being declared; the
12814 checks for names appearing in the decl-specifier-seq should be
12815 done as if we were in the scope of the thing being declared. */
12816 push_deferring_access_checks (dk_deferred
);
12818 /* Parse the decl-specifier-seq. We have to keep track of whether
12819 or not the decl-specifier-seq declares a named class or
12820 enumeration type, since that is the only case in which the
12821 init-declarator-list is allowed to be empty.
12825 In a simple-declaration, the optional init-declarator-list can be
12826 omitted only when declaring a class or enumeration, that is when
12827 the decl-specifier-seq contains either a class-specifier, an
12828 elaborated-type-specifier, or an enum-specifier. */
12829 cp_parser_decl_specifier_seq (parser
,
12830 CP_PARSER_FLAGS_OPTIONAL
,
12832 &declares_class_or_enum
);
12833 /* We no longer need to defer access checks. */
12834 stop_deferring_access_checks ();
12836 /* In a block scope, a valid declaration must always have a
12837 decl-specifier-seq. By not trying to parse declarators, we can
12838 resolve the declaration/expression ambiguity more quickly. */
12839 if (!function_definition_allowed_p
12840 && !decl_specifiers
.any_specifiers_p
)
12842 cp_parser_error (parser
, "expected declaration");
12846 /* If the next two tokens are both identifiers, the code is
12847 erroneous. The usual cause of this situation is code like:
12851 where "T" should name a type -- but does not. */
12852 if (!decl_specifiers
.any_type_specifiers_p
12853 && cp_parser_parse_and_diagnose_invalid_type_name (parser
))
12855 /* If parsing tentatively, we should commit; we really are
12856 looking at a declaration. */
12857 cp_parser_commit_to_tentative_parse (parser
);
12862 /* If we have seen at least one decl-specifier, and the next token
12863 is not a parenthesis, then we must be looking at a declaration.
12864 (After "int (" we might be looking at a functional cast.) */
12865 if (decl_specifiers
.any_specifiers_p
12866 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_PAREN
)
12867 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_BRACE
)
12868 && !cp_parser_error_occurred (parser
))
12869 cp_parser_commit_to_tentative_parse (parser
);
12871 /* Look for C++17 decomposition declaration. */
12872 for (size_t n
= 1; ; n
++)
12873 if (cp_lexer_nth_token_is (parser
->lexer
, n
, CPP_AND
)
12874 || cp_lexer_nth_token_is (parser
->lexer
, n
, CPP_AND_AND
))
12876 else if (cp_lexer_nth_token_is (parser
->lexer
, n
, CPP_OPEN_SQUARE
)
12877 && !cp_lexer_nth_token_is (parser
->lexer
, n
+ 1, CPP_OPEN_SQUARE
)
12878 && decl_specifiers
.any_specifiers_p
)
12881 = cp_parser_decomposition_declaration (parser
, &decl_specifiers
,
12882 maybe_range_for_decl
,
12885 /* The next token should be either a `,' or a `;'. */
12886 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
12887 /* If it's a `;', we are done. */
12888 if (token
->type
== CPP_SEMICOLON
|| maybe_range_for_decl
)
12890 /* Anything else is an error. */
12893 /* If we have already issued an error message we don't need
12894 to issue another one. */
12895 if ((decl
!= error_mark_node
12896 && DECL_INITIAL (decl
) != error_mark_node
)
12897 || cp_parser_uncommitted_to_tentative_parse_p (parser
))
12898 cp_parser_error (parser
, "expected %<,%> or %<;%>");
12899 /* Skip tokens until we reach the end of the statement. */
12900 cp_parser_skip_to_end_of_statement (parser
);
12901 /* If the next token is now a `;', consume it. */
12902 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
12903 cp_lexer_consume_token (parser
->lexer
);
12911 bool auto_specifier_p
;
12912 /* NULL_TREE if both variable and function declaration are allowed,
12913 error_mark_node if function declaration are not allowed and
12914 a FUNCTION_DECL that should be diagnosed if it is followed by
12915 variable declarations. */
12916 tree auto_function_declaration
;
12918 last_type
= NULL_TREE
;
12920 = decl_specifiers
.type
&& type_uses_auto (decl_specifiers
.type
);
12921 auto_function_declaration
= NULL_TREE
;
12923 /* Keep going until we hit the `;' at the end of the simple
12925 saw_declarator
= false;
12926 while (cp_lexer_next_token_is_not (parser
->lexer
,
12930 bool function_definition_p
;
12932 tree auto_result
= NULL_TREE
;
12934 if (saw_declarator
)
12936 /* If we are processing next declarator, comma is expected */
12937 token
= cp_lexer_peek_token (parser
->lexer
);
12938 gcc_assert (token
->type
== CPP_COMMA
);
12939 cp_lexer_consume_token (parser
->lexer
);
12940 if (maybe_range_for_decl
)
12942 *maybe_range_for_decl
= error_mark_node
;
12943 if (comma_loc
== UNKNOWN_LOCATION
)
12944 comma_loc
= token
->location
;
12948 saw_declarator
= true;
12950 /* Parse the init-declarator. */
12951 decl
= cp_parser_init_declarator (parser
, &decl_specifiers
,
12953 function_definition_allowed_p
,
12954 /*member_p=*/false,
12955 declares_class_or_enum
,
12956 &function_definition_p
,
12957 maybe_range_for_decl
,
12960 /* If an error occurred while parsing tentatively, exit quickly.
12961 (That usually happens when in the body of a function; each
12962 statement is treated as a declaration-statement until proven
12964 if (cp_parser_error_occurred (parser
))
12967 if (auto_specifier_p
&& cxx_dialect
>= cxx14
)
12969 /* If the init-declarator-list contains more than one
12970 init-declarator, they shall all form declarations of
12972 if (auto_function_declaration
== NULL_TREE
)
12973 auto_function_declaration
12974 = TREE_CODE (decl
) == FUNCTION_DECL
? decl
: error_mark_node
;
12975 else if (TREE_CODE (decl
) == FUNCTION_DECL
12976 || auto_function_declaration
!= error_mark_node
)
12978 error_at (decl_specifiers
.locations
[ds_type_spec
],
12979 "non-variable %qD in declaration with more than one "
12980 "declarator with placeholder type",
12981 TREE_CODE (decl
) == FUNCTION_DECL
12982 ? decl
: auto_function_declaration
);
12983 auto_function_declaration
= error_mark_node
;
12988 && (!processing_template_decl
|| !type_uses_auto (auto_result
)))
12991 && last_type
!= error_mark_node
12992 && !same_type_p (auto_result
, last_type
))
12994 /* If the list of declarators contains more than one declarator,
12995 the type of each declared variable is determined as described
12996 above. If the type deduced for the template parameter U is not
12997 the same in each deduction, the program is ill-formed. */
12998 error_at (decl_specifiers
.locations
[ds_type_spec
],
12999 "inconsistent deduction for %qT: %qT and then %qT",
13000 decl_specifiers
.type
, last_type
, auto_result
);
13001 last_type
= error_mark_node
;
13004 last_type
= auto_result
;
13007 /* Handle function definitions specially. */
13008 if (function_definition_p
)
13010 /* If the next token is a `,', then we are probably
13011 processing something like:
13015 which is erroneous. */
13016 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
13018 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
13019 error_at (token
->location
,
13021 " declarations and function-definitions is forbidden");
13023 /* Otherwise, we're done with the list of declarators. */
13026 pop_deferring_access_checks ();
13030 if (maybe_range_for_decl
&& *maybe_range_for_decl
== NULL_TREE
)
13031 *maybe_range_for_decl
= decl
;
13032 /* The next token should be either a `,' or a `;'. */
13033 token
= cp_lexer_peek_token (parser
->lexer
);
13034 /* If it's a `,', there are more declarators to come. */
13035 if (token
->type
== CPP_COMMA
)
13036 /* will be consumed next time around */;
13037 /* If it's a `;', we are done. */
13038 else if (token
->type
== CPP_SEMICOLON
)
13040 else if (maybe_range_for_decl
)
13042 if ((declares_class_or_enum
& 2) && token
->type
== CPP_COLON
)
13043 permerror (decl_specifiers
.locations
[ds_type_spec
],
13044 "types may not be defined in a for-range-declaration");
13047 /* Anything else is an error. */
13050 /* If we have already issued an error message we don't need
13051 to issue another one. */
13052 if ((decl
!= error_mark_node
13053 && DECL_INITIAL (decl
) != error_mark_node
)
13054 || cp_parser_uncommitted_to_tentative_parse_p (parser
))
13055 cp_parser_error (parser
, "expected %<,%> or %<;%>");
13056 /* Skip tokens until we reach the end of the statement. */
13057 cp_parser_skip_to_end_of_statement (parser
);
13058 /* If the next token is now a `;', consume it. */
13059 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
13060 cp_lexer_consume_token (parser
->lexer
);
13063 /* After the first time around, a function-definition is not
13064 allowed -- even if it was OK at first. For example:
13069 function_definition_allowed_p
= false;
13072 /* Issue an error message if no declarators are present, and the
13073 decl-specifier-seq does not itself declare a class or
13074 enumeration: [dcl.dcl]/3. */
13075 if (!saw_declarator
)
13077 if (cp_parser_declares_only_class_p (parser
))
13079 if (!declares_class_or_enum
13080 && decl_specifiers
.type
13081 && OVERLOAD_TYPE_P (decl_specifiers
.type
))
13082 /* Ensure an error is issued anyway when finish_decltype_type,
13083 called via cp_parser_decl_specifier_seq, returns a class or
13084 an enumeration (c++/51786). */
13085 decl_specifiers
.type
= NULL_TREE
;
13086 shadow_tag (&decl_specifiers
);
13088 /* Perform any deferred access checks. */
13089 perform_deferred_access_checks (tf_warning_or_error
);
13092 /* Consume the `;'. */
13094 if (!maybe_range_for_decl
)
13095 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
13096 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
13098 if (init_loc
!= UNKNOWN_LOCATION
)
13099 error_at (init_loc
, "initializer in range-based %<for%> loop");
13100 if (comma_loc
!= UNKNOWN_LOCATION
)
13101 error_at (comma_loc
,
13102 "multiple declarations in range-based %<for%> loop");
13106 pop_deferring_access_checks ();
13109 /* Helper of cp_parser_simple_declaration, parse a decomposition declaration.
13110 decl-specifier-seq ref-qualifier [opt] [ identifier-list ]
13114 cp_parser_decomposition_declaration (cp_parser
*parser
,
13115 cp_decl_specifier_seq
*decl_specifiers
,
13116 tree
*maybe_range_for_decl
,
13117 location_t
*init_loc
)
13119 cp_ref_qualifier ref_qual
= cp_parser_ref_qualifier_opt (parser
);
13120 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
13121 cp_parser_require (parser
, CPP_OPEN_SQUARE
, RT_OPEN_SQUARE
);
13123 /* Parse the identifier-list. */
13124 auto_vec
<cp_expr
, 10> v
;
13125 if (!cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_SQUARE
))
13128 cp_expr e
= cp_parser_identifier (parser
);
13129 if (e
.get_value () == error_mark_node
)
13132 if (!cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
13134 cp_lexer_consume_token (parser
->lexer
);
13137 location_t end_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
13138 if (!cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
))
13140 end_loc
= UNKNOWN_LOCATION
;
13141 cp_parser_skip_to_closing_parenthesis_1 (parser
, true, CPP_CLOSE_SQUARE
,
13143 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_SQUARE
))
13144 cp_lexer_consume_token (parser
->lexer
);
13147 cp_parser_skip_to_end_of_statement (parser
);
13148 return error_mark_node
;
13152 if (cxx_dialect
< cxx1z
)
13153 pedwarn (loc
, 0, "structured bindings only available with "
13154 "-std=c++1z or -std=gnu++1z");
13157 cp_declarator
*declarator
= make_declarator (cdk_decomp
);
13158 loc
= end_loc
== UNKNOWN_LOCATION
? loc
: make_location (loc
, loc
, end_loc
);
13159 declarator
->id_loc
= loc
;
13160 if (ref_qual
!= REF_QUAL_NONE
)
13161 declarator
= make_reference_declarator (TYPE_UNQUALIFIED
, declarator
,
13162 ref_qual
== REF_QUAL_RVALUE
,
13164 tree decl
= start_decl (declarator
, decl_specifiers
, SD_INITIALIZED
,
13165 NULL_TREE
, decl_specifiers
->attributes
,
13167 tree orig_decl
= decl
;
13171 cp_decl_specifier_seq decl_specs
;
13172 clear_decl_specs (&decl_specs
);
13173 decl_specs
.type
= make_auto ();
13175 FOR_EACH_VEC_ELT (v
, i
, e
)
13178 declarator
= make_id_declarator (NULL_TREE
, e
.get_value (), sfk_none
);
13180 declarator
->u
.id
.unqualified_name
= e
.get_value ();
13181 declarator
->id_loc
= e
.get_location ();
13182 tree elt_pushed_scope
;
13183 tree decl2
= start_decl (declarator
, &decl_specs
, SD_INITIALIZED
,
13184 NULL_TREE
, NULL_TREE
, &elt_pushed_scope
);
13185 if (decl2
== error_mark_node
)
13186 decl
= error_mark_node
;
13187 else if (decl
!= error_mark_node
&& DECL_CHAIN (decl2
) != prev
)
13189 /* Ensure we've diagnosed redeclaration if we aren't creating
13191 gcc_assert (errorcount
);
13192 decl
= error_mark_node
;
13196 if (elt_pushed_scope
)
13197 pop_scope (elt_pushed_scope
);
13202 error_at (loc
, "empty structured binding declaration");
13203 decl
= error_mark_node
;
13206 if (maybe_range_for_decl
== NULL
13207 || cp_lexer_next_token_is_not (parser
->lexer
, CPP_COLON
))
13209 bool non_constant_p
= false, is_direct_init
= false;
13210 *init_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
13211 tree initializer
= cp_parser_initializer (parser
, &is_direct_init
,
13213 if (initializer
== NULL_TREE
13214 || (TREE_CODE (initializer
) == TREE_LIST
13215 && TREE_CHAIN (initializer
))
13216 || (TREE_CODE (initializer
) == CONSTRUCTOR
13217 && CONSTRUCTOR_NELTS (initializer
) != 1))
13219 error_at (loc
, "invalid initializer for structured binding "
13221 initializer
= error_mark_node
;
13224 if (decl
!= error_mark_node
)
13226 cp_finish_decl (decl
, initializer
, non_constant_p
, NULL_TREE
,
13227 is_direct_init
? LOOKUP_NORMAL
: LOOKUP_IMPLICIT
);
13228 cp_finish_decomp (decl
, prev
, v
.length ());
13231 else if (decl
!= error_mark_node
)
13233 *maybe_range_for_decl
= prev
;
13234 /* Ensure DECL_VALUE_EXPR is created for all the decls but
13235 the underlying DECL. */
13236 cp_finish_decomp (decl
, prev
, v
.length ());
13240 pop_scope (pushed_scope
);
13242 if (decl
== error_mark_node
&& DECL_P (orig_decl
))
13244 if (DECL_NAMESPACE_SCOPE_P (orig_decl
))
13245 SET_DECL_ASSEMBLER_NAME (orig_decl
, get_identifier ("<decomp>"));
13251 /* Parse a decl-specifier-seq.
13253 decl-specifier-seq:
13254 decl-specifier-seq [opt] decl-specifier
13255 decl-specifier attribute-specifier-seq [opt] (C++11)
13258 storage-class-specifier
13269 Concepts Extension:
13274 Set *DECL_SPECS to a representation of the decl-specifier-seq.
13276 The parser flags FLAGS is used to control type-specifier parsing.
13278 *DECLARES_CLASS_OR_ENUM is set to the bitwise or of the following
13281 1: one of the decl-specifiers is an elaborated-type-specifier
13282 (i.e., a type declaration)
13283 2: one of the decl-specifiers is an enum-specifier or a
13284 class-specifier (i.e., a type definition)
13289 cp_parser_decl_specifier_seq (cp_parser
* parser
,
13290 cp_parser_flags flags
,
13291 cp_decl_specifier_seq
*decl_specs
,
13292 int* declares_class_or_enum
)
13294 bool constructor_possible_p
= !parser
->in_declarator_p
;
13295 bool found_decl_spec
= false;
13296 cp_token
*start_token
= NULL
;
13299 /* Clear DECL_SPECS. */
13300 clear_decl_specs (decl_specs
);
13302 /* Assume no class or enumeration type is declared. */
13303 *declares_class_or_enum
= 0;
13305 /* Keep reading specifiers until there are no more to read. */
13308 bool constructor_p
;
13312 /* Peek at the next token. */
13313 token
= cp_lexer_peek_token (parser
->lexer
);
13315 /* Save the first token of the decl spec list for error
13318 start_token
= token
;
13319 /* Handle attributes. */
13320 if (cp_next_tokens_can_be_attribute_p (parser
))
13322 /* Parse the attributes. */
13323 tree attrs
= cp_parser_attributes_opt (parser
);
13325 /* In a sequence of declaration specifiers, c++11 attributes
13326 appertain to the type that precede them. In that case
13329 The attribute-specifier-seq affects the type only for
13330 the declaration it appears in, not other declarations
13331 involving the same type.
13333 But for now let's force the user to position the
13334 attribute either at the beginning of the declaration or
13335 after the declarator-id, which would clearly mean that it
13336 applies to the declarator. */
13337 if (cxx11_attribute_p (attrs
))
13339 if (!found_decl_spec
)
13340 /* The c++11 attribute is at the beginning of the
13341 declaration. It appertains to the entity being
13345 if (decl_specs
->type
&& CLASS_TYPE_P (decl_specs
->type
))
13347 /* This is an attribute following a
13348 class-specifier. */
13349 if (decl_specs
->type_definition_p
)
13350 warn_misplaced_attr_for_class_type (token
->location
,
13356 decl_specs
->std_attributes
13357 = chainon (decl_specs
->std_attributes
,
13359 if (decl_specs
->locations
[ds_std_attribute
] == 0)
13360 decl_specs
->locations
[ds_std_attribute
] = token
->location
;
13366 decl_specs
->attributes
13367 = chainon (decl_specs
->attributes
,
13369 if (decl_specs
->locations
[ds_attribute
] == 0)
13370 decl_specs
->locations
[ds_attribute
] = token
->location
;
13373 /* Assume we will find a decl-specifier keyword. */
13374 found_decl_spec
= true;
13375 /* If the next token is an appropriate keyword, we can simply
13376 add it to the list. */
13377 switch (token
->keyword
)
13383 if (!at_class_scope_p ())
13385 error_at (token
->location
, "%<friend%> used outside of class");
13386 cp_lexer_purge_token (parser
->lexer
);
13391 /* Consume the token. */
13392 cp_lexer_consume_token (parser
->lexer
);
13396 case RID_CONSTEXPR
:
13398 cp_lexer_consume_token (parser
->lexer
);
13403 cp_lexer_consume_token (parser
->lexer
);
13406 /* function-specifier:
13413 cp_parser_function_specifier_opt (parser
, decl_specs
);
13420 /* Consume the token. */
13421 cp_lexer_consume_token (parser
->lexer
);
13422 /* A constructor declarator cannot appear in a typedef. */
13423 constructor_possible_p
= false;
13424 /* The "typedef" keyword can only occur in a declaration; we
13425 may as well commit at this point. */
13426 cp_parser_commit_to_tentative_parse (parser
);
13428 if (decl_specs
->storage_class
!= sc_none
)
13429 decl_specs
->conflicting_specifiers_p
= true;
13432 /* storage-class-specifier:
13442 if (cxx_dialect
== cxx98
)
13444 /* Consume the token. */
13445 cp_lexer_consume_token (parser
->lexer
);
13447 /* Complain about `auto' as a storage specifier, if
13448 we're complaining about C++0x compatibility. */
13449 warning_at (token
->location
, OPT_Wc__11_compat
, "%<auto%>"
13450 " changes meaning in C++11; please remove it");
13452 /* Set the storage class anyway. */
13453 cp_parser_set_storage_class (parser
, decl_specs
, RID_AUTO
,
13457 /* C++0x auto type-specifier. */
13458 found_decl_spec
= false;
13465 /* Consume the token. */
13466 cp_lexer_consume_token (parser
->lexer
);
13467 cp_parser_set_storage_class (parser
, decl_specs
, token
->keyword
,
13471 /* Consume the token. */
13473 cp_lexer_consume_token (parser
->lexer
);
13477 /* We did not yet find a decl-specifier yet. */
13478 found_decl_spec
= false;
13482 if (found_decl_spec
13483 && (flags
& CP_PARSER_FLAGS_ONLY_TYPE_OR_CONSTEXPR
)
13484 && token
->keyword
!= RID_CONSTEXPR
)
13485 error ("decl-specifier invalid in condition");
13487 if (found_decl_spec
13488 && (flags
& CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR
)
13489 && token
->keyword
!= RID_MUTABLE
13490 && token
->keyword
!= RID_CONSTEXPR
)
13491 error_at (token
->location
, "%qD invalid in lambda",
13492 ridpointers
[token
->keyword
]);
13495 set_and_check_decl_spec_loc (decl_specs
, ds
, token
);
13497 /* Constructors are a special case. The `S' in `S()' is not a
13498 decl-specifier; it is the beginning of the declarator. */
13500 = (!found_decl_spec
13501 && constructor_possible_p
13502 && (cp_parser_constructor_declarator_p
13503 (parser
, decl_spec_seq_has_spec_p (decl_specs
, ds_friend
))));
13505 /* If we don't have a DECL_SPEC yet, then we must be looking at
13506 a type-specifier. */
13507 if (!found_decl_spec
&& !constructor_p
)
13509 int decl_spec_declares_class_or_enum
;
13510 bool is_cv_qualifier
;
13514 = cp_parser_type_specifier (parser
, flags
,
13516 /*is_declaration=*/true,
13517 &decl_spec_declares_class_or_enum
,
13519 *declares_class_or_enum
|= decl_spec_declares_class_or_enum
;
13521 /* If this type-specifier referenced a user-defined type
13522 (a typedef, class-name, etc.), then we can't allow any
13523 more such type-specifiers henceforth.
13527 The longest sequence of decl-specifiers that could
13528 possibly be a type name is taken as the
13529 decl-specifier-seq of a declaration. The sequence shall
13530 be self-consistent as described below.
13534 As a general rule, at most one type-specifier is allowed
13535 in the complete decl-specifier-seq of a declaration. The
13536 only exceptions are the following:
13538 -- const or volatile can be combined with any other
13541 -- signed or unsigned can be combined with char, long,
13549 void g (const int Pc);
13551 Here, Pc is *not* part of the decl-specifier seq; it's
13552 the declarator. Therefore, once we see a type-specifier
13553 (other than a cv-qualifier), we forbid any additional
13554 user-defined types. We *do* still allow things like `int
13555 int' to be considered a decl-specifier-seq, and issue the
13556 error message later. */
13557 if (type_spec
&& !is_cv_qualifier
)
13558 flags
|= CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES
;
13559 /* A constructor declarator cannot follow a type-specifier. */
13562 constructor_possible_p
= false;
13563 found_decl_spec
= true;
13564 if (!is_cv_qualifier
)
13565 decl_specs
->any_type_specifiers_p
= true;
13569 /* If we still do not have a DECL_SPEC, then there are no more
13570 decl-specifiers. */
13571 if (!found_decl_spec
)
13574 decl_specs
->any_specifiers_p
= true;
13575 /* After we see one decl-specifier, further decl-specifiers are
13576 always optional. */
13577 flags
|= CP_PARSER_FLAGS_OPTIONAL
;
13580 /* Don't allow a friend specifier with a class definition. */
13581 if (decl_spec_seq_has_spec_p (decl_specs
, ds_friend
)
13582 && (*declares_class_or_enum
& 2))
13583 error_at (decl_specs
->locations
[ds_friend
],
13584 "class definition may not be declared a friend");
13587 /* Parse an (optional) storage-class-specifier.
13589 storage-class-specifier:
13598 storage-class-specifier:
13601 Returns an IDENTIFIER_NODE corresponding to the keyword used. */
13604 cp_parser_storage_class_specifier_opt (cp_parser
* parser
)
13606 switch (cp_lexer_peek_token (parser
->lexer
)->keyword
)
13609 if (cxx_dialect
!= cxx98
)
13611 /* Fall through for C++98. */
13612 gcc_fallthrough ();
13619 /* Consume the token. */
13620 return cp_lexer_consume_token (parser
->lexer
)->u
.value
;
13627 /* Parse an (optional) function-specifier.
13629 function-specifier:
13634 Returns an IDENTIFIER_NODE corresponding to the keyword used.
13635 Updates DECL_SPECS, if it is non-NULL. */
13638 cp_parser_function_specifier_opt (cp_parser
* parser
,
13639 cp_decl_specifier_seq
*decl_specs
)
13641 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
13642 switch (token
->keyword
)
13645 set_and_check_decl_spec_loc (decl_specs
, ds_inline
, token
);
13649 /* 14.5.2.3 [temp.mem]
13651 A member function template shall not be virtual. */
13652 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
13653 && current_class_type
)
13654 error_at (token
->location
, "templates may not be %<virtual%>");
13656 set_and_check_decl_spec_loc (decl_specs
, ds_virtual
, token
);
13660 set_and_check_decl_spec_loc (decl_specs
, ds_explicit
, token
);
13667 /* Consume the token. */
13668 return cp_lexer_consume_token (parser
->lexer
)->u
.value
;
13671 /* Parse a linkage-specification.
13673 linkage-specification:
13674 extern string-literal { declaration-seq [opt] }
13675 extern string-literal declaration */
13678 cp_parser_linkage_specification (cp_parser
* parser
)
13682 /* Look for the `extern' keyword. */
13683 cp_parser_require_keyword (parser
, RID_EXTERN
, RT_EXTERN
);
13685 /* Look for the string-literal. */
13686 linkage
= cp_parser_string_literal (parser
, false, false);
13688 /* Transform the literal into an identifier. If the literal is a
13689 wide-character string, or contains embedded NULs, then we can't
13690 handle it as the user wants. */
13691 if (strlen (TREE_STRING_POINTER (linkage
))
13692 != (size_t) (TREE_STRING_LENGTH (linkage
) - 1))
13694 cp_parser_error (parser
, "invalid linkage-specification");
13695 /* Assume C++ linkage. */
13696 linkage
= lang_name_cplusplus
;
13699 linkage
= get_identifier (TREE_STRING_POINTER (linkage
));
13701 /* We're now using the new linkage. */
13702 push_lang_context (linkage
);
13704 /* If the next token is a `{', then we're using the first
13706 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
13708 cp_ensure_no_omp_declare_simd (parser
);
13709 cp_ensure_no_oacc_routine (parser
);
13711 /* Consume the `{' token. */
13712 cp_lexer_consume_token (parser
->lexer
);
13713 /* Parse the declarations. */
13714 cp_parser_declaration_seq_opt (parser
);
13715 /* Look for the closing `}'. */
13716 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
13718 /* Otherwise, there's just one declaration. */
13721 bool saved_in_unbraced_linkage_specification_p
;
13723 saved_in_unbraced_linkage_specification_p
13724 = parser
->in_unbraced_linkage_specification_p
;
13725 parser
->in_unbraced_linkage_specification_p
= true;
13726 cp_parser_declaration (parser
);
13727 parser
->in_unbraced_linkage_specification_p
13728 = saved_in_unbraced_linkage_specification_p
;
13731 /* We're done with the linkage-specification. */
13732 pop_lang_context ();
13735 /* Parse a static_assert-declaration.
13737 static_assert-declaration:
13738 static_assert ( constant-expression , string-literal ) ;
13739 static_assert ( constant-expression ) ; (C++1Z)
13741 If MEMBER_P, this static_assert is a class member. */
13744 cp_parser_static_assert(cp_parser
*parser
, bool member_p
)
13749 location_t saved_loc
;
13752 /* Peek at the `static_assert' token so we can keep track of exactly
13753 where the static assertion started. */
13754 token
= cp_lexer_peek_token (parser
->lexer
);
13755 saved_loc
= token
->location
;
13757 /* Look for the `static_assert' keyword. */
13758 if (!cp_parser_require_keyword (parser
, RID_STATIC_ASSERT
,
13762 /* We know we are in a static assertion; commit to any tentative
13764 if (cp_parser_parsing_tentatively (parser
))
13765 cp_parser_commit_to_tentative_parse (parser
);
13767 /* Parse the `(' starting the static assertion condition. */
13768 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
13770 /* Parse the constant-expression. Allow a non-constant expression
13771 here in order to give better diagnostics in finish_static_assert. */
13773 cp_parser_constant_expression (parser
,
13774 /*allow_non_constant_p=*/true,
13775 /*non_constant_p=*/&dummy
);
13777 if (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_CLOSE_PAREN
)
13779 if (cxx_dialect
< cxx1z
)
13780 pedwarn (input_location
, OPT_Wpedantic
,
13781 "static_assert without a message "
13782 "only available with -std=c++1z or -std=gnu++1z");
13784 cp_lexer_consume_token (parser
->lexer
);
13785 message
= build_string (1, "");
13786 TREE_TYPE (message
) = char_array_type_node
;
13787 fix_string_type (message
);
13791 /* Parse the separating `,'. */
13792 cp_parser_require (parser
, CPP_COMMA
, RT_COMMA
);
13794 /* Parse the string-literal message. */
13795 message
= cp_parser_string_literal (parser
,
13796 /*translate=*/false,
13799 /* A `)' completes the static assertion. */
13800 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
13801 cp_parser_skip_to_closing_parenthesis (parser
,
13802 /*recovering=*/true,
13803 /*or_comma=*/false,
13804 /*consume_paren=*/true);
13807 /* A semicolon terminates the declaration. */
13808 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
13810 /* Complete the static assertion, which may mean either processing
13811 the static assert now or saving it for template instantiation. */
13812 finish_static_assert (condition
, message
, saved_loc
, member_p
);
13815 /* Parse the expression in decltype ( expression ). */
13818 cp_parser_decltype_expr (cp_parser
*parser
,
13819 bool &id_expression_or_member_access_p
)
13821 cp_token
*id_expr_start_token
;
13824 /* Since we're going to preserve any side-effects from this parse, set up a
13825 firewall to protect our callers from cp_parser_commit_to_tentative_parse
13826 in the expression. */
13827 tentative_firewall
firewall (parser
);
13829 /* First, try parsing an id-expression. */
13830 id_expr_start_token
= cp_lexer_peek_token (parser
->lexer
);
13831 cp_parser_parse_tentatively (parser
);
13832 expr
= cp_parser_id_expression (parser
,
13833 /*template_keyword_p=*/false,
13834 /*check_dependency_p=*/true,
13835 /*template_p=*/NULL
,
13836 /*declarator_p=*/false,
13837 /*optional_p=*/false);
13839 if (!cp_parser_error_occurred (parser
) && expr
!= error_mark_node
)
13841 bool non_integral_constant_expression_p
= false;
13842 tree id_expression
= expr
;
13844 const char *error_msg
;
13846 if (identifier_p (expr
))
13847 /* Lookup the name we got back from the id-expression. */
13848 expr
= cp_parser_lookup_name_simple (parser
, expr
,
13849 id_expr_start_token
->location
);
13852 && expr
!= error_mark_node
13853 && TREE_CODE (expr
) != TYPE_DECL
13854 && (TREE_CODE (expr
) != BIT_NOT_EXPR
13855 || !TYPE_P (TREE_OPERAND (expr
, 0)))
13856 && cp_lexer_peek_token (parser
->lexer
)->type
== CPP_CLOSE_PAREN
)
13858 /* Complete lookup of the id-expression. */
13859 expr
= (finish_id_expression
13860 (id_expression
, expr
, parser
->scope
, &idk
,
13861 /*integral_constant_expression_p=*/false,
13862 /*allow_non_integral_constant_expression_p=*/true,
13863 &non_integral_constant_expression_p
,
13864 /*template_p=*/false,
13866 /*address_p=*/false,
13867 /*template_arg_p=*/false,
13869 id_expr_start_token
->location
));
13871 if (expr
== error_mark_node
)
13872 /* We found an id-expression, but it was something that we
13873 should not have found. This is an error, not something
13874 we can recover from, so note that we found an
13875 id-expression and we'll recover as gracefully as
13877 id_expression_or_member_access_p
= true;
13881 && expr
!= error_mark_node
13882 && cp_lexer_peek_token (parser
->lexer
)->type
== CPP_CLOSE_PAREN
)
13883 /* We have an id-expression. */
13884 id_expression_or_member_access_p
= true;
13887 if (!id_expression_or_member_access_p
)
13889 /* Abort the id-expression parse. */
13890 cp_parser_abort_tentative_parse (parser
);
13892 /* Parsing tentatively, again. */
13893 cp_parser_parse_tentatively (parser
);
13895 /* Parse a class member access. */
13896 expr
= cp_parser_postfix_expression (parser
, /*address_p=*/false,
13897 /*cast_p=*/false, /*decltype*/true,
13898 /*member_access_only_p=*/true, NULL
);
13901 && expr
!= error_mark_node
13902 && cp_lexer_peek_token (parser
->lexer
)->type
== CPP_CLOSE_PAREN
)
13903 /* We have an id-expression. */
13904 id_expression_or_member_access_p
= true;
13907 if (id_expression_or_member_access_p
)
13908 /* We have parsed the complete id-expression or member access. */
13909 cp_parser_parse_definitely (parser
);
13912 /* Abort our attempt to parse an id-expression or member access
13914 cp_parser_abort_tentative_parse (parser
);
13916 /* Parse a full expression. */
13917 expr
= cp_parser_expression (parser
, /*pidk=*/NULL
, /*cast_p=*/false,
13918 /*decltype_p=*/true);
13924 /* Parse a `decltype' type. Returns the type.
13926 simple-type-specifier:
13927 decltype ( expression )
13929 decltype ( auto ) */
13932 cp_parser_decltype (cp_parser
*parser
)
13935 bool id_expression_or_member_access_p
= false;
13936 const char *saved_message
;
13937 bool saved_integral_constant_expression_p
;
13938 bool saved_non_integral_constant_expression_p
;
13939 bool saved_greater_than_is_operator_p
;
13940 cp_token
*start_token
= cp_lexer_peek_token (parser
->lexer
);
13942 if (start_token
->type
== CPP_DECLTYPE
)
13944 /* Already parsed. */
13945 cp_lexer_consume_token (parser
->lexer
);
13946 return saved_checks_value (start_token
->u
.tree_check_value
);
13949 /* Look for the `decltype' token. */
13950 if (!cp_parser_require_keyword (parser
, RID_DECLTYPE
, RT_DECLTYPE
))
13951 return error_mark_node
;
13953 /* Parse the opening `('. */
13954 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
13955 return error_mark_node
;
13957 /* decltype (auto) */
13958 if (cxx_dialect
>= cxx14
13959 && cp_lexer_next_token_is_keyword (parser
->lexer
, RID_AUTO
))
13961 cp_lexer_consume_token (parser
->lexer
);
13962 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
13963 return error_mark_node
;
13964 expr
= make_decltype_auto ();
13965 AUTO_IS_DECLTYPE (expr
) = true;
13969 /* Types cannot be defined in a `decltype' expression. Save away the
13971 saved_message
= parser
->type_definition_forbidden_message
;
13973 /* And create the new one. */
13974 parser
->type_definition_forbidden_message
13975 = G_("types may not be defined in %<decltype%> expressions");
13977 /* The restrictions on constant-expressions do not apply inside
13978 decltype expressions. */
13979 saved_integral_constant_expression_p
13980 = parser
->integral_constant_expression_p
;
13981 saved_non_integral_constant_expression_p
13982 = parser
->non_integral_constant_expression_p
;
13983 parser
->integral_constant_expression_p
= false;
13985 /* Within a parenthesized expression, a `>' token is always
13986 the greater-than operator. */
13987 saved_greater_than_is_operator_p
13988 = parser
->greater_than_is_operator_p
;
13989 parser
->greater_than_is_operator_p
= true;
13991 /* Do not actually evaluate the expression. */
13992 ++cp_unevaluated_operand
;
13994 /* Do not warn about problems with the expression. */
13995 ++c_inhibit_evaluation_warnings
;
13997 expr
= cp_parser_decltype_expr (parser
, id_expression_or_member_access_p
);
13999 /* Go back to evaluating expressions. */
14000 --cp_unevaluated_operand
;
14001 --c_inhibit_evaluation_warnings
;
14003 /* The `>' token might be the end of a template-id or
14004 template-parameter-list now. */
14005 parser
->greater_than_is_operator_p
14006 = saved_greater_than_is_operator_p
;
14008 /* Restore the old message and the integral constant expression
14010 parser
->type_definition_forbidden_message
= saved_message
;
14011 parser
->integral_constant_expression_p
14012 = saved_integral_constant_expression_p
;
14013 parser
->non_integral_constant_expression_p
14014 = saved_non_integral_constant_expression_p
;
14016 /* Parse to the closing `)'. */
14017 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
14019 cp_parser_skip_to_closing_parenthesis (parser
, true, false,
14020 /*consume_paren=*/true);
14021 return error_mark_node
;
14024 expr
= finish_decltype_type (expr
, id_expression_or_member_access_p
,
14025 tf_warning_or_error
);
14028 /* Replace the decltype with a CPP_DECLTYPE so we don't need to parse
14030 start_token
->type
= CPP_DECLTYPE
;
14031 start_token
->u
.tree_check_value
= ggc_cleared_alloc
<struct tree_check
> ();
14032 start_token
->u
.tree_check_value
->value
= expr
;
14033 start_token
->u
.tree_check_value
->checks
= get_deferred_access_checks ();
14034 start_token
->keyword
= RID_MAX
;
14035 cp_lexer_purge_tokens_after (parser
->lexer
, start_token
);
14040 /* Special member functions [gram.special] */
14042 /* Parse a conversion-function-id.
14044 conversion-function-id:
14045 operator conversion-type-id
14047 Returns an IDENTIFIER_NODE representing the operator. */
14050 cp_parser_conversion_function_id (cp_parser
* parser
)
14054 tree saved_qualifying_scope
;
14055 tree saved_object_scope
;
14056 tree pushed_scope
= NULL_TREE
;
14058 /* Look for the `operator' token. */
14059 if (!cp_parser_require_keyword (parser
, RID_OPERATOR
, RT_OPERATOR
))
14060 return error_mark_node
;
14061 /* When we parse the conversion-type-id, the current scope will be
14062 reset. However, we need that information in able to look up the
14063 conversion function later, so we save it here. */
14064 saved_scope
= parser
->scope
;
14065 saved_qualifying_scope
= parser
->qualifying_scope
;
14066 saved_object_scope
= parser
->object_scope
;
14067 /* We must enter the scope of the class so that the names of
14068 entities declared within the class are available in the
14069 conversion-type-id. For example, consider:
14076 S::operator I() { ... }
14078 In order to see that `I' is a type-name in the definition, we
14079 must be in the scope of `S'. */
14081 pushed_scope
= push_scope (saved_scope
);
14082 /* Parse the conversion-type-id. */
14083 type
= cp_parser_conversion_type_id (parser
);
14084 /* Leave the scope of the class, if any. */
14086 pop_scope (pushed_scope
);
14087 /* Restore the saved scope. */
14088 parser
->scope
= saved_scope
;
14089 parser
->qualifying_scope
= saved_qualifying_scope
;
14090 parser
->object_scope
= saved_object_scope
;
14091 /* If the TYPE is invalid, indicate failure. */
14092 if (type
== error_mark_node
)
14093 return error_mark_node
;
14094 return make_conv_op_name (type
);
14097 /* Parse a conversion-type-id:
14099 conversion-type-id:
14100 type-specifier-seq conversion-declarator [opt]
14102 Returns the TYPE specified. */
14105 cp_parser_conversion_type_id (cp_parser
* parser
)
14108 cp_decl_specifier_seq type_specifiers
;
14109 cp_declarator
*declarator
;
14110 tree type_specified
;
14111 const char *saved_message
;
14113 /* Parse the attributes. */
14114 attributes
= cp_parser_attributes_opt (parser
);
14116 saved_message
= parser
->type_definition_forbidden_message
;
14117 parser
->type_definition_forbidden_message
14118 = G_("types may not be defined in a conversion-type-id");
14120 /* Parse the type-specifiers. */
14121 cp_parser_type_specifier_seq (parser
, /*is_declaration=*/false,
14122 /*is_trailing_return=*/false,
14125 parser
->type_definition_forbidden_message
= saved_message
;
14127 /* If that didn't work, stop. */
14128 if (type_specifiers
.type
== error_mark_node
)
14129 return error_mark_node
;
14130 /* Parse the conversion-declarator. */
14131 declarator
= cp_parser_conversion_declarator_opt (parser
);
14133 type_specified
= grokdeclarator (declarator
, &type_specifiers
, TYPENAME
,
14134 /*initialized=*/0, &attributes
);
14136 cplus_decl_attributes (&type_specified
, attributes
, /*flags=*/0);
14138 /* Don't give this error when parsing tentatively. This happens to
14139 work because we always parse this definitively once. */
14140 if (! cp_parser_uncommitted_to_tentative_parse_p (parser
)
14141 && type_uses_auto (type_specified
))
14143 if (cxx_dialect
< cxx14
)
14145 error ("invalid use of %<auto%> in conversion operator");
14146 return error_mark_node
;
14148 else if (template_parm_scope_p ())
14149 warning (0, "use of %<auto%> in member template "
14150 "conversion operator can never be deduced");
14153 return type_specified
;
14156 /* Parse an (optional) conversion-declarator.
14158 conversion-declarator:
14159 ptr-operator conversion-declarator [opt]
14163 static cp_declarator
*
14164 cp_parser_conversion_declarator_opt (cp_parser
* parser
)
14166 enum tree_code code
;
14167 tree class_type
, std_attributes
= NULL_TREE
;
14168 cp_cv_quals cv_quals
;
14170 /* We don't know if there's a ptr-operator next, or not. */
14171 cp_parser_parse_tentatively (parser
);
14172 /* Try the ptr-operator. */
14173 code
= cp_parser_ptr_operator (parser
, &class_type
, &cv_quals
,
14175 /* If it worked, look for more conversion-declarators. */
14176 if (cp_parser_parse_definitely (parser
))
14178 cp_declarator
*declarator
;
14180 /* Parse another optional declarator. */
14181 declarator
= cp_parser_conversion_declarator_opt (parser
);
14183 declarator
= cp_parser_make_indirect_declarator
14184 (code
, class_type
, cv_quals
, declarator
, std_attributes
);
14192 /* Parse an (optional) ctor-initializer.
14195 : mem-initializer-list
14197 Returns TRUE iff the ctor-initializer was actually present. */
14200 cp_parser_ctor_initializer_opt (cp_parser
* parser
)
14202 /* If the next token is not a `:', then there is no
14203 ctor-initializer. */
14204 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COLON
))
14206 /* Do default initialization of any bases and members. */
14207 if (DECL_CONSTRUCTOR_P (current_function_decl
))
14208 finish_mem_initializers (NULL_TREE
);
14213 /* Consume the `:' token. */
14214 cp_lexer_consume_token (parser
->lexer
);
14215 /* And the mem-initializer-list. */
14216 cp_parser_mem_initializer_list (parser
);
14221 /* Parse a mem-initializer-list.
14223 mem-initializer-list:
14224 mem-initializer ... [opt]
14225 mem-initializer ... [opt] , mem-initializer-list */
14228 cp_parser_mem_initializer_list (cp_parser
* parser
)
14230 tree mem_initializer_list
= NULL_TREE
;
14231 tree target_ctor
= error_mark_node
;
14232 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
14234 /* Let the semantic analysis code know that we are starting the
14235 mem-initializer-list. */
14236 if (!DECL_CONSTRUCTOR_P (current_function_decl
))
14237 error_at (token
->location
,
14238 "only constructors take member initializers");
14240 /* Loop through the list. */
14243 tree mem_initializer
;
14245 token
= cp_lexer_peek_token (parser
->lexer
);
14246 /* Parse the mem-initializer. */
14247 mem_initializer
= cp_parser_mem_initializer (parser
);
14248 /* If the next token is a `...', we're expanding member initializers. */
14249 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
14251 /* Consume the `...'. */
14252 cp_lexer_consume_token (parser
->lexer
);
14254 /* The TREE_PURPOSE must be a _TYPE, because base-specifiers
14255 can be expanded but members cannot. */
14256 if (mem_initializer
!= error_mark_node
14257 && !TYPE_P (TREE_PURPOSE (mem_initializer
)))
14259 error_at (token
->location
,
14260 "cannot expand initializer for member %qD",
14261 TREE_PURPOSE (mem_initializer
));
14262 mem_initializer
= error_mark_node
;
14265 /* Construct the pack expansion type. */
14266 if (mem_initializer
!= error_mark_node
)
14267 mem_initializer
= make_pack_expansion (mem_initializer
);
14269 if (target_ctor
!= error_mark_node
14270 && mem_initializer
!= error_mark_node
)
14272 error ("mem-initializer for %qD follows constructor delegation",
14273 TREE_PURPOSE (mem_initializer
));
14274 mem_initializer
= error_mark_node
;
14276 /* Look for a target constructor. */
14277 if (mem_initializer
!= error_mark_node
14278 && CLASS_TYPE_P (TREE_PURPOSE (mem_initializer
))
14279 && same_type_p (TREE_PURPOSE (mem_initializer
), current_class_type
))
14281 maybe_warn_cpp0x (CPP0X_DELEGATING_CTORS
);
14282 if (mem_initializer_list
)
14284 error ("constructor delegation follows mem-initializer for %qD",
14285 TREE_PURPOSE (mem_initializer_list
));
14286 mem_initializer
= error_mark_node
;
14288 target_ctor
= mem_initializer
;
14290 /* Add it to the list, unless it was erroneous. */
14291 if (mem_initializer
!= error_mark_node
)
14293 TREE_CHAIN (mem_initializer
) = mem_initializer_list
;
14294 mem_initializer_list
= mem_initializer
;
14296 /* If the next token is not a `,', we're done. */
14297 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
14299 /* Consume the `,' token. */
14300 cp_lexer_consume_token (parser
->lexer
);
14303 /* Perform semantic analysis. */
14304 if (DECL_CONSTRUCTOR_P (current_function_decl
))
14305 finish_mem_initializers (mem_initializer_list
);
14308 /* Parse a mem-initializer.
14311 mem-initializer-id ( expression-list [opt] )
14312 mem-initializer-id braced-init-list
14317 ( expression-list [opt] )
14319 Returns a TREE_LIST. The TREE_PURPOSE is the TYPE (for a base
14320 class) or FIELD_DECL (for a non-static data member) to initialize;
14321 the TREE_VALUE is the expression-list. An empty initialization
14322 list is represented by void_list_node. */
14325 cp_parser_mem_initializer (cp_parser
* parser
)
14327 tree mem_initializer_id
;
14328 tree expression_list
;
14330 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
14332 /* Find out what is being initialized. */
14333 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
14335 permerror (token
->location
,
14336 "anachronistic old-style base class initializer");
14337 mem_initializer_id
= NULL_TREE
;
14341 mem_initializer_id
= cp_parser_mem_initializer_id (parser
);
14342 if (mem_initializer_id
== error_mark_node
)
14343 return mem_initializer_id
;
14345 member
= expand_member_init (mem_initializer_id
);
14346 if (member
&& !DECL_P (member
))
14347 in_base_initializer
= 1;
14349 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
14351 bool expr_non_constant_p
;
14352 cp_lexer_set_source_position (parser
->lexer
);
14353 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
14354 expression_list
= cp_parser_braced_list (parser
, &expr_non_constant_p
);
14355 CONSTRUCTOR_IS_DIRECT_INIT (expression_list
) = 1;
14356 expression_list
= build_tree_list (NULL_TREE
, expression_list
);
14360 vec
<tree
, va_gc
> *vec
;
14361 vec
= cp_parser_parenthesized_expression_list (parser
, non_attr
,
14363 /*allow_expansion_p=*/true,
14364 /*non_constant_p=*/NULL
);
14366 return error_mark_node
;
14367 expression_list
= build_tree_list_vec (vec
);
14368 release_tree_vector (vec
);
14371 if (expression_list
== error_mark_node
)
14372 return error_mark_node
;
14373 if (!expression_list
)
14374 expression_list
= void_type_node
;
14376 in_base_initializer
= 0;
14378 return member
? build_tree_list (member
, expression_list
) : error_mark_node
;
14381 /* Parse a mem-initializer-id.
14383 mem-initializer-id:
14384 :: [opt] nested-name-specifier [opt] class-name
14385 decltype-specifier (C++11)
14388 Returns a TYPE indicating the class to be initialized for the first
14389 production (and the second in C++11). Returns an IDENTIFIER_NODE
14390 indicating the data member to be initialized for the last production. */
14393 cp_parser_mem_initializer_id (cp_parser
* parser
)
14395 bool global_scope_p
;
14396 bool nested_name_specifier_p
;
14397 bool template_p
= false;
14400 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
14402 /* `typename' is not allowed in this context ([temp.res]). */
14403 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TYPENAME
))
14405 error_at (token
->location
,
14406 "keyword %<typename%> not allowed in this context (a qualified "
14407 "member initializer is implicitly a type)");
14408 cp_lexer_consume_token (parser
->lexer
);
14410 /* Look for the optional `::' operator. */
14412 = (cp_parser_global_scope_opt (parser
,
14413 /*current_scope_valid_p=*/false)
14415 /* Look for the optional nested-name-specifier. The simplest way to
14420 The keyword `typename' is not permitted in a base-specifier or
14421 mem-initializer; in these contexts a qualified name that
14422 depends on a template-parameter is implicitly assumed to be a
14425 is to assume that we have seen the `typename' keyword at this
14427 nested_name_specifier_p
14428 = (cp_parser_nested_name_specifier_opt (parser
,
14429 /*typename_keyword_p=*/true,
14430 /*check_dependency_p=*/true,
14432 /*is_declaration=*/true)
14434 if (nested_name_specifier_p
)
14435 template_p
= cp_parser_optional_template_keyword (parser
);
14436 /* If there is a `::' operator or a nested-name-specifier, then we
14437 are definitely looking for a class-name. */
14438 if (global_scope_p
|| nested_name_specifier_p
)
14439 return cp_parser_class_name (parser
,
14440 /*typename_keyword_p=*/true,
14441 /*template_keyword_p=*/template_p
,
14443 /*check_dependency_p=*/true,
14444 /*class_head_p=*/false,
14445 /*is_declaration=*/true);
14446 /* Otherwise, we could also be looking for an ordinary identifier. */
14447 cp_parser_parse_tentatively (parser
);
14448 if (cp_lexer_next_token_is_decltype (parser
->lexer
))
14449 /* Try a decltype-specifier. */
14450 id
= cp_parser_decltype (parser
);
14452 /* Otherwise, try a class-name. */
14453 id
= cp_parser_class_name (parser
,
14454 /*typename_keyword_p=*/true,
14455 /*template_keyword_p=*/false,
14457 /*check_dependency_p=*/true,
14458 /*class_head_p=*/false,
14459 /*is_declaration=*/true);
14460 /* If we found one, we're done. */
14461 if (cp_parser_parse_definitely (parser
))
14463 /* Otherwise, look for an ordinary identifier. */
14464 return cp_parser_identifier (parser
);
14467 /* Overloading [gram.over] */
14469 /* Parse an operator-function-id.
14471 operator-function-id:
14474 Returns an IDENTIFIER_NODE for the operator which is a
14475 human-readable spelling of the identifier, e.g., `operator +'. */
14478 cp_parser_operator_function_id (cp_parser
* parser
)
14480 /* Look for the `operator' keyword. */
14481 if (!cp_parser_require_keyword (parser
, RID_OPERATOR
, RT_OPERATOR
))
14482 return error_mark_node
;
14483 /* And then the name of the operator itself. */
14484 return cp_parser_operator (parser
);
14487 /* Return an identifier node for a user-defined literal operator.
14488 The suffix identifier is chained to the operator name identifier. */
14491 cp_literal_operator_id (const char* name
)
14494 char *buffer
= XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX
)
14495 + strlen (name
) + 10);
14496 sprintf (buffer
, UDLIT_OP_ANSI_FORMAT
, name
);
14497 identifier
= get_identifier (buffer
);
14502 /* Parse an operator.
14505 new delete new[] delete[] + - * / % ^ & | ~ ! = < >
14506 += -= *= /= %= ^= &= |= << >> >>= <<= == != <= >= &&
14507 || ++ -- , ->* -> () []
14514 Returns an IDENTIFIER_NODE for the operator which is a
14515 human-readable spelling of the identifier, e.g., `operator +'. */
14518 cp_parser_operator (cp_parser
* parser
)
14520 tree id
= NULL_TREE
;
14524 /* Peek at the next token. */
14525 token
= cp_lexer_peek_token (parser
->lexer
);
14527 location_t start_loc
= token
->location
;
14529 /* Figure out which operator we have. */
14530 switch (token
->type
)
14536 /* The keyword should be either `new' or `delete'. */
14537 if (token
->keyword
== RID_NEW
)
14539 else if (token
->keyword
== RID_DELETE
)
14544 /* Consume the `new' or `delete' token. */
14545 location_t end_loc
= cp_lexer_consume_token (parser
->lexer
)->location
;
14547 /* Peek at the next token. */
14548 token
= cp_lexer_peek_token (parser
->lexer
);
14549 /* If it's a `[' token then this is the array variant of the
14551 if (token
->type
== CPP_OPEN_SQUARE
)
14553 /* Consume the `[' token. */
14554 cp_lexer_consume_token (parser
->lexer
);
14555 /* Look for the `]' token. */
14556 if (cp_token
*close_token
14557 = cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
))
14558 end_loc
= close_token
->location
;
14559 id
= cp_operator_id (op
== NEW_EXPR
14560 ? VEC_NEW_EXPR
: VEC_DELETE_EXPR
);
14562 /* Otherwise, we have the non-array variant. */
14564 id
= cp_operator_id (op
);
14566 location_t loc
= make_location (start_loc
, start_loc
, end_loc
);
14568 return cp_expr (id
, loc
);
14572 id
= cp_operator_id (PLUS_EXPR
);
14576 id
= cp_operator_id (MINUS_EXPR
);
14580 id
= cp_operator_id (MULT_EXPR
);
14584 id
= cp_operator_id (TRUNC_DIV_EXPR
);
14588 id
= cp_operator_id (TRUNC_MOD_EXPR
);
14592 id
= cp_operator_id (BIT_XOR_EXPR
);
14596 id
= cp_operator_id (BIT_AND_EXPR
);
14600 id
= cp_operator_id (BIT_IOR_EXPR
);
14604 id
= cp_operator_id (BIT_NOT_EXPR
);
14608 id
= cp_operator_id (TRUTH_NOT_EXPR
);
14612 id
= cp_assignment_operator_id (NOP_EXPR
);
14616 id
= cp_operator_id (LT_EXPR
);
14620 id
= cp_operator_id (GT_EXPR
);
14624 id
= cp_assignment_operator_id (PLUS_EXPR
);
14628 id
= cp_assignment_operator_id (MINUS_EXPR
);
14632 id
= cp_assignment_operator_id (MULT_EXPR
);
14636 id
= cp_assignment_operator_id (TRUNC_DIV_EXPR
);
14640 id
= cp_assignment_operator_id (TRUNC_MOD_EXPR
);
14644 id
= cp_assignment_operator_id (BIT_XOR_EXPR
);
14648 id
= cp_assignment_operator_id (BIT_AND_EXPR
);
14652 id
= cp_assignment_operator_id (BIT_IOR_EXPR
);
14656 id
= cp_operator_id (LSHIFT_EXPR
);
14660 id
= cp_operator_id (RSHIFT_EXPR
);
14663 case CPP_LSHIFT_EQ
:
14664 id
= cp_assignment_operator_id (LSHIFT_EXPR
);
14667 case CPP_RSHIFT_EQ
:
14668 id
= cp_assignment_operator_id (RSHIFT_EXPR
);
14672 id
= cp_operator_id (EQ_EXPR
);
14676 id
= cp_operator_id (NE_EXPR
);
14680 id
= cp_operator_id (LE_EXPR
);
14683 case CPP_GREATER_EQ
:
14684 id
= cp_operator_id (GE_EXPR
);
14688 id
= cp_operator_id (TRUTH_ANDIF_EXPR
);
14692 id
= cp_operator_id (TRUTH_ORIF_EXPR
);
14695 case CPP_PLUS_PLUS
:
14696 id
= cp_operator_id (POSTINCREMENT_EXPR
);
14699 case CPP_MINUS_MINUS
:
14700 id
= cp_operator_id (PREDECREMENT_EXPR
);
14704 id
= cp_operator_id (COMPOUND_EXPR
);
14707 case CPP_DEREF_STAR
:
14708 id
= cp_operator_id (MEMBER_REF
);
14712 id
= cp_operator_id (COMPONENT_REF
);
14715 case CPP_OPEN_PAREN
:
14716 /* Consume the `('. */
14717 cp_lexer_consume_token (parser
->lexer
);
14718 /* Look for the matching `)'. */
14719 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
14720 return cp_operator_id (CALL_EXPR
);
14722 case CPP_OPEN_SQUARE
:
14723 /* Consume the `['. */
14724 cp_lexer_consume_token (parser
->lexer
);
14725 /* Look for the matching `]'. */
14726 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
14727 return cp_operator_id (ARRAY_REF
);
14729 case CPP_UTF8STRING
:
14730 case CPP_UTF8STRING_USERDEF
:
14737 case CPP_STRING_USERDEF
:
14738 case CPP_WSTRING_USERDEF
:
14739 case CPP_STRING16_USERDEF
:
14740 case CPP_STRING32_USERDEF
:
14742 tree str
, string_tree
;
14745 if (cxx_dialect
== cxx98
)
14746 maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS
);
14748 /* Consume the string. */
14749 str
= cp_parser_string_literal (parser
, /*translate=*/true,
14750 /*wide_ok=*/true, /*lookup_udlit=*/false);
14751 if (str
== error_mark_node
)
14752 return error_mark_node
;
14753 else if (TREE_CODE (str
) == USERDEF_LITERAL
)
14755 string_tree
= USERDEF_LITERAL_VALUE (str
);
14756 id
= USERDEF_LITERAL_SUFFIX_ID (str
);
14761 /* Look for the suffix identifier. */
14762 token
= cp_lexer_peek_token (parser
->lexer
);
14763 if (token
->type
== CPP_NAME
)
14764 id
= cp_parser_identifier (parser
);
14765 else if (token
->type
== CPP_KEYWORD
)
14767 error ("unexpected keyword;"
14768 " remove space between quotes and suffix identifier");
14769 return error_mark_node
;
14773 error ("expected suffix identifier");
14774 return error_mark_node
;
14777 sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
14778 (TREE_TYPE (TREE_TYPE (string_tree
))));
14779 len
= TREE_STRING_LENGTH (string_tree
) / sz
- 1;
14782 error ("expected empty string after %<operator%> keyword");
14783 return error_mark_node
;
14785 if (utf8
|| TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string_tree
)))
14788 error ("invalid encoding prefix in literal operator");
14789 return error_mark_node
;
14791 if (id
!= error_mark_node
)
14793 const char *name
= IDENTIFIER_POINTER (id
);
14794 id
= cp_literal_operator_id (name
);
14800 /* Anything else is an error. */
14804 /* If we have selected an identifier, we need to consume the
14807 cp_lexer_consume_token (parser
->lexer
);
14808 /* Otherwise, no valid operator name was present. */
14811 cp_parser_error (parser
, "expected operator");
14812 id
= error_mark_node
;
14815 return cp_expr (id
, start_loc
);
14818 /* Parse a template-declaration.
14820 template-declaration:
14821 export [opt] template < template-parameter-list > declaration
14823 If MEMBER_P is TRUE, this template-declaration occurs within a
14826 The grammar rule given by the standard isn't correct. What
14827 is really meant is:
14829 template-declaration:
14830 export [opt] template-parameter-list-seq
14831 decl-specifier-seq [opt] init-declarator [opt] ;
14832 export [opt] template-parameter-list-seq
14833 function-definition
14835 template-parameter-list-seq:
14836 template-parameter-list-seq [opt]
14837 template < template-parameter-list >
14839 Concept Extensions:
14841 template-parameter-list-seq:
14842 template < template-parameter-list > requires-clause [opt]
14845 requires logical-or-expression */
14848 cp_parser_template_declaration (cp_parser
* parser
, bool member_p
)
14850 /* Check for `export'. */
14851 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_EXPORT
))
14853 /* Consume the `export' token. */
14854 cp_lexer_consume_token (parser
->lexer
);
14855 /* Warn that we do not support `export'. */
14856 warning (0, "keyword %<export%> not implemented, and will be ignored");
14859 cp_parser_template_declaration_after_export (parser
, member_p
);
14862 /* Parse a template-parameter-list.
14864 template-parameter-list:
14866 template-parameter-list , template-parameter
14868 Returns a TREE_LIST. Each node represents a template parameter.
14869 The nodes are connected via their TREE_CHAINs. */
14872 cp_parser_template_parameter_list (cp_parser
* parser
)
14874 tree parameter_list
= NULL_TREE
;
14876 begin_template_parm_list ();
14878 /* The loop below parses the template parms. We first need to know
14879 the total number of template parms to be able to compute proper
14880 canonical types of each dependent type. So after the loop, when
14881 we know the total number of template parms,
14882 end_template_parm_list computes the proper canonical types and
14883 fixes up the dependent types accordingly. */
14888 bool is_parameter_pack
;
14889 location_t parm_loc
;
14891 /* Parse the template-parameter. */
14892 parm_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
14893 parameter
= cp_parser_template_parameter (parser
,
14895 &is_parameter_pack
);
14896 /* Add it to the list. */
14897 if (parameter
!= error_mark_node
)
14898 parameter_list
= process_template_parm (parameter_list
,
14902 is_parameter_pack
);
14905 tree err_parm
= build_tree_list (parameter
, parameter
);
14906 parameter_list
= chainon (parameter_list
, err_parm
);
14909 /* If the next token is not a `,', we're done. */
14910 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
14912 /* Otherwise, consume the `,' token. */
14913 cp_lexer_consume_token (parser
->lexer
);
14916 return end_template_parm_list (parameter_list
);
14919 /* Parse a introduction-list.
14922 introduced-parameter
14923 introduction-list , introduced-parameter
14925 introduced-parameter:
14926 ...[opt] identifier
14928 Returns a TREE_VEC of WILDCARD_DECLs. If the parameter is a pack
14929 then the introduced parm will have WILDCARD_PACK_P set. In addition, the
14930 WILDCARD_DECL will also have DECL_NAME set and token location in
14931 DECL_SOURCE_LOCATION. */
14934 cp_parser_introduction_list (cp_parser
*parser
)
14936 vec
<tree
, va_gc
> *introduction_vec
= make_tree_vector ();
14940 bool is_pack
= cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
);
14942 cp_lexer_consume_token (parser
->lexer
);
14944 /* Build placeholder. */
14945 tree parm
= build_nt (WILDCARD_DECL
);
14946 DECL_SOURCE_LOCATION (parm
)
14947 = cp_lexer_peek_token (parser
->lexer
)->location
;
14948 DECL_NAME (parm
) = cp_parser_identifier (parser
);
14949 WILDCARD_PACK_P (parm
) = is_pack
;
14950 vec_safe_push (introduction_vec
, parm
);
14952 /* If the next token is not a `,', we're done. */
14953 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
14955 /* Otherwise, consume the `,' token. */
14956 cp_lexer_consume_token (parser
->lexer
);
14959 /* Convert the vec into a TREE_VEC. */
14960 tree introduction_list
= make_tree_vec (introduction_vec
->length ());
14963 FOR_EACH_VEC_ELT (*introduction_vec
, n
, parm
)
14964 TREE_VEC_ELT (introduction_list
, n
) = parm
;
14966 release_tree_vector (introduction_vec
);
14967 return introduction_list
;
14970 /* Given a declarator, get the declarator-id part, or NULL_TREE if this
14971 is an abstract declarator. */
14973 static inline cp_declarator
*
14974 get_id_declarator (cp_declarator
*declarator
)
14976 cp_declarator
*d
= declarator
;
14977 while (d
&& d
->kind
!= cdk_id
)
14982 /* Get the unqualified-id from the DECLARATOR or NULL_TREE if this
14983 is an abstract declarator. */
14986 get_unqualified_id (cp_declarator
*declarator
)
14988 declarator
= get_id_declarator (declarator
);
14990 return declarator
->u
.id
.unqualified_name
;
14995 /* Returns true if DECL represents a constrained-parameter. */
14998 is_constrained_parameter (tree decl
)
15001 && TREE_CODE (decl
) == TYPE_DECL
15002 && CONSTRAINED_PARM_CONCEPT (decl
)
15003 && DECL_P (CONSTRAINED_PARM_CONCEPT (decl
)));
15006 /* Returns true if PARM declares a constrained-parameter. */
15009 is_constrained_parameter (cp_parameter_declarator
*parm
)
15011 return is_constrained_parameter (parm
->decl_specifiers
.type
);
15014 /* Check that the type parameter is only a declarator-id, and that its
15015 type is not cv-qualified. */
15018 cp_parser_check_constrained_type_parm (cp_parser
*parser
,
15019 cp_parameter_declarator
*parm
)
15021 if (!parm
->declarator
)
15024 if (parm
->declarator
->kind
!= cdk_id
)
15026 cp_parser_error (parser
, "invalid constrained type parameter");
15030 /* Don't allow cv-qualified type parameters. */
15031 if (decl_spec_seq_has_spec_p (&parm
->decl_specifiers
, ds_const
)
15032 || decl_spec_seq_has_spec_p (&parm
->decl_specifiers
, ds_volatile
))
15034 cp_parser_error (parser
, "cv-qualified type parameter");
15041 /* Finish parsing/processing a template type parameter and checking
15042 various restrictions. */
15045 cp_parser_constrained_type_template_parm (cp_parser
*parser
,
15047 cp_parameter_declarator
* parmdecl
)
15049 if (cp_parser_check_constrained_type_parm (parser
, parmdecl
))
15050 return finish_template_type_parm (class_type_node
, id
);
15052 return error_mark_node
;
15056 finish_constrained_template_template_parm (tree proto
, tree id
)
15058 /* FIXME: This should probably be copied, and we may need to adjust
15059 the template parameter depths. */
15060 tree saved_parms
= current_template_parms
;
15061 begin_template_parm_list ();
15062 current_template_parms
= DECL_TEMPLATE_PARMS (proto
);
15063 end_template_parm_list ();
15065 tree parm
= finish_template_template_parm (class_type_node
, id
);
15066 current_template_parms
= saved_parms
;
15071 /* Finish parsing/processing a template template parameter by borrowing
15072 the template parameter list from the prototype parameter. */
15075 cp_parser_constrained_template_template_parm (cp_parser
*parser
,
15078 cp_parameter_declarator
*parmdecl
)
15080 if (!cp_parser_check_constrained_type_parm (parser
, parmdecl
))
15081 return error_mark_node
;
15082 return finish_constrained_template_template_parm (proto
, id
);
15085 /* Create a new non-type template parameter from the given PARM
15089 constrained_non_type_template_parm (bool *is_non_type
,
15090 cp_parameter_declarator
*parm
)
15092 *is_non_type
= true;
15093 cp_declarator
*decl
= parm
->declarator
;
15094 cp_decl_specifier_seq
*specs
= &parm
->decl_specifiers
;
15095 specs
->type
= TREE_TYPE (DECL_INITIAL (specs
->type
));
15096 return grokdeclarator (decl
, specs
, TPARM
, 0, NULL
);
15099 /* Build a constrained template parameter based on the PARMDECL
15100 declarator. The type of PARMDECL is the constrained type, which
15101 refers to the prototype template parameter that ultimately
15102 specifies the type of the declared parameter. */
15105 finish_constrained_parameter (cp_parser
*parser
,
15106 cp_parameter_declarator
*parmdecl
,
15108 bool *is_parameter_pack
)
15110 tree decl
= parmdecl
->decl_specifiers
.type
;
15111 tree id
= get_unqualified_id (parmdecl
->declarator
);
15112 tree def
= parmdecl
->default_argument
;
15113 tree proto
= DECL_INITIAL (decl
);
15115 /* A template parameter constrained by a variadic concept shall also
15116 be declared as a template parameter pack. */
15117 bool is_variadic
= template_parameter_pack_p (proto
);
15118 if (is_variadic
&& !*is_parameter_pack
)
15119 cp_parser_error (parser
, "variadic constraint introduced without %<...%>");
15121 /* Build the parameter. Return an error if the declarator was invalid. */
15123 if (TREE_CODE (proto
) == TYPE_DECL
)
15124 parm
= cp_parser_constrained_type_template_parm (parser
, id
, parmdecl
);
15125 else if (TREE_CODE (proto
) == TEMPLATE_DECL
)
15126 parm
= cp_parser_constrained_template_template_parm (parser
, proto
, id
,
15129 parm
= constrained_non_type_template_parm (is_non_type
, parmdecl
);
15130 if (parm
== error_mark_node
)
15131 return error_mark_node
;
15133 /* Finish the parameter decl and create a node attaching the
15134 default argument and constraint. */
15135 parm
= build_tree_list (def
, parm
);
15136 TEMPLATE_PARM_CONSTRAINTS (parm
) = decl
;
15141 /* Returns true if the parsed type actually represents the declaration
15142 of a type template-parameter. */
15145 declares_constrained_type_template_parameter (tree type
)
15147 return (is_constrained_parameter (type
)
15148 && TREE_CODE (TREE_TYPE (type
)) == TEMPLATE_TYPE_PARM
);
15152 /* Returns true if the parsed type actually represents the declaration of
15153 a template template-parameter. */
15156 declares_constrained_template_template_parameter (tree type
)
15158 return (is_constrained_parameter (type
)
15159 && TREE_CODE (TREE_TYPE (type
)) == TEMPLATE_TEMPLATE_PARM
);
15162 /* Parse a default argument for a type template-parameter.
15163 Note that diagnostics are handled in cp_parser_template_parameter. */
15166 cp_parser_default_type_template_argument (cp_parser
*parser
)
15168 gcc_assert (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
));
15170 /* Consume the `=' token. */
15171 cp_lexer_consume_token (parser
->lexer
);
15173 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
15175 /* Parse the default-argument. */
15176 push_deferring_access_checks (dk_no_deferred
);
15177 tree default_argument
= cp_parser_type_id (parser
);
15178 pop_deferring_access_checks ();
15180 if (flag_concepts
&& type_uses_auto (default_argument
))
15182 error_at (token
->location
,
15183 "invalid use of %<auto%> in default template argument");
15184 return error_mark_node
;
15187 return default_argument
;
15190 /* Parse a default argument for a template template-parameter. */
15193 cp_parser_default_template_template_argument (cp_parser
*parser
)
15195 gcc_assert (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
));
15199 /* Consume the `='. */
15200 cp_lexer_consume_token (parser
->lexer
);
15201 /* Parse the id-expression. */
15202 push_deferring_access_checks (dk_no_deferred
);
15203 /* save token before parsing the id-expression, for error
15205 const cp_token
* token
= cp_lexer_peek_token (parser
->lexer
);
15206 tree default_argument
15207 = cp_parser_id_expression (parser
,
15208 /*template_keyword_p=*/false,
15209 /*check_dependency_p=*/true,
15210 /*template_p=*/&is_template
,
15211 /*declarator_p=*/false,
15212 /*optional_p=*/false);
15213 if (TREE_CODE (default_argument
) == TYPE_DECL
)
15214 /* If the id-expression was a template-id that refers to
15215 a template-class, we already have the declaration here,
15216 so no further lookup is needed. */
15219 /* Look up the name. */
15221 = cp_parser_lookup_name (parser
, default_argument
,
15223 /*is_template=*/is_template
,
15224 /*is_namespace=*/false,
15225 /*check_dependency=*/true,
15226 /*ambiguous_decls=*/NULL
,
15228 /* See if the default argument is valid. */
15229 default_argument
= check_template_template_default_arg (default_argument
);
15230 pop_deferring_access_checks ();
15231 return default_argument
;
15234 /* Parse a template-parameter.
15236 template-parameter:
15238 parameter-declaration
15240 If all goes well, returns a TREE_LIST. The TREE_VALUE represents
15241 the parameter. The TREE_PURPOSE is the default value, if any.
15242 Returns ERROR_MARK_NODE on failure. *IS_NON_TYPE is set to true
15243 iff this parameter is a non-type parameter. *IS_PARAMETER_PACK is
15244 set to true iff this parameter is a parameter pack. */
15247 cp_parser_template_parameter (cp_parser
* parser
, bool *is_non_type
,
15248 bool *is_parameter_pack
)
15251 cp_parameter_declarator
*parameter_declarator
;
15254 /* Assume it is a type parameter or a template parameter. */
15255 *is_non_type
= false;
15256 /* Assume it not a parameter pack. */
15257 *is_parameter_pack
= false;
15258 /* Peek at the next token. */
15259 token
= cp_lexer_peek_token (parser
->lexer
);
15260 /* If it is `template', we have a type-parameter. */
15261 if (token
->keyword
== RID_TEMPLATE
)
15262 return cp_parser_type_parameter (parser
, is_parameter_pack
);
15263 /* If it is `class' or `typename' we do not know yet whether it is a
15264 type parameter or a non-type parameter. Consider:
15266 template <typename T, typename T::X X> ...
15270 template <class C, class D*> ...
15272 Here, the first parameter is a type parameter, and the second is
15273 a non-type parameter. We can tell by looking at the token after
15274 the identifier -- if it is a `,', `=', or `>' then we have a type
15276 if (token
->keyword
== RID_TYPENAME
|| token
->keyword
== RID_CLASS
)
15278 /* Peek at the token after `class' or `typename'. */
15279 token
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
15280 /* If it's an ellipsis, we have a template type parameter
15282 if (token
->type
== CPP_ELLIPSIS
)
15283 return cp_parser_type_parameter (parser
, is_parameter_pack
);
15284 /* If it's an identifier, skip it. */
15285 if (token
->type
== CPP_NAME
)
15286 token
= cp_lexer_peek_nth_token (parser
->lexer
, 3);
15287 /* Now, see if the token looks like the end of a template
15289 if (token
->type
== CPP_COMMA
15290 || token
->type
== CPP_EQ
15291 || token
->type
== CPP_GREATER
)
15292 return cp_parser_type_parameter (parser
, is_parameter_pack
);
15295 /* Otherwise, it is a non-type parameter or a constrained parameter.
15299 When parsing a default template-argument for a non-type
15300 template-parameter, the first non-nested `>' is taken as the end
15301 of the template parameter-list rather than a greater-than
15303 parameter_declarator
15304 = cp_parser_parameter_declaration (parser
, /*template_parm_p=*/true,
15305 /*parenthesized_p=*/NULL
);
15307 if (!parameter_declarator
)
15308 return error_mark_node
;
15310 /* If the parameter declaration is marked as a parameter pack, set
15311 *IS_PARAMETER_PACK to notify the caller. */
15312 if (parameter_declarator
->template_parameter_pack_p
)
15313 *is_parameter_pack
= true;
15315 if (parameter_declarator
->default_argument
)
15317 /* Can happen in some cases of erroneous input (c++/34892). */
15318 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
15319 /* Consume the `...' for better error recovery. */
15320 cp_lexer_consume_token (parser
->lexer
);
15323 // The parameter may have been constrained.
15324 if (is_constrained_parameter (parameter_declarator
))
15325 return finish_constrained_parameter (parser
,
15326 parameter_declarator
,
15328 is_parameter_pack
);
15330 // Now we're sure that the parameter is a non-type parameter.
15331 *is_non_type
= true;
15333 parm
= grokdeclarator (parameter_declarator
->declarator
,
15334 ¶meter_declarator
->decl_specifiers
,
15335 TPARM
, /*initialized=*/0,
15336 /*attrlist=*/NULL
);
15337 if (parm
== error_mark_node
)
15338 return error_mark_node
;
15340 return build_tree_list (parameter_declarator
->default_argument
, parm
);
15343 /* Parse a type-parameter.
15346 class identifier [opt]
15347 class identifier [opt] = type-id
15348 typename identifier [opt]
15349 typename identifier [opt] = type-id
15350 template < template-parameter-list > class identifier [opt]
15351 template < template-parameter-list > class identifier [opt]
15354 GNU Extension (variadic templates):
15357 class ... identifier [opt]
15358 typename ... identifier [opt]
15360 Returns a TREE_LIST. The TREE_VALUE is itself a TREE_LIST. The
15361 TREE_PURPOSE is the default-argument, if any. The TREE_VALUE is
15362 the declaration of the parameter.
15364 Sets *IS_PARAMETER_PACK if this is a template parameter pack. */
15367 cp_parser_type_parameter (cp_parser
* parser
, bool *is_parameter_pack
)
15372 /* Look for a keyword to tell us what kind of parameter this is. */
15373 token
= cp_parser_require (parser
, CPP_KEYWORD
, RT_CLASS_TYPENAME_TEMPLATE
);
15375 return error_mark_node
;
15377 switch (token
->keyword
)
15383 tree default_argument
;
15385 /* If the next token is an ellipsis, we have a template
15387 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
15389 /* Consume the `...' token. */
15390 cp_lexer_consume_token (parser
->lexer
);
15391 maybe_warn_variadic_templates ();
15393 *is_parameter_pack
= true;
15396 /* If the next token is an identifier, then it names the
15398 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
15399 identifier
= cp_parser_identifier (parser
);
15401 identifier
= NULL_TREE
;
15403 /* Create the parameter. */
15404 parameter
= finish_template_type_parm (class_type_node
, identifier
);
15406 /* If the next token is an `=', we have a default argument. */
15407 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
))
15410 = cp_parser_default_type_template_argument (parser
);
15412 /* Template parameter packs cannot have default
15414 if (*is_parameter_pack
)
15417 error_at (token
->location
,
15418 "template parameter pack %qD cannot have a "
15419 "default argument", identifier
);
15421 error_at (token
->location
,
15422 "template parameter packs cannot have "
15423 "default arguments");
15424 default_argument
= NULL_TREE
;
15426 else if (check_for_bare_parameter_packs (default_argument
))
15427 default_argument
= error_mark_node
;
15430 default_argument
= NULL_TREE
;
15432 /* Create the combined representation of the parameter and the
15433 default argument. */
15434 parameter
= build_tree_list (default_argument
, parameter
);
15441 tree default_argument
;
15443 /* Look for the `<'. */
15444 cp_parser_require (parser
, CPP_LESS
, RT_LESS
);
15445 /* Parse the template-parameter-list. */
15446 cp_parser_template_parameter_list (parser
);
15447 /* Look for the `>'. */
15448 cp_parser_require (parser
, CPP_GREATER
, RT_GREATER
);
15450 // If template requirements are present, parse them.
15453 tree reqs
= get_shorthand_constraints (current_template_parms
);
15454 if (tree r
= cp_parser_requires_clause_opt (parser
))
15455 reqs
= conjoin_constraints (reqs
, normalize_expression (r
));
15456 TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
) = reqs
;
15459 /* Look for the `class' or 'typename' keywords. */
15460 cp_parser_type_parameter_key (parser
);
15461 /* If the next token is an ellipsis, we have a template
15463 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
15465 /* Consume the `...' token. */
15466 cp_lexer_consume_token (parser
->lexer
);
15467 maybe_warn_variadic_templates ();
15469 *is_parameter_pack
= true;
15471 /* If the next token is an `=', then there is a
15472 default-argument. If the next token is a `>', we are at
15473 the end of the parameter-list. If the next token is a `,',
15474 then we are at the end of this parameter. */
15475 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_EQ
)
15476 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_GREATER
)
15477 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
15479 identifier
= cp_parser_identifier (parser
);
15480 /* Treat invalid names as if the parameter were nameless. */
15481 if (identifier
== error_mark_node
)
15482 identifier
= NULL_TREE
;
15485 identifier
= NULL_TREE
;
15487 /* Create the template parameter. */
15488 parameter
= finish_template_template_parm (class_type_node
,
15491 /* If the next token is an `=', then there is a
15492 default-argument. */
15493 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
))
15496 = cp_parser_default_template_template_argument (parser
);
15498 /* Template parameter packs cannot have default
15500 if (*is_parameter_pack
)
15503 error_at (token
->location
,
15504 "template parameter pack %qD cannot "
15505 "have a default argument",
15508 error_at (token
->location
, "template parameter packs cannot "
15509 "have default arguments");
15510 default_argument
= NULL_TREE
;
15514 default_argument
= NULL_TREE
;
15516 /* Create the combined representation of the parameter and the
15517 default argument. */
15518 parameter
= build_tree_list (default_argument
, parameter
);
15523 gcc_unreachable ();
15530 /* Parse a template-id.
15533 template-name < template-argument-list [opt] >
15535 If TEMPLATE_KEYWORD_P is TRUE, then we have just seen the
15536 `template' keyword. In this case, a TEMPLATE_ID_EXPR will be
15537 returned. Otherwise, if the template-name names a function, or set
15538 of functions, returns a TEMPLATE_ID_EXPR. If the template-name
15539 names a class, returns a TYPE_DECL for the specialization.
15541 If CHECK_DEPENDENCY_P is FALSE, names are looked up in
15542 uninstantiated templates. */
15545 cp_parser_template_id (cp_parser
*parser
,
15546 bool template_keyword_p
,
15547 bool check_dependency_p
,
15548 enum tag_types tag_type
,
15549 bool is_declaration
)
15554 cp_token_position start_of_id
= 0;
15555 cp_token
*next_token
= NULL
, *next_token_2
= NULL
;
15556 bool is_identifier
;
15558 /* If the next token corresponds to a template-id, there is no need
15560 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
15561 if (token
->type
== CPP_TEMPLATE_ID
)
15563 cp_lexer_consume_token (parser
->lexer
);
15564 return saved_checks_value (token
->u
.tree_check_value
);
15567 /* Avoid performing name lookup if there is no possibility of
15568 finding a template-id. */
15569 if ((token
->type
!= CPP_NAME
&& token
->keyword
!= RID_OPERATOR
)
15570 || (token
->type
== CPP_NAME
15571 && !cp_parser_nth_token_starts_template_argument_list_p
15574 cp_parser_error (parser
, "expected template-id");
15575 return error_mark_node
;
15578 /* Remember where the template-id starts. */
15579 if (cp_parser_uncommitted_to_tentative_parse_p (parser
))
15580 start_of_id
= cp_lexer_token_position (parser
->lexer
, false);
15582 push_deferring_access_checks (dk_deferred
);
15584 /* Parse the template-name. */
15585 is_identifier
= false;
15586 templ
= cp_parser_template_name (parser
, template_keyword_p
,
15587 check_dependency_p
,
15591 if (templ
== error_mark_node
|| is_identifier
)
15593 pop_deferring_access_checks ();
15597 /* Since we're going to preserve any side-effects from this parse, set up a
15598 firewall to protect our callers from cp_parser_commit_to_tentative_parse
15599 in the template arguments. */
15600 tentative_firewall
firewall (parser
);
15602 /* If we find the sequence `[:' after a template-name, it's probably
15603 a digraph-typo for `< ::'. Substitute the tokens and check if we can
15604 parse correctly the argument list. */
15605 if (((next_token
= cp_lexer_peek_token (parser
->lexer
))->type
15606 == CPP_OPEN_SQUARE
)
15607 && next_token
->flags
& DIGRAPH
15608 && ((next_token_2
= cp_lexer_peek_nth_token (parser
->lexer
, 2))->type
15610 && !(next_token_2
->flags
& PREV_WHITE
))
15612 cp_parser_parse_tentatively (parser
);
15613 /* Change `:' into `::'. */
15614 next_token_2
->type
= CPP_SCOPE
;
15615 /* Consume the first token (CPP_OPEN_SQUARE - which we pretend it is
15617 cp_lexer_consume_token (parser
->lexer
);
15619 /* Parse the arguments. */
15620 arguments
= cp_parser_enclosed_template_argument_list (parser
);
15621 if (!cp_parser_parse_definitely (parser
))
15623 /* If we couldn't parse an argument list, then we revert our changes
15624 and return simply an error. Maybe this is not a template-id
15626 next_token_2
->type
= CPP_COLON
;
15627 cp_parser_error (parser
, "expected %<<%>");
15628 pop_deferring_access_checks ();
15629 return error_mark_node
;
15631 /* Otherwise, emit an error about the invalid digraph, but continue
15632 parsing because we got our argument list. */
15633 if (permerror (next_token
->location
,
15634 "%<<::%> cannot begin a template-argument list"))
15636 static bool hint
= false;
15637 inform (next_token
->location
,
15638 "%<<:%> is an alternate spelling for %<[%>."
15639 " Insert whitespace between %<<%> and %<::%>");
15640 if (!hint
&& !flag_permissive
)
15642 inform (next_token
->location
, "(if you use %<-fpermissive%> "
15643 "or %<-std=c++11%>, or %<-std=gnu++11%> G++ will "
15644 "accept your code)");
15651 /* Look for the `<' that starts the template-argument-list. */
15652 if (!cp_parser_require (parser
, CPP_LESS
, RT_LESS
))
15654 pop_deferring_access_checks ();
15655 return error_mark_node
;
15657 /* Parse the arguments. */
15658 arguments
= cp_parser_enclosed_template_argument_list (parser
);
15661 /* Set the location to be of the form:
15662 template-name < template-argument-list [opt] >
15663 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15664 with caret == start at the start of the template-name,
15665 ranging until the closing '>'. */
15666 location_t finish_loc
15667 = get_finish (cp_lexer_previous_token (parser
->lexer
)->location
);
15668 location_t combined_loc
15669 = make_location (token
->location
, token
->location
, finish_loc
);
15671 /* Build a representation of the specialization. */
15672 if (identifier_p (templ
))
15673 template_id
= build_min_nt_loc (combined_loc
,
15676 else if (DECL_TYPE_TEMPLATE_P (templ
)
15677 || DECL_TEMPLATE_TEMPLATE_PARM_P (templ
))
15679 bool entering_scope
;
15680 /* In "template <typename T> ... A<T>::", A<T> is the abstract A
15681 template (rather than some instantiation thereof) only if
15682 is not nested within some other construct. For example, in
15683 "template <typename T> void f(T) { A<T>::", A<T> is just an
15684 instantiation of A. */
15685 entering_scope
= (template_parm_scope_p ()
15686 && cp_lexer_next_token_is (parser
->lexer
,
15689 = finish_template_type (templ
, arguments
, entering_scope
);
15691 /* A template-like identifier may be a partial concept id. */
15692 else if (flag_concepts
15693 && (template_id
= (cp_parser_maybe_partial_concept_id
15694 (parser
, templ
, arguments
))))
15695 return template_id
;
15696 else if (variable_template_p (templ
))
15698 template_id
= lookup_template_variable (templ
, arguments
);
15699 if (TREE_CODE (template_id
) == TEMPLATE_ID_EXPR
)
15700 SET_EXPR_LOCATION (template_id
, combined_loc
);
15704 /* If it's not a class-template or a template-template, it should be
15705 a function-template. */
15706 gcc_assert ((DECL_FUNCTION_TEMPLATE_P (templ
)
15707 || TREE_CODE (templ
) == OVERLOAD
15708 || BASELINK_P (templ
)));
15710 template_id
= lookup_template_function (templ
, arguments
);
15711 if (TREE_CODE (template_id
) == TEMPLATE_ID_EXPR
)
15712 SET_EXPR_LOCATION (template_id
, combined_loc
);
15715 /* If parsing tentatively, replace the sequence of tokens that makes
15716 up the template-id with a CPP_TEMPLATE_ID token. That way,
15717 should we re-parse the token stream, we will not have to repeat
15718 the effort required to do the parse, nor will we issue duplicate
15719 error messages about problems during instantiation of the
15722 /* Don't do this if we had a parse error in a declarator; re-parsing
15723 might succeed if a name changes meaning (60361). */
15724 && !(cp_parser_error_occurred (parser
)
15725 && cp_parser_parsing_tentatively (parser
)
15726 && parser
->in_declarator_p
))
15728 /* Reset the contents of the START_OF_ID token. */
15729 token
->type
= CPP_TEMPLATE_ID
;
15730 token
->location
= combined_loc
;
15732 /* We must mark the lookup as kept, so we don't throw it away on
15733 the first parse. */
15734 if (is_overloaded_fn (template_id
))
15735 lookup_keep (get_fns (template_id
), true);
15737 /* Retrieve any deferred checks. Do not pop this access checks yet
15738 so the memory will not be reclaimed during token replacing below. */
15739 token
->u
.tree_check_value
= ggc_cleared_alloc
<struct tree_check
> ();
15740 token
->u
.tree_check_value
->value
= template_id
;
15741 token
->u
.tree_check_value
->checks
= get_deferred_access_checks ();
15742 token
->keyword
= RID_MAX
;
15744 /* Purge all subsequent tokens. */
15745 cp_lexer_purge_tokens_after (parser
->lexer
, start_of_id
);
15747 /* ??? Can we actually assume that, if template_id ==
15748 error_mark_node, we will have issued a diagnostic to the
15749 user, as opposed to simply marking the tentative parse as
15751 if (cp_parser_error_occurred (parser
) && template_id
!= error_mark_node
)
15752 error_at (token
->location
, "parse error in template argument list");
15755 pop_to_parent_deferring_access_checks ();
15756 return template_id
;
15759 /* Parse a template-name.
15764 The standard should actually say:
15768 operator-function-id
15770 A defect report has been filed about this issue.
15772 A conversion-function-id cannot be a template name because they cannot
15773 be part of a template-id. In fact, looking at this code:
15775 a.operator K<int>()
15777 the conversion-function-id is "operator K<int>", and K<int> is a type-id.
15778 It is impossible to call a templated conversion-function-id with an
15779 explicit argument list, since the only allowed template parameter is
15780 the type to which it is converting.
15782 If TEMPLATE_KEYWORD_P is true, then we have just seen the
15783 `template' keyword, in a construction like:
15787 In that case `f' is taken to be a template-name, even though there
15788 is no way of knowing for sure.
15790 Returns the TEMPLATE_DECL for the template, or an OVERLOAD if the
15791 name refers to a set of overloaded functions, at least one of which
15792 is a template, or an IDENTIFIER_NODE with the name of the template,
15793 if TEMPLATE_KEYWORD_P is true. If CHECK_DEPENDENCY_P is FALSE,
15794 names are looked up inside uninstantiated templates. */
15797 cp_parser_template_name (cp_parser
* parser
,
15798 bool template_keyword_p
,
15799 bool check_dependency_p
,
15800 bool is_declaration
,
15801 enum tag_types tag_type
,
15802 bool *is_identifier
)
15806 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
15808 /* If the next token is `operator', then we have either an
15809 operator-function-id or a conversion-function-id. */
15810 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_OPERATOR
))
15812 /* We don't know whether we're looking at an
15813 operator-function-id or a conversion-function-id. */
15814 cp_parser_parse_tentatively (parser
);
15815 /* Try an operator-function-id. */
15816 identifier
= cp_parser_operator_function_id (parser
);
15817 /* If that didn't work, try a conversion-function-id. */
15818 if (!cp_parser_parse_definitely (parser
))
15820 cp_parser_error (parser
, "expected template-name");
15821 return error_mark_node
;
15824 /* Look for the identifier. */
15826 identifier
= cp_parser_identifier (parser
);
15828 /* If we didn't find an identifier, we don't have a template-id. */
15829 if (identifier
== error_mark_node
)
15830 return error_mark_node
;
15832 /* If the name immediately followed the `template' keyword, then it
15833 is a template-name. However, if the next token is not `<', then
15834 we do not treat it as a template-name, since it is not being used
15835 as part of a template-id. This enables us to handle constructs
15838 template <typename T> struct S { S(); };
15839 template <typename T> S<T>::S();
15841 correctly. We would treat `S' as a template -- if it were `S<T>'
15842 -- but we do not if there is no `<'. */
15844 if (processing_template_decl
15845 && cp_parser_nth_token_starts_template_argument_list_p (parser
, 1))
15847 /* In a declaration, in a dependent context, we pretend that the
15848 "template" keyword was present in order to improve error
15849 recovery. For example, given:
15851 template <typename T> void f(T::X<int>);
15853 we want to treat "X<int>" as a template-id. */
15855 && !template_keyword_p
15856 && parser
->scope
&& TYPE_P (parser
->scope
)
15857 && check_dependency_p
15858 && dependent_scope_p (parser
->scope
)
15859 /* Do not do this for dtors (or ctors), since they never
15860 need the template keyword before their name. */
15861 && !constructor_name_p (identifier
, parser
->scope
))
15863 cp_token_position start
= 0;
15865 /* Explain what went wrong. */
15866 error_at (token
->location
, "non-template %qD used as template",
15868 inform (token
->location
, "use %<%T::template %D%> to indicate that it is a template",
15869 parser
->scope
, identifier
);
15870 /* If parsing tentatively, find the location of the "<" token. */
15871 if (cp_parser_simulate_error (parser
))
15872 start
= cp_lexer_token_position (parser
->lexer
, true);
15873 /* Parse the template arguments so that we can issue error
15874 messages about them. */
15875 cp_lexer_consume_token (parser
->lexer
);
15876 cp_parser_enclosed_template_argument_list (parser
);
15877 /* Skip tokens until we find a good place from which to
15878 continue parsing. */
15879 cp_parser_skip_to_closing_parenthesis (parser
,
15880 /*recovering=*/true,
15882 /*consume_paren=*/false);
15883 /* If parsing tentatively, permanently remove the
15884 template argument list. That will prevent duplicate
15885 error messages from being issued about the missing
15886 "template" keyword. */
15888 cp_lexer_purge_tokens_after (parser
->lexer
, start
);
15890 *is_identifier
= true;
15891 parser
->context
->object_type
= NULL_TREE
;
15895 /* If the "template" keyword is present, then there is generally
15896 no point in doing name-lookup, so we just return IDENTIFIER.
15897 But, if the qualifying scope is non-dependent then we can
15898 (and must) do name-lookup normally. */
15899 if (template_keyword_p
)
15901 tree scope
= (parser
->scope
? parser
->scope
15902 : parser
->context
->object_type
);
15903 if (scope
&& TYPE_P (scope
)
15904 && (!CLASS_TYPE_P (scope
)
15905 || (check_dependency_p
&& dependent_type_p (scope
))))
15907 /* We're optimizing away the call to cp_parser_lookup_name, but
15908 we still need to do this. */
15909 parser
->context
->object_type
= NULL_TREE
;
15915 /* Look up the name. */
15916 decl
= cp_parser_lookup_name (parser
, identifier
,
15918 /*is_template=*/true,
15919 /*is_namespace=*/false,
15920 check_dependency_p
,
15921 /*ambiguous_decls=*/NULL
,
15924 decl
= strip_using_decl (decl
);
15926 /* If DECL is a template, then the name was a template-name. */
15927 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
15929 if (TREE_DEPRECATED (decl
)
15930 && deprecated_state
!= DEPRECATED_SUPPRESS
)
15931 warn_deprecated_use (decl
, NULL_TREE
);
15935 /* The standard does not explicitly indicate whether a name that
15936 names a set of overloaded declarations, some of which are
15937 templates, is a template-name. However, such a name should
15938 be a template-name; otherwise, there is no way to form a
15939 template-id for the overloaded templates. */
15940 bool found
= false;
15942 for (lkp_iterator
iter (MAYBE_BASELINK_FUNCTIONS (decl
));
15943 !found
&& iter
; ++iter
)
15944 if (TREE_CODE (*iter
) == TEMPLATE_DECL
)
15949 /* The name does not name a template. */
15950 cp_parser_error (parser
, "expected template-name");
15951 return error_mark_node
;
15955 /* If DECL is dependent, and refers to a function, then just return
15956 its name; we will look it up again during template instantiation. */
15957 if (DECL_FUNCTION_TEMPLATE_P (decl
) || !DECL_P (decl
))
15959 tree scope
= ovl_scope (decl
);
15960 if (TYPE_P (scope
) && dependent_type_p (scope
))
15967 /* Parse a template-argument-list.
15969 template-argument-list:
15970 template-argument ... [opt]
15971 template-argument-list , template-argument ... [opt]
15973 Returns a TREE_VEC containing the arguments. */
15976 cp_parser_template_argument_list (cp_parser
* parser
)
15978 tree fixed_args
[10];
15979 unsigned n_args
= 0;
15980 unsigned alloced
= 10;
15981 tree
*arg_ary
= fixed_args
;
15983 bool saved_in_template_argument_list_p
;
15985 bool saved_non_ice_p
;
15987 saved_in_template_argument_list_p
= parser
->in_template_argument_list_p
;
15988 parser
->in_template_argument_list_p
= true;
15989 /* Even if the template-id appears in an integral
15990 constant-expression, the contents of the argument list do
15992 saved_ice_p
= parser
->integral_constant_expression_p
;
15993 parser
->integral_constant_expression_p
= false;
15994 saved_non_ice_p
= parser
->non_integral_constant_expression_p
;
15995 parser
->non_integral_constant_expression_p
= false;
15997 /* Parse the arguments. */
16003 /* Consume the comma. */
16004 cp_lexer_consume_token (parser
->lexer
);
16006 /* Parse the template-argument. */
16007 argument
= cp_parser_template_argument (parser
);
16009 /* If the next token is an ellipsis, we're expanding a template
16011 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
16013 if (argument
== error_mark_node
)
16015 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
16016 error_at (token
->location
,
16017 "expected parameter pack before %<...%>");
16019 /* Consume the `...' token. */
16020 cp_lexer_consume_token (parser
->lexer
);
16022 /* Make the argument into a TYPE_PACK_EXPANSION or
16023 EXPR_PACK_EXPANSION. */
16024 argument
= make_pack_expansion (argument
);
16027 if (n_args
== alloced
)
16031 if (arg_ary
== fixed_args
)
16033 arg_ary
= XNEWVEC (tree
, alloced
);
16034 memcpy (arg_ary
, fixed_args
, sizeof (tree
) * n_args
);
16037 arg_ary
= XRESIZEVEC (tree
, arg_ary
, alloced
);
16039 arg_ary
[n_args
++] = argument
;
16041 while (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
));
16043 vec
= make_tree_vec (n_args
);
16046 TREE_VEC_ELT (vec
, n_args
) = arg_ary
[n_args
];
16048 if (arg_ary
!= fixed_args
)
16050 parser
->non_integral_constant_expression_p
= saved_non_ice_p
;
16051 parser
->integral_constant_expression_p
= saved_ice_p
;
16052 parser
->in_template_argument_list_p
= saved_in_template_argument_list_p
;
16054 SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (vec
, TREE_VEC_LENGTH (vec
));
16058 /* Parse a template-argument.
16061 assignment-expression
16065 The representation is that of an assignment-expression, type-id, or
16066 id-expression -- except that the qualified id-expression is
16067 evaluated, so that the value returned is either a DECL or an
16070 Although the standard says "assignment-expression", it forbids
16071 throw-expressions or assignments in the template argument.
16072 Therefore, we use "conditional-expression" instead. */
16075 cp_parser_template_argument (cp_parser
* parser
)
16080 bool maybe_type_id
= false;
16081 cp_token
*token
= NULL
, *argument_start_token
= NULL
;
16082 location_t loc
= 0;
16085 /* There's really no way to know what we're looking at, so we just
16086 try each alternative in order.
16090 In a template-argument, an ambiguity between a type-id and an
16091 expression is resolved to a type-id, regardless of the form of
16092 the corresponding template-parameter.
16094 Therefore, we try a type-id first. */
16095 cp_parser_parse_tentatively (parser
);
16096 argument
= cp_parser_template_type_arg (parser
);
16097 /* If there was no error parsing the type-id but the next token is a
16098 '>>', our behavior depends on which dialect of C++ we're
16099 parsing. In C++98, we probably found a typo for '> >'. But there
16100 are type-id which are also valid expressions. For instance:
16102 struct X { int operator >> (int); };
16103 template <int V> struct Foo {};
16106 Here 'X()' is a valid type-id of a function type, but the user just
16107 wanted to write the expression "X() >> 5". Thus, we remember that we
16108 found a valid type-id, but we still try to parse the argument as an
16109 expression to see what happens.
16111 In C++0x, the '>>' will be considered two separate '>'
16113 if (!cp_parser_error_occurred (parser
)
16114 && cxx_dialect
== cxx98
16115 && cp_lexer_next_token_is (parser
->lexer
, CPP_RSHIFT
))
16117 maybe_type_id
= true;
16118 cp_parser_abort_tentative_parse (parser
);
16122 /* If the next token isn't a `,' or a `>', then this argument wasn't
16123 really finished. This means that the argument is not a valid
16125 if (!cp_parser_next_token_ends_template_argument_p (parser
))
16126 cp_parser_error (parser
, "expected template-argument");
16127 /* If that worked, we're done. */
16128 if (cp_parser_parse_definitely (parser
))
16131 /* We're still not sure what the argument will be. */
16132 cp_parser_parse_tentatively (parser
);
16133 /* Try a template. */
16134 argument_start_token
= cp_lexer_peek_token (parser
->lexer
);
16135 argument
= cp_parser_id_expression (parser
,
16136 /*template_keyword_p=*/false,
16137 /*check_dependency_p=*/true,
16139 /*declarator_p=*/false,
16140 /*optional_p=*/false);
16141 /* If the next token isn't a `,' or a `>', then this argument wasn't
16142 really finished. */
16143 if (!cp_parser_next_token_ends_template_argument_p (parser
))
16144 cp_parser_error (parser
, "expected template-argument");
16145 if (!cp_parser_error_occurred (parser
))
16147 /* Figure out what is being referred to. If the id-expression
16148 was for a class template specialization, then we will have a
16149 TYPE_DECL at this point. There is no need to do name lookup
16150 at this point in that case. */
16151 if (TREE_CODE (argument
) != TYPE_DECL
)
16152 argument
= cp_parser_lookup_name (parser
, argument
,
16154 /*is_template=*/template_p
,
16155 /*is_namespace=*/false,
16156 /*check_dependency=*/true,
16157 /*ambiguous_decls=*/NULL
,
16158 argument_start_token
->location
);
16159 /* Handle a constrained-type-specifier for a non-type template
16161 if (tree decl
= cp_parser_maybe_concept_name (parser
, argument
))
16163 else if (TREE_CODE (argument
) != TEMPLATE_DECL
16164 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
16165 cp_parser_error (parser
, "expected template-name");
16167 if (cp_parser_parse_definitely (parser
))
16169 if (TREE_DEPRECATED (argument
))
16170 warn_deprecated_use (argument
, NULL_TREE
);
16173 /* It must be a non-type argument. In C++17 any constant-expression is
16175 if (cxx_dialect
> cxx14
)
16178 /* Otherwise, the permitted cases are given in [temp.arg.nontype]:
16180 -- an integral constant-expression of integral or enumeration
16183 -- the name of a non-type template-parameter; or
16185 -- the name of an object or function with external linkage...
16187 -- the address of an object or function with external linkage...
16189 -- a pointer to member... */
16190 /* Look for a non-type template parameter. */
16191 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
16193 cp_parser_parse_tentatively (parser
);
16194 argument
= cp_parser_primary_expression (parser
,
16195 /*address_p=*/false,
16197 /*template_arg_p=*/true,
16199 if (TREE_CODE (argument
) != TEMPLATE_PARM_INDEX
16200 || !cp_parser_next_token_ends_template_argument_p (parser
))
16201 cp_parser_simulate_error (parser
);
16202 if (cp_parser_parse_definitely (parser
))
16206 /* If the next token is "&", the argument must be the address of an
16207 object or function with external linkage. */
16208 address_p
= cp_lexer_next_token_is (parser
->lexer
, CPP_AND
);
16211 loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
16212 cp_lexer_consume_token (parser
->lexer
);
16214 /* See if we might have an id-expression. */
16215 token
= cp_lexer_peek_token (parser
->lexer
);
16216 if (token
->type
== CPP_NAME
16217 || token
->keyword
== RID_OPERATOR
16218 || token
->type
== CPP_SCOPE
16219 || token
->type
== CPP_TEMPLATE_ID
16220 || token
->type
== CPP_NESTED_NAME_SPECIFIER
)
16222 cp_parser_parse_tentatively (parser
);
16223 argument
= cp_parser_primary_expression (parser
,
16226 /*template_arg_p=*/true,
16228 if (cp_parser_error_occurred (parser
)
16229 || !cp_parser_next_token_ends_template_argument_p (parser
))
16230 cp_parser_abort_tentative_parse (parser
);
16235 if (INDIRECT_REF_P (argument
))
16237 /* Strip the dereference temporarily. */
16238 gcc_assert (REFERENCE_REF_P (argument
));
16239 argument
= TREE_OPERAND (argument
, 0);
16242 /* If we're in a template, we represent a qualified-id referring
16243 to a static data member as a SCOPE_REF even if the scope isn't
16244 dependent so that we can check access control later. */
16246 if (TREE_CODE (probe
) == SCOPE_REF
)
16247 probe
= TREE_OPERAND (probe
, 1);
16250 /* A variable without external linkage might still be a
16251 valid constant-expression, so no error is issued here
16252 if the external-linkage check fails. */
16253 if (!address_p
&& !DECL_EXTERNAL_LINKAGE_P (probe
))
16254 cp_parser_simulate_error (parser
);
16256 else if (is_overloaded_fn (argument
))
16257 /* All overloaded functions are allowed; if the external
16258 linkage test does not pass, an error will be issued
16262 && (TREE_CODE (argument
) == OFFSET_REF
16263 || TREE_CODE (argument
) == SCOPE_REF
))
16264 /* A pointer-to-member. */
16266 else if (TREE_CODE (argument
) == TEMPLATE_PARM_INDEX
)
16269 cp_parser_simulate_error (parser
);
16271 if (cp_parser_parse_definitely (parser
))
16274 argument
= build_x_unary_op (loc
, ADDR_EXPR
, argument
,
16275 tf_warning_or_error
);
16277 argument
= convert_from_reference (argument
);
16282 /* If the argument started with "&", there are no other valid
16283 alternatives at this point. */
16286 cp_parser_error (parser
, "invalid non-type template argument");
16287 return error_mark_node
;
16291 /* If the argument wasn't successfully parsed as a type-id followed
16292 by '>>', the argument can only be a constant expression now.
16293 Otherwise, we try parsing the constant-expression tentatively,
16294 because the argument could really be a type-id. */
16296 cp_parser_parse_tentatively (parser
);
16298 if (cxx_dialect
<= cxx14
)
16299 argument
= cp_parser_constant_expression (parser
);
16302 /* With C++17 generalized non-type template arguments we need to handle
16303 lvalue constant expressions, too. */
16304 argument
= cp_parser_assignment_expression (parser
);
16305 require_potential_constant_expression (argument
);
16308 if (!maybe_type_id
)
16310 if (!cp_parser_next_token_ends_template_argument_p (parser
))
16311 cp_parser_error (parser
, "expected template-argument");
16312 if (cp_parser_parse_definitely (parser
))
16314 /* We did our best to parse the argument as a non type-id, but that
16315 was the only alternative that matched (albeit with a '>' after
16316 it). We can assume it's just a typo from the user, and a
16317 diagnostic will then be issued. */
16318 return cp_parser_template_type_arg (parser
);
16321 /* Parse an explicit-instantiation.
16323 explicit-instantiation:
16324 template declaration
16326 Although the standard says `declaration', what it really means is:
16328 explicit-instantiation:
16329 template decl-specifier-seq [opt] declarator [opt] ;
16331 Things like `template int S<int>::i = 5, int S<double>::j;' are not
16332 supposed to be allowed. A defect report has been filed about this
16337 explicit-instantiation:
16338 storage-class-specifier template
16339 decl-specifier-seq [opt] declarator [opt] ;
16340 function-specifier template
16341 decl-specifier-seq [opt] declarator [opt] ; */
16344 cp_parser_explicit_instantiation (cp_parser
* parser
)
16346 int declares_class_or_enum
;
16347 cp_decl_specifier_seq decl_specifiers
;
16348 tree extension_specifier
= NULL_TREE
;
16350 timevar_push (TV_TEMPLATE_INST
);
16352 /* Look for an (optional) storage-class-specifier or
16353 function-specifier. */
16354 if (cp_parser_allow_gnu_extensions_p (parser
))
16356 extension_specifier
16357 = cp_parser_storage_class_specifier_opt (parser
);
16358 if (!extension_specifier
)
16359 extension_specifier
16360 = cp_parser_function_specifier_opt (parser
,
16361 /*decl_specs=*/NULL
);
16364 /* Look for the `template' keyword. */
16365 cp_parser_require_keyword (parser
, RID_TEMPLATE
, RT_TEMPLATE
);
16366 /* Let the front end know that we are processing an explicit
16368 begin_explicit_instantiation ();
16369 /* [temp.explicit] says that we are supposed to ignore access
16370 control while processing explicit instantiation directives. */
16371 push_deferring_access_checks (dk_no_check
);
16372 /* Parse a decl-specifier-seq. */
16373 cp_parser_decl_specifier_seq (parser
,
16374 CP_PARSER_FLAGS_OPTIONAL
,
16376 &declares_class_or_enum
);
16377 /* If there was exactly one decl-specifier, and it declared a class,
16378 and there's no declarator, then we have an explicit type
16380 if (declares_class_or_enum
&& cp_parser_declares_only_class_p (parser
))
16384 type
= check_tag_decl (&decl_specifiers
,
16385 /*explicit_type_instantiation_p=*/true);
16386 /* Turn access control back on for names used during
16387 template instantiation. */
16388 pop_deferring_access_checks ();
16390 do_type_instantiation (type
, extension_specifier
,
16391 /*complain=*/tf_error
);
16395 cp_declarator
*declarator
;
16398 /* Parse the declarator. */
16400 = cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_NAMED
,
16401 /*ctor_dtor_or_conv_p=*/NULL
,
16402 /*parenthesized_p=*/NULL
,
16403 /*member_p=*/false,
16404 /*friend_p=*/false);
16405 if (declares_class_or_enum
& 2)
16406 cp_parser_check_for_definition_in_return_type (declarator
,
16407 decl_specifiers
.type
,
16408 decl_specifiers
.locations
[ds_type_spec
]);
16409 if (declarator
!= cp_error_declarator
)
16411 if (decl_spec_seq_has_spec_p (&decl_specifiers
, ds_inline
))
16412 permerror (decl_specifiers
.locations
[ds_inline
],
16413 "explicit instantiation shall not use"
16414 " %<inline%> specifier");
16415 if (decl_spec_seq_has_spec_p (&decl_specifiers
, ds_constexpr
))
16416 permerror (decl_specifiers
.locations
[ds_constexpr
],
16417 "explicit instantiation shall not use"
16418 " %<constexpr%> specifier");
16420 decl
= grokdeclarator (declarator
, &decl_specifiers
,
16421 NORMAL
, 0, &decl_specifiers
.attributes
);
16422 /* Turn access control back on for names used during
16423 template instantiation. */
16424 pop_deferring_access_checks ();
16425 /* Do the explicit instantiation. */
16426 do_decl_instantiation (decl
, extension_specifier
);
16430 pop_deferring_access_checks ();
16431 /* Skip the body of the explicit instantiation. */
16432 cp_parser_skip_to_end_of_statement (parser
);
16435 /* We're done with the instantiation. */
16436 end_explicit_instantiation ();
16438 cp_parser_consume_semicolon_at_end_of_statement (parser
);
16440 timevar_pop (TV_TEMPLATE_INST
);
16443 /* Parse an explicit-specialization.
16445 explicit-specialization:
16446 template < > declaration
16448 Although the standard says `declaration', what it really means is:
16450 explicit-specialization:
16451 template <> decl-specifier [opt] init-declarator [opt] ;
16452 template <> function-definition
16453 template <> explicit-specialization
16454 template <> template-declaration */
16457 cp_parser_explicit_specialization (cp_parser
* parser
)
16459 bool need_lang_pop
;
16460 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
16462 /* Look for the `template' keyword. */
16463 cp_parser_require_keyword (parser
, RID_TEMPLATE
, RT_TEMPLATE
);
16464 /* Look for the `<'. */
16465 cp_parser_require (parser
, CPP_LESS
, RT_LESS
);
16466 /* Look for the `>'. */
16467 cp_parser_require (parser
, CPP_GREATER
, RT_GREATER
);
16468 /* We have processed another parameter list. */
16469 ++parser
->num_template_parameter_lists
;
16472 A template ... explicit specialization ... shall not have C
16474 if (current_lang_name
== lang_name_c
)
16476 error_at (token
->location
, "template specialization with C linkage");
16477 /* Give it C++ linkage to avoid confusing other parts of the
16479 push_lang_context (lang_name_cplusplus
);
16480 need_lang_pop
= true;
16483 need_lang_pop
= false;
16484 /* Let the front end know that we are beginning a specialization. */
16485 if (!begin_specialization ())
16487 end_specialization ();
16491 /* If the next keyword is `template', we need to figure out whether
16492 or not we're looking a template-declaration. */
16493 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TEMPLATE
))
16495 if (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_LESS
16496 && cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
!= CPP_GREATER
)
16497 cp_parser_template_declaration_after_export (parser
,
16498 /*member_p=*/false);
16500 cp_parser_explicit_specialization (parser
);
16503 /* Parse the dependent declaration. */
16504 cp_parser_single_declaration (parser
,
16506 /*member_p=*/false,
16507 /*explicit_specialization_p=*/true,
16508 /*friend_p=*/NULL
);
16509 /* We're done with the specialization. */
16510 end_specialization ();
16511 /* For the erroneous case of a template with C linkage, we pushed an
16512 implicit C++ linkage scope; exit that scope now. */
16514 pop_lang_context ();
16515 /* We're done with this parameter list. */
16516 --parser
->num_template_parameter_lists
;
16519 /* Parse a type-specifier.
16522 simple-type-specifier
16525 elaborated-type-specifier
16533 Returns a representation of the type-specifier. For a
16534 class-specifier, enum-specifier, or elaborated-type-specifier, a
16535 TREE_TYPE is returned; otherwise, a TYPE_DECL is returned.
16537 The parser flags FLAGS is used to control type-specifier parsing.
16539 If IS_DECLARATION is TRUE, then this type-specifier is appearing
16540 in a decl-specifier-seq.
16542 If DECLARES_CLASS_OR_ENUM is non-NULL, and the type-specifier is a
16543 class-specifier, enum-specifier, or elaborated-type-specifier, then
16544 *DECLARES_CLASS_OR_ENUM is set to a nonzero value. The value is 1
16545 if a type is declared; 2 if it is defined. Otherwise, it is set to
16548 If IS_CV_QUALIFIER is non-NULL, and the type-specifier is a
16549 cv-qualifier, then IS_CV_QUALIFIER is set to TRUE. Otherwise, it
16550 is set to FALSE. */
16553 cp_parser_type_specifier (cp_parser
* parser
,
16554 cp_parser_flags flags
,
16555 cp_decl_specifier_seq
*decl_specs
,
16556 bool is_declaration
,
16557 int* declares_class_or_enum
,
16558 bool* is_cv_qualifier
)
16560 tree type_spec
= NULL_TREE
;
16563 cp_decl_spec ds
= ds_last
;
16565 /* Assume this type-specifier does not declare a new type. */
16566 if (declares_class_or_enum
)
16567 *declares_class_or_enum
= 0;
16568 /* And that it does not specify a cv-qualifier. */
16569 if (is_cv_qualifier
)
16570 *is_cv_qualifier
= false;
16571 /* Peek at the next token. */
16572 token
= cp_lexer_peek_token (parser
->lexer
);
16574 /* If we're looking at a keyword, we can use that to guide the
16575 production we choose. */
16576 keyword
= token
->keyword
;
16580 if ((flags
& CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
))
16581 goto elaborated_type_specifier
;
16583 /* Look for the enum-specifier. */
16584 type_spec
= cp_parser_enum_specifier (parser
);
16585 /* If that worked, we're done. */
16588 if (declares_class_or_enum
)
16589 *declares_class_or_enum
= 2;
16591 cp_parser_set_decl_spec_type (decl_specs
,
16594 /*type_definition_p=*/true);
16598 goto elaborated_type_specifier
;
16600 /* Any of these indicate either a class-specifier, or an
16601 elaborated-type-specifier. */
16605 if ((flags
& CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
))
16606 goto elaborated_type_specifier
;
16608 /* Parse tentatively so that we can back up if we don't find a
16609 class-specifier. */
16610 cp_parser_parse_tentatively (parser
);
16611 /* Look for the class-specifier. */
16612 type_spec
= cp_parser_class_specifier (parser
);
16613 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, type_spec
);
16614 /* If that worked, we're done. */
16615 if (cp_parser_parse_definitely (parser
))
16617 if (declares_class_or_enum
)
16618 *declares_class_or_enum
= 2;
16620 cp_parser_set_decl_spec_type (decl_specs
,
16623 /*type_definition_p=*/true);
16627 /* Fall through. */
16628 elaborated_type_specifier
:
16629 /* We're declaring (not defining) a class or enum. */
16630 if (declares_class_or_enum
)
16631 *declares_class_or_enum
= 1;
16633 /* Fall through. */
16635 /* Look for an elaborated-type-specifier. */
16637 = (cp_parser_elaborated_type_specifier
16639 decl_spec_seq_has_spec_p (decl_specs
, ds_friend
),
16642 cp_parser_set_decl_spec_type (decl_specs
,
16645 /*type_definition_p=*/false);
16650 if (is_cv_qualifier
)
16651 *is_cv_qualifier
= true;
16656 if (is_cv_qualifier
)
16657 *is_cv_qualifier
= true;
16662 if (is_cv_qualifier
)
16663 *is_cv_qualifier
= true;
16667 /* The `__complex__' keyword is a GNU extension. */
16675 /* Handle simple keywords. */
16680 set_and_check_decl_spec_loc (decl_specs
, ds
, token
);
16681 decl_specs
->any_specifiers_p
= true;
16683 return cp_lexer_consume_token (parser
->lexer
)->u
.value
;
16686 /* If we do not already have a type-specifier, assume we are looking
16687 at a simple-type-specifier. */
16688 type_spec
= cp_parser_simple_type_specifier (parser
,
16692 /* If we didn't find a type-specifier, and a type-specifier was not
16693 optional in this context, issue an error message. */
16694 if (!type_spec
&& !(flags
& CP_PARSER_FLAGS_OPTIONAL
))
16696 cp_parser_error (parser
, "expected type specifier");
16697 return error_mark_node
;
16703 /* Parse a simple-type-specifier.
16705 simple-type-specifier:
16706 :: [opt] nested-name-specifier [opt] type-name
16707 :: [opt] nested-name-specifier template template-id
16722 simple-type-specifier:
16724 decltype ( expression )
16727 __underlying_type ( type-id )
16731 nested-name-specifier(opt) template-name
16735 simple-type-specifier:
16737 __typeof__ unary-expression
16738 __typeof__ ( type-id )
16739 __typeof__ ( type-id ) { initializer-list , [opt] }
16741 Concepts Extension:
16743 simple-type-specifier:
16744 constrained-type-specifier
16746 Returns the indicated TYPE_DECL. If DECL_SPECS is not NULL, it is
16747 appropriately updated. */
16750 cp_parser_simple_type_specifier (cp_parser
* parser
,
16751 cp_decl_specifier_seq
*decl_specs
,
16752 cp_parser_flags flags
)
16754 tree type
= NULL_TREE
;
16758 /* Peek at the next token. */
16759 token
= cp_lexer_peek_token (parser
->lexer
);
16761 /* If we're looking at a keyword, things are easy. */
16762 switch (token
->keyword
)
16766 decl_specs
->explicit_char_p
= true;
16767 type
= char_type_node
;
16770 type
= char16_type_node
;
16773 type
= char32_type_node
;
16776 type
= wchar_type_node
;
16779 type
= boolean_type_node
;
16782 set_and_check_decl_spec_loc (decl_specs
, ds_short
, token
);
16783 type
= short_integer_type_node
;
16787 decl_specs
->explicit_int_p
= true;
16788 type
= integer_type_node
;
16794 idx
= token
->keyword
- RID_INT_N_0
;
16795 if (! int_n_enabled_p
[idx
])
16799 decl_specs
->explicit_intN_p
= true;
16800 decl_specs
->int_n_idx
= idx
;
16802 type
= int_n_trees
[idx
].signed_type
;
16806 set_and_check_decl_spec_loc (decl_specs
, ds_long
, token
);
16807 type
= long_integer_type_node
;
16810 set_and_check_decl_spec_loc (decl_specs
, ds_signed
, token
);
16811 type
= integer_type_node
;
16814 set_and_check_decl_spec_loc (decl_specs
, ds_unsigned
, token
);
16815 type
= unsigned_type_node
;
16818 type
= float_type_node
;
16821 type
= double_type_node
;
16824 type
= void_type_node
;
16828 maybe_warn_cpp0x (CPP0X_AUTO
);
16829 if (parser
->auto_is_implicit_function_template_parm_p
)
16831 /* The 'auto' might be the placeholder return type for a function decl
16832 with trailing return type. */
16833 bool have_trailing_return_fn_decl
= false;
16835 cp_parser_parse_tentatively (parser
);
16836 cp_lexer_consume_token (parser
->lexer
);
16837 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_EQ
)
16838 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
)
16839 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_PAREN
)
16840 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_EOF
))
16842 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
16844 cp_lexer_consume_token (parser
->lexer
);
16845 cp_parser_skip_to_closing_parenthesis (parser
,
16846 /*recovering*/false,
16848 /*consume_paren*/true);
16852 if (cp_lexer_next_token_is (parser
->lexer
, CPP_DEREF
))
16854 have_trailing_return_fn_decl
= true;
16858 cp_lexer_consume_token (parser
->lexer
);
16860 cp_parser_abort_tentative_parse (parser
);
16862 if (have_trailing_return_fn_decl
)
16864 type
= make_auto ();
16868 if (cxx_dialect
>= cxx14
)
16870 type
= synthesize_implicit_template_parm (parser
, NULL_TREE
);
16871 type
= TREE_TYPE (type
);
16874 type
= error_mark_node
;
16876 if (current_class_type
&& LAMBDA_TYPE_P (current_class_type
))
16878 if (cxx_dialect
< cxx14
)
16879 error_at (token
->location
,
16880 "use of %<auto%> in lambda parameter declaration "
16881 "only available with "
16882 "-std=c++14 or -std=gnu++14");
16884 else if (cxx_dialect
< cxx14
)
16885 error_at (token
->location
,
16886 "use of %<auto%> in parameter declaration "
16887 "only available with "
16888 "-std=c++14 or -std=gnu++14");
16889 else if (!flag_concepts
)
16890 pedwarn (token
->location
, OPT_Wpedantic
,
16891 "ISO C++ forbids use of %<auto%> in parameter "
16895 type
= make_auto ();
16899 /* Since DR 743, decltype can either be a simple-type-specifier by
16900 itself or begin a nested-name-specifier. Parsing it will replace
16901 it with a CPP_DECLTYPE, so just rewind and let the CPP_DECLTYPE
16902 handling below decide what to do. */
16903 cp_parser_decltype (parser
);
16904 cp_lexer_set_token_position (parser
->lexer
, token
);
16908 /* Consume the `typeof' token. */
16909 cp_lexer_consume_token (parser
->lexer
);
16910 /* Parse the operand to `typeof'. */
16911 type
= cp_parser_sizeof_operand (parser
, RID_TYPEOF
);
16912 /* If it is not already a TYPE, take its type. */
16913 if (!TYPE_P (type
))
16914 type
= finish_typeof (type
);
16917 cp_parser_set_decl_spec_type (decl_specs
, type
,
16919 /*type_definition_p=*/false);
16923 case RID_UNDERLYING_TYPE
:
16924 type
= cp_parser_trait_expr (parser
, RID_UNDERLYING_TYPE
);
16926 cp_parser_set_decl_spec_type (decl_specs
, type
,
16928 /*type_definition_p=*/false);
16933 case RID_DIRECT_BASES
:
16934 type
= cp_parser_trait_expr (parser
, token
->keyword
);
16936 cp_parser_set_decl_spec_type (decl_specs
, type
,
16938 /*type_definition_p=*/false);
16944 /* If token is an already-parsed decltype not followed by ::,
16945 it's a simple-type-specifier. */
16946 if (token
->type
== CPP_DECLTYPE
16947 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
!= CPP_SCOPE
)
16949 type
= saved_checks_value (token
->u
.tree_check_value
);
16952 cp_parser_set_decl_spec_type (decl_specs
, type
,
16954 /*type_definition_p=*/false);
16955 /* Remember that we are handling a decltype in order to
16956 implement the resolution of DR 1510 when the argument
16957 isn't instantiation dependent. */
16958 decl_specs
->decltype_p
= true;
16960 cp_lexer_consume_token (parser
->lexer
);
16964 /* If the type-specifier was for a built-in type, we're done. */
16967 /* Record the type. */
16969 && (token
->keyword
!= RID_SIGNED
16970 && token
->keyword
!= RID_UNSIGNED
16971 && token
->keyword
!= RID_SHORT
16972 && token
->keyword
!= RID_LONG
))
16973 cp_parser_set_decl_spec_type (decl_specs
,
16976 /*type_definition_p=*/false);
16978 decl_specs
->any_specifiers_p
= true;
16980 /* Consume the token. */
16981 cp_lexer_consume_token (parser
->lexer
);
16983 if (type
== error_mark_node
)
16984 return error_mark_node
;
16986 /* There is no valid C++ program where a non-template type is
16987 followed by a "<". That usually indicates that the user thought
16988 that the type was a template. */
16989 cp_parser_check_for_invalid_template_id (parser
, type
, none_type
,
16992 return TYPE_NAME (type
);
16995 /* The type-specifier must be a user-defined type. */
16996 if (!(flags
& CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES
))
17001 /* Don't gobble tokens or issue error messages if this is an
17002 optional type-specifier. */
17003 if ((flags
& CP_PARSER_FLAGS_OPTIONAL
) || cxx_dialect
>= cxx1z
)
17004 cp_parser_parse_tentatively (parser
);
17006 token
= cp_lexer_peek_token (parser
->lexer
);
17008 /* Look for the optional `::' operator. */
17010 = (cp_parser_global_scope_opt (parser
,
17011 /*current_scope_valid_p=*/false)
17013 /* Look for the nested-name specifier. */
17015 = (cp_parser_nested_name_specifier_opt (parser
,
17016 /*typename_keyword_p=*/false,
17017 /*check_dependency_p=*/true,
17019 /*is_declaration=*/false)
17021 /* If we have seen a nested-name-specifier, and the next token
17022 is `template', then we are using the template-id production. */
17024 && cp_parser_optional_template_keyword (parser
))
17026 /* Look for the template-id. */
17027 type
= cp_parser_template_id (parser
,
17028 /*template_keyword_p=*/true,
17029 /*check_dependency_p=*/true,
17031 /*is_declaration=*/false);
17032 /* If the template-id did not name a type, we are out of
17034 if (TREE_CODE (type
) != TYPE_DECL
)
17036 cp_parser_error (parser
, "expected template-id for type");
17040 /* Otherwise, look for a type-name. */
17042 type
= cp_parser_type_name (parser
);
17043 /* Keep track of all name-lookups performed in class scopes. */
17047 && TREE_CODE (type
) == TYPE_DECL
17048 && identifier_p (DECL_NAME (type
)))
17049 maybe_note_name_used_in_class (DECL_NAME (type
), type
);
17050 /* If it didn't work out, we don't have a TYPE. */
17051 if (((flags
& CP_PARSER_FLAGS_OPTIONAL
) || cxx_dialect
>= cxx1z
)
17052 && !cp_parser_parse_definitely (parser
))
17054 if (!type
&& cxx_dialect
>= cxx1z
)
17056 if (flags
& CP_PARSER_FLAGS_OPTIONAL
)
17057 cp_parser_parse_tentatively (parser
);
17059 cp_parser_global_scope_opt (parser
,
17060 /*current_scope_valid_p=*/false);
17061 cp_parser_nested_name_specifier_opt (parser
,
17062 /*typename_keyword_p=*/false,
17063 /*check_dependency_p=*/true,
17065 /*is_declaration=*/false);
17066 tree name
= cp_parser_identifier (parser
);
17067 if (name
&& TREE_CODE (name
) == IDENTIFIER_NODE
17068 && parser
->scope
!= error_mark_node
)
17070 tree tmpl
= cp_parser_lookup_name (parser
, name
,
17072 /*is_template=*/false,
17073 /*is_namespace=*/false,
17074 /*check_dependency=*/true,
17075 /*ambiguous_decls=*/NULL
,
17077 if (tmpl
&& tmpl
!= error_mark_node
17078 && (DECL_CLASS_TEMPLATE_P (tmpl
)
17079 || DECL_TEMPLATE_TEMPLATE_PARM_P (tmpl
)))
17080 type
= make_template_placeholder (tmpl
);
17083 type
= error_mark_node
;
17084 if (!cp_parser_simulate_error (parser
))
17085 cp_parser_name_lookup_error (parser
, name
, tmpl
,
17086 NLE_TYPE
, token
->location
);
17090 type
= error_mark_node
;
17092 if ((flags
& CP_PARSER_FLAGS_OPTIONAL
)
17093 && !cp_parser_parse_definitely (parser
))
17096 if (type
&& decl_specs
)
17097 cp_parser_set_decl_spec_type (decl_specs
, type
,
17099 /*type_definition_p=*/false);
17102 /* If we didn't get a type-name, issue an error message. */
17103 if (!type
&& !(flags
& CP_PARSER_FLAGS_OPTIONAL
))
17105 cp_parser_error (parser
, "expected type-name");
17106 return error_mark_node
;
17109 if (type
&& type
!= error_mark_node
)
17111 /* See if TYPE is an Objective-C type, and if so, parse and
17112 accept any protocol references following it. Do this before
17113 the cp_parser_check_for_invalid_template_id() call, because
17114 Objective-C types can be followed by '<...>' which would
17115 enclose protocol names rather than template arguments, and so
17116 everything is fine. */
17117 if (c_dialect_objc () && !parser
->scope
17118 && (objc_is_id (type
) || objc_is_class_name (type
)))
17120 tree protos
= cp_parser_objc_protocol_refs_opt (parser
);
17121 tree qual_type
= objc_get_protocol_qualified_type (type
, protos
);
17123 /* Clobber the "unqualified" type previously entered into
17124 DECL_SPECS with the new, improved protocol-qualified version. */
17126 decl_specs
->type
= qual_type
;
17131 /* There is no valid C++ program where a non-template type is
17132 followed by a "<". That usually indicates that the user
17133 thought that the type was a template. */
17134 cp_parser_check_for_invalid_template_id (parser
, type
,
17142 /* Parse a type-name.
17148 simple-template-id [in c++0x]
17165 Returns a TYPE_DECL for the type. */
17168 cp_parser_type_name (cp_parser
* parser
)
17170 return cp_parser_type_name (parser
, /*typename_keyword_p=*/false);
17175 cp_parser_type_name (cp_parser
* parser
, bool typename_keyword_p
)
17179 /* We can't know yet whether it is a class-name or not. */
17180 cp_parser_parse_tentatively (parser
);
17181 /* Try a class-name. */
17182 type_decl
= cp_parser_class_name (parser
,
17183 typename_keyword_p
,
17184 /*template_keyword_p=*/false,
17186 /*check_dependency_p=*/true,
17187 /*class_head_p=*/false,
17188 /*is_declaration=*/false);
17189 /* If it's not a class-name, keep looking. */
17190 if (!cp_parser_parse_definitely (parser
))
17192 if (cxx_dialect
< cxx11
)
17193 /* It must be a typedef-name or an enum-name. */
17194 return cp_parser_nonclass_name (parser
);
17196 cp_parser_parse_tentatively (parser
);
17197 /* It is either a simple-template-id representing an
17198 instantiation of an alias template... */
17199 type_decl
= cp_parser_template_id (parser
,
17200 /*template_keyword_p=*/false,
17201 /*check_dependency_p=*/true,
17203 /*is_declaration=*/false);
17204 /* Note that this must be an instantiation of an alias template
17205 because [temp.names]/6 says:
17207 A template-id that names an alias template specialization
17210 Whereas [temp.names]/7 says:
17212 A simple-template-id that names a class template
17213 specialization is a class-name.
17215 With concepts, this could also be a partial-concept-id that
17216 declares a non-type template parameter. */
17217 if (type_decl
!= NULL_TREE
17218 && TREE_CODE (type_decl
) == TYPE_DECL
17219 && TYPE_DECL_ALIAS_P (type_decl
))
17220 gcc_assert (DECL_TEMPLATE_INSTANTIATION (type_decl
));
17221 else if (is_constrained_parameter (type_decl
))
17222 /* Don't do anything. */ ;
17224 cp_parser_simulate_error (parser
);
17226 if (!cp_parser_parse_definitely (parser
))
17227 /* ... Or a typedef-name or an enum-name. */
17228 return cp_parser_nonclass_name (parser
);
17234 /* Check if DECL and ARGS can form a constrained-type-specifier.
17235 If ARGS is non-null, we try to form a concept check of the
17236 form DECL<?, ARGS> where ? is a wildcard that matches any
17237 kind of template argument. If ARGS is NULL, then we try to
17238 form a concept check of the form DECL<?>. */
17241 cp_parser_maybe_constrained_type_specifier (cp_parser
*parser
,
17242 tree decl
, tree args
)
17244 gcc_assert (args
? TREE_CODE (args
) == TREE_VEC
: true);
17246 /* If we a constrained-type-specifier cannot be deduced. */
17247 if (parser
->prevent_constrained_type_specifiers
)
17250 /* A constrained type specifier can only be found in an
17251 overload set or as a reference to a template declaration.
17253 FIXME: This might be masking a bug. It's possible that
17254 that the deduction below is causing template specializations
17255 to be formed with the wildcard as an argument. */
17256 if (TREE_CODE (decl
) != OVERLOAD
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
17259 /* Try to build a call expression that evaluates the
17260 concept. This can fail if the overload set refers
17261 only to non-templates. */
17262 tree placeholder
= build_nt (WILDCARD_DECL
);
17263 tree check
= build_concept_check (decl
, placeholder
, args
);
17264 if (check
== error_mark_node
)
17267 /* Deduce the checked constraint and the prototype parameter.
17269 FIXME: In certain cases, failure to deduce should be a
17270 diagnosable error. */
17273 if (!deduce_constrained_parameter (check
, conc
, proto
))
17276 /* In template parameter scope, this results in a constrained
17277 parameter. Return a descriptor of that parm. */
17278 if (processing_template_parmlist
)
17279 return build_constrained_parameter (conc
, proto
, args
);
17281 /* In a parameter-declaration-clause, constrained-type
17282 specifiers result in invented template parameters. */
17283 if (parser
->auto_is_implicit_function_template_parm_p
)
17285 tree x
= build_constrained_parameter (conc
, proto
, args
);
17286 return synthesize_implicit_template_parm (parser
, x
);
17290 /* Otherwise, we're in a context where the constrained
17291 type name is deduced and the constraint applies
17292 after deduction. */
17293 return make_constrained_auto (conc
, args
);
17299 /* If DECL refers to a concept, return a TYPE_DECL representing
17300 the result of using the constrained type specifier in the
17301 current context. DECL refers to a concept if
17303 - it is an overload set containing a function concept taking a single
17306 - it is a variable concept taking a single type argument. */
17309 cp_parser_maybe_concept_name (cp_parser
* parser
, tree decl
)
17312 && (TREE_CODE (decl
) == OVERLOAD
17313 || BASELINK_P (decl
)
17314 || variable_concept_p (decl
)))
17315 return cp_parser_maybe_constrained_type_specifier (parser
, decl
, NULL_TREE
);
17320 /* Check if DECL and ARGS form a partial-concept-id. If so,
17321 assign ID to the resulting constrained placeholder.
17323 Returns true if the partial-concept-id designates a placeholder
17324 and false otherwise. Note that *id is set to NULL_TREE in
17328 cp_parser_maybe_partial_concept_id (cp_parser
*parser
, tree decl
, tree args
)
17330 return cp_parser_maybe_constrained_type_specifier (parser
, decl
, args
);
17333 /* Parse a non-class type-name, that is, either an enum-name, a typedef-name,
17345 Returns a TYPE_DECL for the type. */
17348 cp_parser_nonclass_name (cp_parser
* parser
)
17353 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
17354 identifier
= cp_parser_identifier (parser
);
17355 if (identifier
== error_mark_node
)
17356 return error_mark_node
;
17358 /* Look up the type-name. */
17359 type_decl
= cp_parser_lookup_name_simple (parser
, identifier
, token
->location
);
17361 type_decl
= strip_using_decl (type_decl
);
17363 /* If we found an overload set, then it may refer to a concept-name. */
17364 if (tree decl
= cp_parser_maybe_concept_name (parser
, type_decl
))
17367 if (TREE_CODE (type_decl
) != TYPE_DECL
17368 && (objc_is_id (identifier
) || objc_is_class_name (identifier
)))
17370 /* See if this is an Objective-C type. */
17371 tree protos
= cp_parser_objc_protocol_refs_opt (parser
);
17372 tree type
= objc_get_protocol_qualified_type (identifier
, protos
);
17374 type_decl
= TYPE_NAME (type
);
17377 /* Issue an error if we did not find a type-name. */
17378 if (TREE_CODE (type_decl
) != TYPE_DECL
17379 /* In Objective-C, we have the complication that class names are
17380 normally type names and start declarations (eg, the
17381 "NSObject" in "NSObject *object;"), but can be used in an
17382 Objective-C 2.0 dot-syntax (as in "NSObject.version") which
17383 is an expression. So, a classname followed by a dot is not a
17384 valid type-name. */
17385 || (objc_is_class_name (TREE_TYPE (type_decl
))
17386 && cp_lexer_peek_token (parser
->lexer
)->type
== CPP_DOT
))
17388 if (!cp_parser_simulate_error (parser
))
17389 cp_parser_name_lookup_error (parser
, identifier
, type_decl
,
17390 NLE_TYPE
, token
->location
);
17391 return error_mark_node
;
17393 /* Remember that the name was used in the definition of the
17394 current class so that we can check later to see if the
17395 meaning would have been different after the class was
17396 entirely defined. */
17397 else if (type_decl
!= error_mark_node
17399 maybe_note_name_used_in_class (identifier
, type_decl
);
17404 /* Parse an elaborated-type-specifier. Note that the grammar given
17405 here incorporates the resolution to DR68.
17407 elaborated-type-specifier:
17408 class-key :: [opt] nested-name-specifier [opt] identifier
17409 class-key :: [opt] nested-name-specifier [opt] template [opt] template-id
17410 enum-key :: [opt] nested-name-specifier [opt] identifier
17411 typename :: [opt] nested-name-specifier identifier
17412 typename :: [opt] nested-name-specifier template [opt]
17417 elaborated-type-specifier:
17418 class-key attributes :: [opt] nested-name-specifier [opt] identifier
17419 class-key attributes :: [opt] nested-name-specifier [opt]
17420 template [opt] template-id
17421 enum attributes :: [opt] nested-name-specifier [opt] identifier
17423 If IS_FRIEND is TRUE, then this elaborated-type-specifier is being
17424 declared `friend'. If IS_DECLARATION is TRUE, then this
17425 elaborated-type-specifier appears in a decl-specifiers-seq, i.e.,
17426 something is being declared.
17428 Returns the TYPE specified. */
17431 cp_parser_elaborated_type_specifier (cp_parser
* parser
,
17433 bool is_declaration
)
17435 enum tag_types tag_type
;
17437 tree type
= NULL_TREE
;
17438 tree attributes
= NULL_TREE
;
17440 cp_token
*token
= NULL
;
17442 /* See if we're looking at the `enum' keyword. */
17443 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_ENUM
))
17445 /* Consume the `enum' token. */
17446 cp_lexer_consume_token (parser
->lexer
);
17447 /* Remember that it's an enumeration type. */
17448 tag_type
= enum_type
;
17449 /* Issue a warning if the `struct' or `class' key (for C++0x scoped
17450 enums) is used here. */
17451 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
17452 if (cp_parser_is_keyword (token
, RID_CLASS
)
17453 || cp_parser_is_keyword (token
, RID_STRUCT
))
17455 gcc_rich_location
richloc (token
->location
);
17456 richloc
.add_range (input_location
, false);
17457 richloc
.add_fixit_remove ();
17458 pedwarn_at_rich_loc (&richloc
, 0, "elaborated-type-specifier for "
17459 "a scoped enum must not use the %qD keyword",
17461 /* Consume the `struct' or `class' and parse it anyway. */
17462 cp_lexer_consume_token (parser
->lexer
);
17464 /* Parse the attributes. */
17465 attributes
= cp_parser_attributes_opt (parser
);
17467 /* Or, it might be `typename'. */
17468 else if (cp_lexer_next_token_is_keyword (parser
->lexer
,
17471 /* Consume the `typename' token. */
17472 cp_lexer_consume_token (parser
->lexer
);
17473 /* Remember that it's a `typename' type. */
17474 tag_type
= typename_type
;
17476 /* Otherwise it must be a class-key. */
17479 tag_type
= cp_parser_class_key (parser
);
17480 if (tag_type
== none_type
)
17481 return error_mark_node
;
17482 /* Parse the attributes. */
17483 attributes
= cp_parser_attributes_opt (parser
);
17486 /* Look for the `::' operator. */
17487 globalscope
= cp_parser_global_scope_opt (parser
,
17488 /*current_scope_valid_p=*/false);
17489 /* Look for the nested-name-specifier. */
17490 tree nested_name_specifier
;
17491 if (tag_type
== typename_type
&& !globalscope
)
17493 nested_name_specifier
17494 = cp_parser_nested_name_specifier (parser
,
17495 /*typename_keyword_p=*/true,
17496 /*check_dependency_p=*/true,
17499 if (!nested_name_specifier
)
17500 return error_mark_node
;
17503 /* Even though `typename' is not present, the proposed resolution
17504 to Core Issue 180 says that in `class A<T>::B', `B' should be
17505 considered a type-name, even if `A<T>' is dependent. */
17506 nested_name_specifier
17507 = cp_parser_nested_name_specifier_opt (parser
,
17508 /*typename_keyword_p=*/true,
17509 /*check_dependency_p=*/true,
17512 /* For everything but enumeration types, consider a template-id.
17513 For an enumeration type, consider only a plain identifier. */
17514 if (tag_type
!= enum_type
)
17516 bool template_p
= false;
17519 /* Allow the `template' keyword. */
17520 template_p
= cp_parser_optional_template_keyword (parser
);
17521 /* If we didn't see `template', we don't know if there's a
17522 template-id or not. */
17524 cp_parser_parse_tentatively (parser
);
17525 /* Parse the template-id. */
17526 token
= cp_lexer_peek_token (parser
->lexer
);
17527 decl
= cp_parser_template_id (parser
, template_p
,
17528 /*check_dependency_p=*/true,
17531 /* If we didn't find a template-id, look for an ordinary
17533 if (!template_p
&& !cp_parser_parse_definitely (parser
))
17535 /* We can get here when cp_parser_template_id, called by
17536 cp_parser_class_name with tag_type == none_type, succeeds
17537 and caches a BASELINK. Then, when called again here,
17538 instead of failing and returning an error_mark_node
17539 returns it (see template/typename17.C in C++11).
17540 ??? Could we diagnose this earlier? */
17541 else if (tag_type
== typename_type
&& BASELINK_P (decl
))
17543 cp_parser_diagnose_invalid_type_name (parser
, decl
, token
->location
);
17544 type
= error_mark_node
;
17546 /* If DECL is a TEMPLATE_ID_EXPR, and the `typename' keyword is
17547 in effect, then we must assume that, upon instantiation, the
17548 template will correspond to a class. */
17549 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
17550 && tag_type
== typename_type
)
17551 type
= make_typename_type (parser
->scope
, decl
,
17553 /*complain=*/tf_error
);
17554 /* If the `typename' keyword is in effect and DECL is not a type
17555 decl, then type is non existent. */
17556 else if (tag_type
== typename_type
&& TREE_CODE (decl
) != TYPE_DECL
)
17558 else if (TREE_CODE (decl
) == TYPE_DECL
)
17560 type
= check_elaborated_type_specifier (tag_type
, decl
,
17561 /*allow_template_p=*/true);
17563 /* If the next token is a semicolon, this must be a specialization,
17564 instantiation, or friend declaration. Check the scope while we
17565 still know whether or not we had a nested-name-specifier. */
17566 if (type
!= error_mark_node
17567 && !nested_name_specifier
&& !is_friend
17568 && cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
17569 check_unqualified_spec_or_inst (type
, token
->location
);
17571 else if (decl
== error_mark_node
)
17572 type
= error_mark_node
;
17577 token
= cp_lexer_peek_token (parser
->lexer
);
17578 identifier
= cp_parser_identifier (parser
);
17580 if (identifier
== error_mark_node
)
17582 parser
->scope
= NULL_TREE
;
17583 return error_mark_node
;
17586 /* For a `typename', we needn't call xref_tag. */
17587 if (tag_type
== typename_type
17588 && TREE_CODE (parser
->scope
) != NAMESPACE_DECL
)
17589 return cp_parser_make_typename_type (parser
, identifier
,
17592 /* Template parameter lists apply only if we are not within a
17593 function parameter list. */
17594 bool template_parm_lists_apply
17595 = parser
->num_template_parameter_lists
;
17596 if (template_parm_lists_apply
)
17597 for (cp_binding_level
*s
= current_binding_level
;
17598 s
&& s
->kind
!= sk_template_parms
;
17599 s
= s
->level_chain
)
17600 if (s
->kind
== sk_function_parms
)
17601 template_parm_lists_apply
= false;
17603 /* Look up a qualified name in the usual way. */
17607 tree ambiguous_decls
;
17609 decl
= cp_parser_lookup_name (parser
, identifier
,
17611 /*is_template=*/false,
17612 /*is_namespace=*/false,
17613 /*check_dependency=*/true,
17617 /* If the lookup was ambiguous, an error will already have been
17619 if (ambiguous_decls
)
17620 return error_mark_node
;
17622 /* If we are parsing friend declaration, DECL may be a
17623 TEMPLATE_DECL tree node here. However, we need to check
17624 whether this TEMPLATE_DECL results in valid code. Consider
17625 the following example:
17628 template <class T> class C {};
17631 template <class T> friend class N::C; // #1, valid code
17633 template <class T> class Y {
17634 friend class N::C; // #2, invalid code
17637 For both case #1 and #2, we arrive at a TEMPLATE_DECL after
17638 name lookup of `N::C'. We see that friend declaration must
17639 be template for the code to be valid. Note that
17640 processing_template_decl does not work here since it is
17641 always 1 for the above two cases. */
17643 decl
= (cp_parser_maybe_treat_template_as_class
17644 (decl
, /*tag_name_p=*/is_friend
17645 && template_parm_lists_apply
));
17647 if (TREE_CODE (decl
) != TYPE_DECL
)
17649 cp_parser_diagnose_invalid_type_name (parser
,
17652 return error_mark_node
;
17655 if (TREE_CODE (TREE_TYPE (decl
)) != TYPENAME_TYPE
)
17657 bool allow_template
= (template_parm_lists_apply
17658 || DECL_SELF_REFERENCE_P (decl
));
17659 type
= check_elaborated_type_specifier (tag_type
, decl
,
17662 if (type
== error_mark_node
)
17663 return error_mark_node
;
17666 /* Forward declarations of nested types, such as
17671 are invalid unless all components preceding the final '::'
17672 are complete. If all enclosing types are complete, these
17673 declarations become merely pointless.
17675 Invalid forward declarations of nested types are errors
17676 caught elsewhere in parsing. Those that are pointless arrive
17679 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
)
17680 && !is_friend
&& !processing_explicit_instantiation
)
17681 warning (0, "declaration %qD does not declare anything", decl
);
17683 type
= TREE_TYPE (decl
);
17687 /* An elaborated-type-specifier sometimes introduces a new type and
17688 sometimes names an existing type. Normally, the rule is that it
17689 introduces a new type only if there is not an existing type of
17690 the same name already in scope. For example, given:
17693 void f() { struct S s; }
17695 the `struct S' in the body of `f' is the same `struct S' as in
17696 the global scope; the existing definition is used. However, if
17697 there were no global declaration, this would introduce a new
17698 local class named `S'.
17700 An exception to this rule applies to the following code:
17702 namespace N { struct S; }
17704 Here, the elaborated-type-specifier names a new type
17705 unconditionally; even if there is already an `S' in the
17706 containing scope this declaration names a new type.
17707 This exception only applies if the elaborated-type-specifier
17708 forms the complete declaration:
17712 A declaration consisting solely of `class-key identifier ;' is
17713 either a redeclaration of the name in the current scope or a
17714 forward declaration of the identifier as a class name. It
17715 introduces the name into the current scope.
17717 We are in this situation precisely when the next token is a `;'.
17719 An exception to the exception is that a `friend' declaration does
17720 *not* name a new type; i.e., given:
17722 struct S { friend struct T; };
17724 `T' is not a new type in the scope of `S'.
17726 Also, `new struct S' or `sizeof (struct S)' never results in the
17727 definition of a new type; a new type can only be declared in a
17728 declaration context. */
17734 /* Friends have special name lookup rules. */
17735 ts
= ts_within_enclosing_non_class
;
17736 else if (is_declaration
17737 && cp_lexer_next_token_is (parser
->lexer
,
17739 /* This is a `class-key identifier ;' */
17745 (template_parm_lists_apply
17746 && (cp_parser_next_token_starts_class_definition_p (parser
)
17747 || cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
)));
17748 /* An unqualified name was used to reference this type, so
17749 there were no qualifying templates. */
17750 if (template_parm_lists_apply
17751 && !cp_parser_check_template_parameters (parser
,
17752 /*num_templates=*/0,
17754 /*declarator=*/NULL
))
17755 return error_mark_node
;
17756 type
= xref_tag (tag_type
, identifier
, ts
, template_p
);
17760 if (type
== error_mark_node
)
17761 return error_mark_node
;
17763 /* Allow attributes on forward declarations of classes. */
17766 if (TREE_CODE (type
) == TYPENAME_TYPE
)
17767 warning (OPT_Wattributes
,
17768 "attributes ignored on uninstantiated type");
17769 else if (tag_type
!= enum_type
&& CLASSTYPE_TEMPLATE_INSTANTIATION (type
)
17770 && ! processing_explicit_instantiation
)
17771 warning (OPT_Wattributes
,
17772 "attributes ignored on template instantiation");
17773 else if (is_declaration
&& cp_parser_declares_only_class_p (parser
))
17774 cplus_decl_attributes (&type
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
17776 warning (OPT_Wattributes
,
17777 "attributes ignored on elaborated-type-specifier that is not a forward declaration");
17780 if (tag_type
!= enum_type
)
17782 /* Indicate whether this class was declared as a `class' or as a
17784 if (CLASS_TYPE_P (type
))
17785 CLASSTYPE_DECLARED_CLASS (type
) = (tag_type
== class_type
);
17786 cp_parser_check_class_key (tag_type
, type
);
17789 /* A "<" cannot follow an elaborated type specifier. If that
17790 happens, the user was probably trying to form a template-id. */
17791 cp_parser_check_for_invalid_template_id (parser
, type
, tag_type
,
17797 /* Parse an enum-specifier.
17800 enum-head { enumerator-list [opt] }
17801 enum-head { enumerator-list , } [C++0x]
17804 enum-key identifier [opt] enum-base [opt]
17805 enum-key nested-name-specifier identifier enum-base [opt]
17810 enum struct [C++0x]
17813 : type-specifier-seq
17815 opaque-enum-specifier:
17816 enum-key identifier enum-base [opt] ;
17819 enum-key attributes[opt] identifier [opt] enum-base [opt]
17820 { enumerator-list [opt] }attributes[opt]
17821 enum-key attributes[opt] identifier [opt] enum-base [opt]
17822 { enumerator-list, }attributes[opt] [C++0x]
17824 Returns an ENUM_TYPE representing the enumeration, or NULL_TREE
17825 if the token stream isn't an enum-specifier after all. */
17828 cp_parser_enum_specifier (cp_parser
* parser
)
17831 tree type
= NULL_TREE
;
17833 tree nested_name_specifier
= NULL_TREE
;
17835 bool scoped_enum_p
= false;
17836 bool has_underlying_type
= false;
17837 bool nested_being_defined
= false;
17838 bool new_value_list
= false;
17839 bool is_new_type
= false;
17840 bool is_unnamed
= false;
17841 tree underlying_type
= NULL_TREE
;
17842 cp_token
*type_start_token
= NULL
;
17843 bool saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
17845 parser
->colon_corrects_to_scope_p
= false;
17847 /* Parse tentatively so that we can back up if we don't find a
17849 cp_parser_parse_tentatively (parser
);
17851 /* Caller guarantees that the current token is 'enum', an identifier
17852 possibly follows, and the token after that is an opening brace.
17853 If we don't have an identifier, fabricate an anonymous name for
17854 the enumeration being defined. */
17855 cp_lexer_consume_token (parser
->lexer
);
17857 /* Parse the "class" or "struct", which indicates a scoped
17858 enumeration type in C++0x. */
17859 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_CLASS
)
17860 || cp_lexer_next_token_is_keyword (parser
->lexer
, RID_STRUCT
))
17862 if (cxx_dialect
< cxx11
)
17863 maybe_warn_cpp0x (CPP0X_SCOPED_ENUMS
);
17865 /* Consume the `struct' or `class' token. */
17866 cp_lexer_consume_token (parser
->lexer
);
17868 scoped_enum_p
= true;
17871 attributes
= cp_parser_attributes_opt (parser
);
17873 /* Clear the qualification. */
17874 parser
->scope
= NULL_TREE
;
17875 parser
->qualifying_scope
= NULL_TREE
;
17876 parser
->object_scope
= NULL_TREE
;
17878 /* Figure out in what scope the declaration is being placed. */
17879 prev_scope
= current_scope ();
17881 type_start_token
= cp_lexer_peek_token (parser
->lexer
);
17883 push_deferring_access_checks (dk_no_check
);
17884 nested_name_specifier
17885 = cp_parser_nested_name_specifier_opt (parser
,
17886 /*typename_keyword_p=*/true,
17887 /*check_dependency_p=*/false,
17889 /*is_declaration=*/false);
17891 if (nested_name_specifier
)
17895 identifier
= cp_parser_identifier (parser
);
17896 name
= cp_parser_lookup_name (parser
, identifier
,
17898 /*is_template=*/false,
17899 /*is_namespace=*/false,
17900 /*check_dependency=*/true,
17901 /*ambiguous_decls=*/NULL
,
17903 if (name
&& name
!= error_mark_node
)
17905 type
= TREE_TYPE (name
);
17906 if (TREE_CODE (type
) == TYPENAME_TYPE
)
17908 /* Are template enums allowed in ISO? */
17909 if (template_parm_scope_p ())
17910 pedwarn (type_start_token
->location
, OPT_Wpedantic
,
17911 "%qD is an enumeration template", name
);
17912 /* ignore a typename reference, for it will be solved by name
17917 else if (nested_name_specifier
== error_mark_node
)
17918 /* We already issued an error. */;
17921 error_at (type_start_token
->location
,
17922 "%qD does not name an enumeration in %qT",
17923 identifier
, nested_name_specifier
);
17924 nested_name_specifier
= error_mark_node
;
17929 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
17930 identifier
= cp_parser_identifier (parser
);
17933 identifier
= make_anon_name ();
17936 error_at (type_start_token
->location
,
17937 "unnamed scoped enum is not allowed");
17940 pop_deferring_access_checks ();
17942 /* Check for the `:' that denotes a specified underlying type in C++0x.
17943 Note that a ':' could also indicate a bitfield width, however. */
17944 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
17946 cp_decl_specifier_seq type_specifiers
;
17948 /* Consume the `:'. */
17949 cp_lexer_consume_token (parser
->lexer
);
17951 /* Parse the type-specifier-seq. */
17952 cp_parser_type_specifier_seq (parser
, /*is_declaration=*/false,
17953 /*is_trailing_return=*/false,
17956 /* At this point this is surely not elaborated type specifier. */
17957 if (!cp_parser_parse_definitely (parser
))
17960 if (cxx_dialect
< cxx11
)
17961 maybe_warn_cpp0x (CPP0X_SCOPED_ENUMS
);
17963 has_underlying_type
= true;
17965 /* If that didn't work, stop. */
17966 if (type_specifiers
.type
!= error_mark_node
)
17968 underlying_type
= grokdeclarator (NULL
, &type_specifiers
, TYPENAME
,
17969 /*initialized=*/0, NULL
);
17970 if (underlying_type
== error_mark_node
17971 || check_for_bare_parameter_packs (underlying_type
))
17972 underlying_type
= NULL_TREE
;
17976 /* Look for the `{' but don't consume it yet. */
17977 if (!cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
17979 if (cxx_dialect
< cxx11
|| (!scoped_enum_p
&& !underlying_type
))
17981 cp_parser_error (parser
, "expected %<{%>");
17982 if (has_underlying_type
)
17988 /* An opaque-enum-specifier must have a ';' here. */
17989 if ((scoped_enum_p
|| underlying_type
)
17990 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
17992 cp_parser_error (parser
, "expected %<;%> or %<{%>");
17993 if (has_underlying_type
)
18001 if (!has_underlying_type
&& !cp_parser_parse_definitely (parser
))
18004 if (nested_name_specifier
)
18006 if (CLASS_TYPE_P (nested_name_specifier
))
18008 nested_being_defined
= TYPE_BEING_DEFINED (nested_name_specifier
);
18009 TYPE_BEING_DEFINED (nested_name_specifier
) = 1;
18010 push_scope (nested_name_specifier
);
18012 else if (TREE_CODE (nested_name_specifier
) == NAMESPACE_DECL
)
18014 push_nested_namespace (nested_name_specifier
);
18018 /* Issue an error message if type-definitions are forbidden here. */
18019 if (!cp_parser_check_type_definition (parser
))
18020 type
= error_mark_node
;
18022 /* Create the new type. We do this before consuming the opening
18023 brace so the enum will be recorded as being on the line of its
18024 tag (or the 'enum' keyword, if there is no tag). */
18025 type
= start_enum (identifier
, type
, underlying_type
,
18026 attributes
, scoped_enum_p
, &is_new_type
);
18028 /* If the next token is not '{' it is an opaque-enum-specifier or an
18029 elaborated-type-specifier. */
18030 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
18032 timevar_push (TV_PARSE_ENUM
);
18033 if (nested_name_specifier
18034 && nested_name_specifier
!= error_mark_node
)
18036 /* The following catches invalid code such as:
18037 enum class S<int>::E { A, B, C }; */
18038 if (!processing_specialization
18039 && CLASS_TYPE_P (nested_name_specifier
)
18040 && CLASSTYPE_USE_TEMPLATE (nested_name_specifier
))
18041 error_at (type_start_token
->location
, "cannot add an enumerator "
18042 "list to a template instantiation");
18044 if (TREE_CODE (nested_name_specifier
) == TYPENAME_TYPE
)
18046 error_at (type_start_token
->location
,
18047 "%<%T::%E%> has not been declared",
18048 TYPE_CONTEXT (nested_name_specifier
),
18049 nested_name_specifier
);
18050 type
= error_mark_node
;
18052 else if (TREE_CODE (nested_name_specifier
) != NAMESPACE_DECL
18053 && !CLASS_TYPE_P (nested_name_specifier
))
18055 error_at (type_start_token
->location
, "nested name specifier "
18056 "%qT for enum declaration does not name a class "
18057 "or namespace", nested_name_specifier
);
18058 type
= error_mark_node
;
18060 /* If that scope does not contain the scope in which the
18061 class was originally declared, the program is invalid. */
18062 else if (prev_scope
&& !is_ancestor (prev_scope
,
18063 nested_name_specifier
))
18065 if (at_namespace_scope_p ())
18066 error_at (type_start_token
->location
,
18067 "declaration of %qD in namespace %qD which does not "
18069 type
, prev_scope
, nested_name_specifier
);
18071 error_at (type_start_token
->location
,
18072 "declaration of %qD in %qD which does not "
18074 type
, prev_scope
, nested_name_specifier
);
18075 type
= error_mark_node
;
18077 /* If that scope is the scope where the declaration is being placed
18078 the program is invalid. */
18079 else if (CLASS_TYPE_P (nested_name_specifier
)
18080 && CLASS_TYPE_P (prev_scope
)
18081 && same_type_p (nested_name_specifier
, prev_scope
))
18083 permerror (type_start_token
->location
,
18084 "extra qualification not allowed");
18085 nested_name_specifier
= NULL_TREE
;
18090 begin_scope (sk_scoped_enum
, type
);
18092 /* Consume the opening brace. */
18093 cp_lexer_consume_token (parser
->lexer
);
18095 if (type
== error_mark_node
)
18096 ; /* Nothing to add */
18097 else if (OPAQUE_ENUM_P (type
)
18098 || (cxx_dialect
> cxx98
&& processing_specialization
))
18100 new_value_list
= true;
18101 SET_OPAQUE_ENUM_P (type
, false);
18102 DECL_SOURCE_LOCATION (TYPE_NAME (type
)) = type_start_token
->location
;
18106 error_at (type_start_token
->location
,
18107 "multiple definition of %q#T", type
);
18108 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type
)),
18109 "previous definition here");
18110 type
= error_mark_node
;
18113 if (type
== error_mark_node
)
18114 cp_parser_skip_to_end_of_block_or_statement (parser
);
18115 /* If the next token is not '}', then there are some enumerators. */
18116 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_BRACE
))
18118 if (is_unnamed
&& !scoped_enum_p
)
18119 pedwarn (type_start_token
->location
, OPT_Wpedantic
,
18120 "ISO C++ forbids empty unnamed enum");
18123 cp_parser_enumerator_list (parser
, type
);
18125 /* Consume the final '}'. */
18126 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
18130 timevar_pop (TV_PARSE_ENUM
);
18134 /* If a ';' follows, then it is an opaque-enum-specifier
18135 and additional restrictions apply. */
18136 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
18139 error_at (type_start_token
->location
,
18140 "opaque-enum-specifier without name");
18141 else if (nested_name_specifier
)
18142 error_at (type_start_token
->location
,
18143 "opaque-enum-specifier must use a simple identifier");
18147 /* Look for trailing attributes to apply to this enumeration, and
18148 apply them if appropriate. */
18149 if (cp_parser_allow_gnu_extensions_p (parser
))
18151 tree trailing_attr
= cp_parser_gnu_attributes_opt (parser
);
18152 cplus_decl_attributes (&type
,
18154 (int) ATTR_FLAG_TYPE_IN_PLACE
);
18157 /* Finish up the enumeration. */
18158 if (type
!= error_mark_node
)
18160 if (new_value_list
)
18161 finish_enum_value_list (type
);
18163 finish_enum (type
);
18166 if (nested_name_specifier
)
18168 if (CLASS_TYPE_P (nested_name_specifier
))
18170 TYPE_BEING_DEFINED (nested_name_specifier
) = nested_being_defined
;
18171 pop_scope (nested_name_specifier
);
18173 else if (TREE_CODE (nested_name_specifier
) == NAMESPACE_DECL
)
18175 pop_nested_namespace (nested_name_specifier
);
18179 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
18183 /* Parse an enumerator-list. The enumerators all have the indicated
18187 enumerator-definition
18188 enumerator-list , enumerator-definition */
18191 cp_parser_enumerator_list (cp_parser
* parser
, tree type
)
18195 /* Parse an enumerator-definition. */
18196 cp_parser_enumerator_definition (parser
, type
);
18198 /* If the next token is not a ',', we've reached the end of
18200 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
18202 /* Otherwise, consume the `,' and keep going. */
18203 cp_lexer_consume_token (parser
->lexer
);
18204 /* If the next token is a `}', there is a trailing comma. */
18205 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_BRACE
))
18207 if (cxx_dialect
< cxx11
&& !in_system_header_at (input_location
))
18208 pedwarn (input_location
, OPT_Wpedantic
,
18209 "comma at end of enumerator list");
18215 /* Parse an enumerator-definition. The enumerator has the indicated
18218 enumerator-definition:
18220 enumerator = constant-expression
18227 enumerator-definition:
18228 enumerator attributes [opt]
18229 enumerator attributes [opt] = constant-expression */
18232 cp_parser_enumerator_definition (cp_parser
* parser
, tree type
)
18238 /* Save the input location because we are interested in the location
18239 of the identifier and not the location of the explicit value. */
18240 loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
18242 /* Look for the identifier. */
18243 identifier
= cp_parser_identifier (parser
);
18244 if (identifier
== error_mark_node
)
18247 /* Parse any specified attributes. */
18248 tree attrs
= cp_parser_attributes_opt (parser
);
18250 /* If the next token is an '=', then there is an explicit value. */
18251 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
))
18253 /* Consume the `=' token. */
18254 cp_lexer_consume_token (parser
->lexer
);
18255 /* Parse the value. */
18256 value
= cp_parser_constant_expression (parser
);
18261 /* If we are processing a template, make sure the initializer of the
18262 enumerator doesn't contain any bare template parameter pack. */
18263 if (check_for_bare_parameter_packs (value
))
18264 value
= error_mark_node
;
18266 /* Create the enumerator. */
18267 build_enumerator (identifier
, value
, type
, attrs
, loc
);
18270 /* Parse a namespace-name.
18273 original-namespace-name
18276 Returns the NAMESPACE_DECL for the namespace. */
18279 cp_parser_namespace_name (cp_parser
* parser
)
18282 tree namespace_decl
;
18284 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
18286 /* Get the name of the namespace. */
18287 identifier
= cp_parser_identifier (parser
);
18288 if (identifier
== error_mark_node
)
18289 return error_mark_node
;
18291 /* Look up the identifier in the currently active scope. Look only
18292 for namespaces, due to:
18294 [basic.lookup.udir]
18296 When looking up a namespace-name in a using-directive or alias
18297 definition, only namespace names are considered.
18301 [basic.lookup.qual]
18303 During the lookup of a name preceding the :: scope resolution
18304 operator, object, function, and enumerator names are ignored.
18306 (Note that cp_parser_qualifying_entity only calls this
18307 function if the token after the name is the scope resolution
18309 namespace_decl
= cp_parser_lookup_name (parser
, identifier
,
18311 /*is_template=*/false,
18312 /*is_namespace=*/true,
18313 /*check_dependency=*/true,
18314 /*ambiguous_decls=*/NULL
,
18316 /* If it's not a namespace, issue an error. */
18317 if (namespace_decl
== error_mark_node
18318 || TREE_CODE (namespace_decl
) != NAMESPACE_DECL
)
18320 if (!cp_parser_uncommitted_to_tentative_parse_p (parser
))
18321 error_at (token
->location
, "%qD is not a namespace-name", identifier
);
18322 cp_parser_error (parser
, "expected namespace-name");
18323 namespace_decl
= error_mark_node
;
18326 return namespace_decl
;
18329 /* Parse a namespace-definition.
18331 namespace-definition:
18332 named-namespace-definition
18333 unnamed-namespace-definition
18335 named-namespace-definition:
18336 original-namespace-definition
18337 extension-namespace-definition
18339 original-namespace-definition:
18340 namespace identifier { namespace-body }
18342 extension-namespace-definition:
18343 namespace original-namespace-name { namespace-body }
18345 unnamed-namespace-definition:
18346 namespace { namespace-body } */
18349 cp_parser_namespace_definition (cp_parser
* parser
)
18352 int nested_definition_count
= 0;
18354 cp_ensure_no_omp_declare_simd (parser
);
18355 cp_ensure_no_oacc_routine (parser
);
18357 bool is_inline
= cp_lexer_next_token_is_keyword (parser
->lexer
, RID_INLINE
);
18361 maybe_warn_cpp0x (CPP0X_INLINE_NAMESPACES
);
18362 cp_lexer_consume_token (parser
->lexer
);
18365 /* Look for the `namespace' keyword. */
18367 = cp_parser_require_keyword (parser
, RID_NAMESPACE
, RT_NAMESPACE
);
18369 /* Parse any specified attributes before the identifier. */
18370 tree attribs
= cp_parser_attributes_opt (parser
);
18374 identifier
= NULL_TREE
;
18376 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
18378 identifier
= cp_parser_identifier (parser
);
18380 /* Parse any attributes specified after the identifier. */
18381 attribs
= chainon (attribs
, cp_parser_attributes_opt (parser
));
18384 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SCOPE
))
18387 if (!nested_definition_count
&& cxx_dialect
< cxx1z
)
18388 pedwarn (input_location
, OPT_Wpedantic
,
18389 "nested namespace definitions only available with "
18390 "-std=c++1z or -std=gnu++1z");
18392 /* Nested namespace names can create new namespaces (unlike
18393 other qualified-ids). */
18394 if (int count
= identifier
? push_namespace (identifier
) : 0)
18395 nested_definition_count
+= count
;
18397 cp_parser_error (parser
, "nested namespace name required");
18398 cp_lexer_consume_token (parser
->lexer
);
18401 if (nested_definition_count
&& !identifier
)
18402 cp_parser_error (parser
, "namespace name required");
18404 if (nested_definition_count
&& attribs
)
18405 error_at (token
->location
,
18406 "a nested namespace definition cannot have attributes");
18407 if (nested_definition_count
&& is_inline
)
18408 error_at (token
->location
,
18409 "a nested namespace definition cannot be inline");
18411 /* Start the namespace. */
18412 nested_definition_count
+= push_namespace (identifier
, is_inline
);
18414 bool has_visibility
= handle_namespace_attrs (current_namespace
, attribs
);
18416 warning (OPT_Wnamespaces
, "namespace %qD entered", current_namespace
);
18418 /* Look for the `{' to validate starting the namespace. */
18419 if (cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
))
18421 /* Parse the body of the namespace. */
18422 cp_parser_namespace_body (parser
);
18424 /* Look for the final `}'. */
18425 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
18428 if (has_visibility
)
18429 pop_visibility (1);
18431 /* Pop the nested namespace definitions. */
18432 while (nested_definition_count
--)
18436 /* Parse a namespace-body.
18439 declaration-seq [opt] */
18442 cp_parser_namespace_body (cp_parser
* parser
)
18444 cp_parser_declaration_seq_opt (parser
);
18447 /* Parse a namespace-alias-definition.
18449 namespace-alias-definition:
18450 namespace identifier = qualified-namespace-specifier ; */
18453 cp_parser_namespace_alias_definition (cp_parser
* parser
)
18456 tree namespace_specifier
;
18458 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
18460 /* Look for the `namespace' keyword. */
18461 cp_parser_require_keyword (parser
, RID_NAMESPACE
, RT_NAMESPACE
);
18462 /* Look for the identifier. */
18463 identifier
= cp_parser_identifier (parser
);
18464 if (identifier
== error_mark_node
)
18466 /* Look for the `=' token. */
18467 if (!cp_parser_uncommitted_to_tentative_parse_p (parser
)
18468 && cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
18470 error_at (token
->location
, "%<namespace%> definition is not allowed here");
18471 /* Skip the definition. */
18472 cp_lexer_consume_token (parser
->lexer
);
18473 if (cp_parser_skip_to_closing_brace (parser
))
18474 cp_lexer_consume_token (parser
->lexer
);
18477 cp_parser_require (parser
, CPP_EQ
, RT_EQ
);
18478 /* Look for the qualified-namespace-specifier. */
18479 namespace_specifier
18480 = cp_parser_qualified_namespace_specifier (parser
);
18481 /* Look for the `;' token. */
18482 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
18484 /* Register the alias in the symbol table. */
18485 do_namespace_alias (identifier
, namespace_specifier
);
18488 /* Parse a qualified-namespace-specifier.
18490 qualified-namespace-specifier:
18491 :: [opt] nested-name-specifier [opt] namespace-name
18493 Returns a NAMESPACE_DECL corresponding to the specified
18497 cp_parser_qualified_namespace_specifier (cp_parser
* parser
)
18499 /* Look for the optional `::'. */
18500 cp_parser_global_scope_opt (parser
,
18501 /*current_scope_valid_p=*/false);
18503 /* Look for the optional nested-name-specifier. */
18504 cp_parser_nested_name_specifier_opt (parser
,
18505 /*typename_keyword_p=*/false,
18506 /*check_dependency_p=*/true,
18508 /*is_declaration=*/true);
18510 return cp_parser_namespace_name (parser
);
18513 /* Parse a using-declaration, or, if ACCESS_DECLARATION_P is true, an
18514 access declaration.
18517 using typename [opt] :: [opt] nested-name-specifier unqualified-id ;
18518 using :: unqualified-id ;
18520 access-declaration:
18526 cp_parser_using_declaration (cp_parser
* parser
,
18527 bool access_declaration_p
)
18530 bool typename_p
= false;
18531 bool global_scope_p
;
18535 int oldcount
= errorcount
;
18536 cp_token
*diag_token
= NULL
;
18538 if (access_declaration_p
)
18540 diag_token
= cp_lexer_peek_token (parser
->lexer
);
18541 cp_parser_parse_tentatively (parser
);
18545 /* Look for the `using' keyword. */
18546 cp_parser_require_keyword (parser
, RID_USING
, RT_USING
);
18549 /* Peek at the next token. */
18550 token
= cp_lexer_peek_token (parser
->lexer
);
18551 /* See if it's `typename'. */
18552 if (token
->keyword
== RID_TYPENAME
)
18554 /* Remember that we've seen it. */
18556 /* Consume the `typename' token. */
18557 cp_lexer_consume_token (parser
->lexer
);
18561 /* Look for the optional global scope qualification. */
18563 = (cp_parser_global_scope_opt (parser
,
18564 /*current_scope_valid_p=*/false)
18567 /* If we saw `typename', or didn't see `::', then there must be a
18568 nested-name-specifier present. */
18569 if (typename_p
|| !global_scope_p
)
18571 qscope
= cp_parser_nested_name_specifier (parser
, typename_p
,
18572 /*check_dependency_p=*/true,
18574 /*is_declaration=*/true);
18575 if (!qscope
&& !cp_parser_uncommitted_to_tentative_parse_p (parser
))
18577 cp_parser_skip_to_end_of_block_or_statement (parser
);
18581 /* Otherwise, we could be in either of the two productions. In that
18582 case, treat the nested-name-specifier as optional. */
18584 qscope
= cp_parser_nested_name_specifier_opt (parser
,
18585 /*typename_keyword_p=*/false,
18586 /*check_dependency_p=*/true,
18588 /*is_declaration=*/true);
18590 qscope
= global_namespace
;
18591 else if (UNSCOPED_ENUM_P (qscope
))
18592 qscope
= CP_TYPE_CONTEXT (qscope
);
18594 if (access_declaration_p
&& cp_parser_error_occurred (parser
))
18595 /* Something has already gone wrong; there's no need to parse
18596 further. Since an error has occurred, the return value of
18597 cp_parser_parse_definitely will be false, as required. */
18598 return cp_parser_parse_definitely (parser
);
18600 token
= cp_lexer_peek_token (parser
->lexer
);
18601 /* Parse the unqualified-id. */
18602 identifier
= cp_parser_unqualified_id (parser
,
18603 /*template_keyword_p=*/false,
18604 /*check_dependency_p=*/true,
18605 /*declarator_p=*/true,
18606 /*optional_p=*/false);
18608 if (access_declaration_p
)
18610 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
18611 cp_parser_simulate_error (parser
);
18612 if (!cp_parser_parse_definitely (parser
))
18615 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
18617 cp_token
*ell
= cp_lexer_consume_token (parser
->lexer
);
18618 if (cxx_dialect
< cxx1z
18619 && !in_system_header_at (ell
->location
))
18620 pedwarn (ell
->location
, 0,
18621 "pack expansion in using-declaration only available "
18622 "with -std=c++1z or -std=gnu++1z");
18623 qscope
= make_pack_expansion (qscope
);
18626 /* The function we call to handle a using-declaration is different
18627 depending on what scope we are in. */
18628 if (qscope
== error_mark_node
|| identifier
== error_mark_node
)
18630 else if (!identifier_p (identifier
)
18631 && TREE_CODE (identifier
) != BIT_NOT_EXPR
)
18632 /* [namespace.udecl]
18634 A using declaration shall not name a template-id. */
18635 error_at (token
->location
,
18636 "a template-id may not appear in a using-declaration");
18639 if (at_class_scope_p ())
18641 /* Create the USING_DECL. */
18642 decl
= do_class_using_decl (qscope
, identifier
);
18644 if (decl
&& typename_p
)
18645 USING_DECL_TYPENAME_P (decl
) = 1;
18647 if (check_for_bare_parameter_packs (decl
))
18649 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
18653 /* Add it to the list of members in this class. */
18654 finish_member_declaration (decl
);
18658 decl
= cp_parser_lookup_name_simple (parser
,
18661 if (decl
== error_mark_node
)
18662 cp_parser_name_lookup_error (parser
, identifier
,
18665 else if (check_for_bare_parameter_packs (decl
))
18667 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
18670 else if (!at_namespace_scope_p ())
18671 finish_local_using_decl (decl
, qscope
, identifier
);
18673 finish_namespace_using_decl (decl
, qscope
, identifier
);
18677 if (!access_declaration_p
18678 && cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
18680 cp_token
*comma
= cp_lexer_consume_token (parser
->lexer
);
18681 if (cxx_dialect
< cxx1z
)
18682 pedwarn (comma
->location
, 0,
18683 "comma-separated list in using-declaration only available "
18684 "with -std=c++1z or -std=gnu++1z");
18688 /* Look for the final `;'. */
18689 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
18691 if (access_declaration_p
&& errorcount
== oldcount
)
18692 warning_at (diag_token
->location
, OPT_Wdeprecated
,
18693 "access declarations are deprecated "
18694 "in favour of using-declarations; "
18695 "suggestion: add the %<using%> keyword");
18700 /* Parse an alias-declaration.
18703 using identifier attribute-specifier-seq [opt] = type-id */
18706 cp_parser_alias_declaration (cp_parser
* parser
)
18708 tree id
, type
, decl
, pushed_scope
= NULL_TREE
, attributes
;
18709 location_t id_location
;
18710 cp_declarator
*declarator
;
18711 cp_decl_specifier_seq decl_specs
;
18713 const char *saved_message
= NULL
;
18715 /* Look for the `using' keyword. */
18716 cp_token
*using_token
18717 = cp_parser_require_keyword (parser
, RID_USING
, RT_USING
);
18718 if (using_token
== NULL
)
18719 return error_mark_node
;
18721 id_location
= cp_lexer_peek_token (parser
->lexer
)->location
;
18722 id
= cp_parser_identifier (parser
);
18723 if (id
== error_mark_node
)
18724 return error_mark_node
;
18726 cp_token
*attrs_token
= cp_lexer_peek_token (parser
->lexer
);
18727 attributes
= cp_parser_attributes_opt (parser
);
18728 if (attributes
== error_mark_node
)
18729 return error_mark_node
;
18731 cp_parser_require (parser
, CPP_EQ
, RT_EQ
);
18733 if (cp_parser_error_occurred (parser
))
18734 return error_mark_node
;
18736 cp_parser_commit_to_tentative_parse (parser
);
18738 /* Now we are going to parse the type-id of the declaration. */
18743 "A type-specifier-seq shall not define a class or enumeration
18744 unless it appears in the type-id of an alias-declaration (7.1.3) that
18745 is not the declaration of a template-declaration."
18747 In other words, if we currently are in an alias template, the
18748 type-id should not define a type.
18750 So let's set parser->type_definition_forbidden_message in that
18751 case; cp_parser_check_type_definition (called by
18752 cp_parser_class_specifier) will then emit an error if a type is
18753 defined in the type-id. */
18754 if (parser
->num_template_parameter_lists
)
18756 saved_message
= parser
->type_definition_forbidden_message
;
18757 parser
->type_definition_forbidden_message
=
18758 G_("types may not be defined in alias template declarations");
18761 type
= cp_parser_type_id (parser
);
18763 /* Restore the error message if need be. */
18764 if (parser
->num_template_parameter_lists
)
18765 parser
->type_definition_forbidden_message
= saved_message
;
18767 if (type
== error_mark_node
18768 || !cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
))
18770 cp_parser_skip_to_end_of_block_or_statement (parser
);
18771 return error_mark_node
;
18774 /* A typedef-name can also be introduced by an alias-declaration. The
18775 identifier following the using keyword becomes a typedef-name. It has
18776 the same semantics as if it were introduced by the typedef
18777 specifier. In particular, it does not define a new type and it shall
18778 not appear in the type-id. */
18780 clear_decl_specs (&decl_specs
);
18781 decl_specs
.type
= type
;
18782 if (attributes
!= NULL_TREE
)
18784 decl_specs
.attributes
= attributes
;
18785 set_and_check_decl_spec_loc (&decl_specs
,
18789 set_and_check_decl_spec_loc (&decl_specs
,
18792 set_and_check_decl_spec_loc (&decl_specs
,
18796 declarator
= make_id_declarator (NULL_TREE
, id
, sfk_none
);
18797 declarator
->id_loc
= id_location
;
18799 member_p
= at_class_scope_p ();
18801 decl
= grokfield (declarator
, &decl_specs
, NULL_TREE
, false,
18802 NULL_TREE
, attributes
);
18804 decl
= start_decl (declarator
, &decl_specs
, 0,
18805 attributes
, NULL_TREE
, &pushed_scope
);
18806 if (decl
== error_mark_node
)
18809 // Attach constraints to the alias declaration.
18810 if (flag_concepts
&& current_template_parms
)
18812 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
18813 tree constr
= build_constraints (reqs
, NULL_TREE
);
18814 set_constraints (decl
, constr
);
18817 cp_finish_decl (decl
, NULL_TREE
, 0, NULL_TREE
, 0);
18820 pop_scope (pushed_scope
);
18822 /* If decl is a template, return its TEMPLATE_DECL so that it gets
18823 added into the symbol table; otherwise, return the TYPE_DECL. */
18824 if (DECL_LANG_SPECIFIC (decl
)
18825 && DECL_TEMPLATE_INFO (decl
)
18826 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl
)))
18828 decl
= DECL_TI_TEMPLATE (decl
);
18830 check_member_template (decl
);
18836 /* Parse a using-directive.
18839 using namespace :: [opt] nested-name-specifier [opt]
18840 namespace-name ; */
18843 cp_parser_using_directive (cp_parser
* parser
)
18845 tree namespace_decl
;
18848 /* Look for the `using' keyword. */
18849 cp_parser_require_keyword (parser
, RID_USING
, RT_USING
);
18850 /* And the `namespace' keyword. */
18851 cp_parser_require_keyword (parser
, RID_NAMESPACE
, RT_NAMESPACE
);
18852 /* Look for the optional `::' operator. */
18853 cp_parser_global_scope_opt (parser
, /*current_scope_valid_p=*/false);
18854 /* And the optional nested-name-specifier. */
18855 cp_parser_nested_name_specifier_opt (parser
,
18856 /*typename_keyword_p=*/false,
18857 /*check_dependency_p=*/true,
18859 /*is_declaration=*/true);
18860 /* Get the namespace being used. */
18861 namespace_decl
= cp_parser_namespace_name (parser
);
18862 /* And any specified attributes. */
18863 attribs
= cp_parser_attributes_opt (parser
);
18865 /* Update the symbol table. */
18866 if (namespace_bindings_p ())
18867 finish_namespace_using_directive (namespace_decl
, attribs
);
18869 finish_local_using_directive (namespace_decl
, attribs
);
18871 /* Look for the final `;'. */
18872 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
18875 /* Parse an asm-definition.
18878 asm ( string-literal ) ;
18883 asm volatile [opt] ( string-literal ) ;
18884 asm volatile [opt] ( string-literal : asm-operand-list [opt] ) ;
18885 asm volatile [opt] ( string-literal : asm-operand-list [opt]
18886 : asm-operand-list [opt] ) ;
18887 asm volatile [opt] ( string-literal : asm-operand-list [opt]
18888 : asm-operand-list [opt]
18889 : asm-clobber-list [opt] ) ;
18890 asm volatile [opt] goto ( string-literal : : asm-operand-list [opt]
18891 : asm-clobber-list [opt]
18892 : asm-goto-list ) ; */
18895 cp_parser_asm_definition (cp_parser
* parser
)
18898 tree outputs
= NULL_TREE
;
18899 tree inputs
= NULL_TREE
;
18900 tree clobbers
= NULL_TREE
;
18901 tree labels
= NULL_TREE
;
18903 bool volatile_p
= false;
18904 bool extended_p
= false;
18905 bool invalid_inputs_p
= false;
18906 bool invalid_outputs_p
= false;
18907 bool goto_p
= false;
18908 required_token missing
= RT_NONE
;
18910 /* Look for the `asm' keyword. */
18911 cp_parser_require_keyword (parser
, RID_ASM
, RT_ASM
);
18913 if (parser
->in_function_body
18914 && DECL_DECLARED_CONSTEXPR_P (current_function_decl
))
18916 error ("%<asm%> in %<constexpr%> function");
18917 cp_function_chain
->invalid_constexpr
= true;
18920 /* See if the next token is `volatile'. */
18921 if (cp_parser_allow_gnu_extensions_p (parser
)
18922 && cp_lexer_next_token_is_keyword (parser
->lexer
, RID_VOLATILE
))
18924 /* Remember that we saw the `volatile' keyword. */
18926 /* Consume the token. */
18927 cp_lexer_consume_token (parser
->lexer
);
18929 if (cp_parser_allow_gnu_extensions_p (parser
)
18930 && parser
->in_function_body
18931 && cp_lexer_next_token_is_keyword (parser
->lexer
, RID_GOTO
))
18933 /* Remember that we saw the `goto' keyword. */
18935 /* Consume the token. */
18936 cp_lexer_consume_token (parser
->lexer
);
18938 /* Look for the opening `('. */
18939 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
18941 /* Look for the string. */
18942 string
= cp_parser_string_literal (parser
, false, false);
18943 if (string
== error_mark_node
)
18945 cp_parser_skip_to_closing_parenthesis (parser
, true, false,
18946 /*consume_paren=*/true);
18950 /* If we're allowing GNU extensions, check for the extended assembly
18951 syntax. Unfortunately, the `:' tokens need not be separated by
18952 a space in C, and so, for compatibility, we tolerate that here
18953 too. Doing that means that we have to treat the `::' operator as
18955 if (cp_parser_allow_gnu_extensions_p (parser
)
18956 && parser
->in_function_body
18957 && (cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
)
18958 || cp_lexer_next_token_is (parser
->lexer
, CPP_SCOPE
)))
18960 bool inputs_p
= false;
18961 bool clobbers_p
= false;
18962 bool labels_p
= false;
18964 /* The extended syntax was used. */
18967 /* Look for outputs. */
18968 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
18970 /* Consume the `:'. */
18971 cp_lexer_consume_token (parser
->lexer
);
18972 /* Parse the output-operands. */
18973 if (cp_lexer_next_token_is_not (parser
->lexer
,
18975 && cp_lexer_next_token_is_not (parser
->lexer
,
18977 && cp_lexer_next_token_is_not (parser
->lexer
,
18981 outputs
= cp_parser_asm_operand_list (parser
);
18982 if (outputs
== error_mark_node
)
18983 invalid_outputs_p
= true;
18986 /* If the next token is `::', there are no outputs, and the
18987 next token is the beginning of the inputs. */
18988 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_SCOPE
))
18989 /* The inputs are coming next. */
18992 /* Look for inputs. */
18994 || cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
18996 /* Consume the `:' or `::'. */
18997 cp_lexer_consume_token (parser
->lexer
);
18998 /* Parse the output-operands. */
18999 if (cp_lexer_next_token_is_not (parser
->lexer
,
19001 && cp_lexer_next_token_is_not (parser
->lexer
,
19003 && cp_lexer_next_token_is_not (parser
->lexer
,
19006 inputs
= cp_parser_asm_operand_list (parser
);
19007 if (inputs
== error_mark_node
)
19008 invalid_inputs_p
= true;
19011 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_SCOPE
))
19012 /* The clobbers are coming next. */
19015 /* Look for clobbers. */
19017 || cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
19020 /* Consume the `:' or `::'. */
19021 cp_lexer_consume_token (parser
->lexer
);
19022 /* Parse the clobbers. */
19023 if (cp_lexer_next_token_is_not (parser
->lexer
,
19025 && cp_lexer_next_token_is_not (parser
->lexer
,
19027 clobbers
= cp_parser_asm_clobber_list (parser
);
19030 && cp_lexer_next_token_is (parser
->lexer
, CPP_SCOPE
))
19031 /* The labels are coming next. */
19034 /* Look for labels. */
19036 || (goto_p
&& cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
)))
19039 /* Consume the `:' or `::'. */
19040 cp_lexer_consume_token (parser
->lexer
);
19041 /* Parse the labels. */
19042 labels
= cp_parser_asm_label_list (parser
);
19045 if (goto_p
&& !labels_p
)
19046 missing
= clobbers_p
? RT_COLON
: RT_COLON_SCOPE
;
19049 missing
= RT_COLON_SCOPE
;
19051 /* Look for the closing `)'. */
19052 if (!cp_parser_require (parser
, missing
? CPP_COLON
: CPP_CLOSE_PAREN
,
19053 missing
? missing
: RT_CLOSE_PAREN
))
19054 cp_parser_skip_to_closing_parenthesis (parser
, true, false,
19055 /*consume_paren=*/true);
19056 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
19058 if (!invalid_inputs_p
&& !invalid_outputs_p
)
19060 /* Create the ASM_EXPR. */
19061 if (parser
->in_function_body
)
19063 asm_stmt
= finish_asm_stmt (volatile_p
, string
, outputs
,
19064 inputs
, clobbers
, labels
);
19065 /* If the extended syntax was not used, mark the ASM_EXPR. */
19068 tree temp
= asm_stmt
;
19069 if (TREE_CODE (temp
) == CLEANUP_POINT_EXPR
)
19070 temp
= TREE_OPERAND (temp
, 0);
19072 ASM_INPUT_P (temp
) = 1;
19076 symtab
->finalize_toplevel_asm (string
);
19080 /* Given the type TYPE of a declaration with declarator DECLARATOR, return the
19081 type that comes from the decl-specifier-seq. */
19084 strip_declarator_types (tree type
, cp_declarator
*declarator
)
19086 for (cp_declarator
*d
= declarator
; d
;)
19096 if (TYPE_PTRMEMFUNC_P (type
))
19097 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
19098 type
= TREE_TYPE (type
);
19106 /* Declarators [gram.dcl.decl] */
19108 /* Parse an init-declarator.
19111 declarator initializer [opt]
19116 declarator asm-specification [opt] attributes [opt] initializer [opt]
19118 function-definition:
19119 decl-specifier-seq [opt] declarator ctor-initializer [opt]
19121 decl-specifier-seq [opt] declarator function-try-block
19125 function-definition:
19126 __extension__ function-definition
19130 function-definition:
19131 decl-specifier-seq [opt] declarator function-transaction-block
19133 The DECL_SPECIFIERS apply to this declarator. Returns a
19134 representation of the entity declared. If MEMBER_P is TRUE, then
19135 this declarator appears in a class scope. The new DECL created by
19136 this declarator is returned.
19138 The CHECKS are access checks that should be performed once we know
19139 what entity is being declared (and, therefore, what classes have
19142 If FUNCTION_DEFINITION_ALLOWED_P then we handle the declarator and
19143 for a function-definition here as well. If the declarator is a
19144 declarator for a function-definition, *FUNCTION_DEFINITION_P will
19145 be TRUE upon return. By that point, the function-definition will
19146 have been completely parsed.
19148 FUNCTION_DEFINITION_P may be NULL if FUNCTION_DEFINITION_ALLOWED_P
19151 If MAYBE_RANGE_FOR_DECL is not NULL, the pointed tree will be set to the
19152 parsed declaration if it is an uninitialized single declarator not followed
19153 by a `;', or to error_mark_node otherwise. Either way, the trailing `;',
19154 if present, will not be consumed. If returned, this declarator will be
19155 created with SD_INITIALIZED but will not call cp_finish_decl.
19157 If INIT_LOC is not NULL, and *INIT_LOC is equal to UNKNOWN_LOCATION,
19158 and there is an initializer, the pointed location_t is set to the
19159 location of the '=' or `(', or '{' in C++11 token introducing the
19163 cp_parser_init_declarator (cp_parser
* parser
,
19164 cp_decl_specifier_seq
*decl_specifiers
,
19165 vec
<deferred_access_check
, va_gc
> *checks
,
19166 bool function_definition_allowed_p
,
19168 int declares_class_or_enum
,
19169 bool* function_definition_p
,
19170 tree
* maybe_range_for_decl
,
19171 location_t
* init_loc
,
19174 cp_token
*token
= NULL
, *asm_spec_start_token
= NULL
,
19175 *attributes_start_token
= NULL
;
19176 cp_declarator
*declarator
;
19177 tree prefix_attributes
;
19178 tree attributes
= NULL
;
19179 tree asm_specification
;
19181 tree decl
= NULL_TREE
;
19183 int is_initialized
;
19184 /* Only valid if IS_INITIALIZED is true. In that case, CPP_EQ if
19185 initialized with "= ..", CPP_OPEN_PAREN if initialized with
19187 enum cpp_ttype initialization_kind
;
19188 bool is_direct_init
= false;
19189 bool is_non_constant_init
;
19190 int ctor_dtor_or_conv_p
;
19191 bool friend_p
= cp_parser_friend_p (decl_specifiers
);
19192 tree pushed_scope
= NULL_TREE
;
19193 bool range_for_decl_p
= false;
19194 bool saved_default_arg_ok_p
= parser
->default_arg_ok_p
;
19195 location_t tmp_init_loc
= UNKNOWN_LOCATION
;
19197 /* Gather the attributes that were provided with the
19198 decl-specifiers. */
19199 prefix_attributes
= decl_specifiers
->attributes
;
19201 /* Assume that this is not the declarator for a function
19203 if (function_definition_p
)
19204 *function_definition_p
= false;
19206 /* Default arguments are only permitted for function parameters. */
19207 if (decl_spec_seq_has_spec_p (decl_specifiers
, ds_typedef
))
19208 parser
->default_arg_ok_p
= false;
19210 /* Defer access checks while parsing the declarator; we cannot know
19211 what names are accessible until we know what is being
19213 resume_deferring_access_checks ();
19215 token
= cp_lexer_peek_token (parser
->lexer
);
19217 /* Parse the declarator. */
19219 = cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_NAMED
,
19220 &ctor_dtor_or_conv_p
,
19221 /*parenthesized_p=*/NULL
,
19222 member_p
, friend_p
);
19223 /* Gather up the deferred checks. */
19224 stop_deferring_access_checks ();
19226 parser
->default_arg_ok_p
= saved_default_arg_ok_p
;
19228 /* If the DECLARATOR was erroneous, there's no need to go
19230 if (declarator
== cp_error_declarator
)
19231 return error_mark_node
;
19233 /* Check that the number of template-parameter-lists is OK. */
19234 if (!cp_parser_check_declarator_template_parameters (parser
, declarator
,
19236 return error_mark_node
;
19238 if (declares_class_or_enum
& 2)
19239 cp_parser_check_for_definition_in_return_type (declarator
,
19240 decl_specifiers
->type
,
19241 decl_specifiers
->locations
[ds_type_spec
]);
19243 /* Figure out what scope the entity declared by the DECLARATOR is
19244 located in. `grokdeclarator' sometimes changes the scope, so
19245 we compute it now. */
19246 scope
= get_scope_of_declarator (declarator
);
19248 /* Perform any lookups in the declared type which were thought to be
19249 dependent, but are not in the scope of the declarator. */
19250 decl_specifiers
->type
19251 = maybe_update_decl_type (decl_specifiers
->type
, scope
);
19253 /* If we're allowing GNU extensions, look for an
19254 asm-specification. */
19255 if (cp_parser_allow_gnu_extensions_p (parser
))
19257 /* Look for an asm-specification. */
19258 asm_spec_start_token
= cp_lexer_peek_token (parser
->lexer
);
19259 asm_specification
= cp_parser_asm_specification_opt (parser
);
19262 asm_specification
= NULL_TREE
;
19264 /* Look for attributes. */
19265 attributes_start_token
= cp_lexer_peek_token (parser
->lexer
);
19266 attributes
= cp_parser_attributes_opt (parser
);
19268 /* Peek at the next token. */
19269 token
= cp_lexer_peek_token (parser
->lexer
);
19271 bool bogus_implicit_tmpl
= false;
19273 if (function_declarator_p (declarator
))
19275 /* Handle C++17 deduction guides. */
19276 if (!decl_specifiers
->type
19277 && ctor_dtor_or_conv_p
<= 0
19278 && cxx_dialect
>= cxx1z
)
19280 cp_declarator
*id
= get_id_declarator (declarator
);
19281 tree name
= id
->u
.id
.unqualified_name
;
19282 parser
->scope
= id
->u
.id
.qualifying_scope
;
19283 tree tmpl
= cp_parser_lookup_name_simple (parser
, name
, id
->id_loc
);
19285 && (DECL_CLASS_TEMPLATE_P (tmpl
)
19286 || DECL_TEMPLATE_TEMPLATE_PARM_P (tmpl
)))
19288 id
->u
.id
.unqualified_name
= dguide_name (tmpl
);
19289 id
->u
.id
.sfk
= sfk_deduction_guide
;
19290 ctor_dtor_or_conv_p
= 1;
19294 /* Check to see if the token indicates the start of a
19295 function-definition. */
19296 if (cp_parser_token_starts_function_definition_p (token
))
19298 if (!function_definition_allowed_p
)
19300 /* If a function-definition should not appear here, issue an
19302 cp_parser_error (parser
,
19303 "a function-definition is not allowed here");
19304 return error_mark_node
;
19307 location_t func_brace_location
19308 = cp_lexer_peek_token (parser
->lexer
)->location
;
19310 /* Neither attributes nor an asm-specification are allowed
19311 on a function-definition. */
19312 if (asm_specification
)
19313 error_at (asm_spec_start_token
->location
,
19314 "an asm-specification is not allowed "
19315 "on a function-definition");
19317 error_at (attributes_start_token
->location
,
19318 "attributes are not allowed "
19319 "on a function-definition");
19320 /* This is a function-definition. */
19321 *function_definition_p
= true;
19323 /* Parse the function definition. */
19325 decl
= cp_parser_save_member_function_body (parser
,
19328 prefix_attributes
);
19331 (cp_parser_function_definition_from_specifiers_and_declarator
19332 (parser
, decl_specifiers
, prefix_attributes
, declarator
));
19334 if (decl
!= error_mark_node
&& DECL_STRUCT_FUNCTION (decl
))
19336 /* This is where the prologue starts... */
19337 DECL_STRUCT_FUNCTION (decl
)->function_start_locus
19338 = func_brace_location
;
19344 else if (parser
->fully_implicit_function_template_p
)
19346 /* A non-template declaration involving a function parameter list
19347 containing an implicit template parameter will be made into a
19348 template. If the resulting declaration is not going to be an
19349 actual function then finish the template scope here to prevent it.
19350 An error message will be issued once we have a decl to talk about.
19352 FIXME probably we should do type deduction rather than create an
19353 implicit template, but the standard currently doesn't allow it. */
19354 bogus_implicit_tmpl
= true;
19355 finish_fully_implicit_template (parser
, NULL_TREE
);
19360 Only in function declarations for constructors, destructors, type
19361 conversions, and deduction guides can the decl-specifier-seq be omitted.
19363 We explicitly postpone this check past the point where we handle
19364 function-definitions because we tolerate function-definitions
19365 that are missing their return types in some modes. */
19366 if (!decl_specifiers
->any_specifiers_p
&& ctor_dtor_or_conv_p
<= 0)
19368 cp_parser_error (parser
,
19369 "expected constructor, destructor, or type conversion");
19370 return error_mark_node
;
19373 /* An `=' or an `(', or an '{' in C++0x, indicates an initializer. */
19374 if (token
->type
== CPP_EQ
19375 || token
->type
== CPP_OPEN_PAREN
19376 || token
->type
== CPP_OPEN_BRACE
)
19378 is_initialized
= SD_INITIALIZED
;
19379 initialization_kind
= token
->type
;
19380 if (maybe_range_for_decl
)
19381 *maybe_range_for_decl
= error_mark_node
;
19382 tmp_init_loc
= token
->location
;
19383 if (init_loc
&& *init_loc
== UNKNOWN_LOCATION
)
19384 *init_loc
= tmp_init_loc
;
19386 if (token
->type
== CPP_EQ
19387 && function_declarator_p (declarator
))
19389 cp_token
*t2
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
19390 if (t2
->keyword
== RID_DEFAULT
)
19391 is_initialized
= SD_DEFAULTED
;
19392 else if (t2
->keyword
== RID_DELETE
)
19393 is_initialized
= SD_DELETED
;
19398 /* If the init-declarator isn't initialized and isn't followed by a
19399 `,' or `;', it's not a valid init-declarator. */
19400 if (token
->type
!= CPP_COMMA
19401 && token
->type
!= CPP_SEMICOLON
)
19403 if (maybe_range_for_decl
&& *maybe_range_for_decl
!= error_mark_node
)
19404 range_for_decl_p
= true;
19407 if (!maybe_range_for_decl
)
19408 cp_parser_error (parser
, "expected initializer");
19409 return error_mark_node
;
19412 is_initialized
= SD_UNINITIALIZED
;
19413 initialization_kind
= CPP_EOF
;
19416 /* Because start_decl has side-effects, we should only call it if we
19417 know we're going ahead. By this point, we know that we cannot
19418 possibly be looking at any other construct. */
19419 cp_parser_commit_to_tentative_parse (parser
);
19421 /* Enter the newly declared entry in the symbol table. If we're
19422 processing a declaration in a class-specifier, we wait until
19423 after processing the initializer. */
19426 if (parser
->in_unbraced_linkage_specification_p
)
19427 decl_specifiers
->storage_class
= sc_extern
;
19428 decl
= start_decl (declarator
, decl_specifiers
,
19429 range_for_decl_p
? SD_INITIALIZED
: is_initialized
,
19430 attributes
, prefix_attributes
, &pushed_scope
);
19431 cp_finalize_omp_declare_simd (parser
, decl
);
19432 cp_finalize_oacc_routine (parser
, decl
, false);
19433 /* Adjust location of decl if declarator->id_loc is more appropriate:
19434 set, and decl wasn't merged with another decl, in which case its
19435 location would be different from input_location, and more accurate. */
19437 && declarator
->id_loc
!= UNKNOWN_LOCATION
19438 && DECL_SOURCE_LOCATION (decl
) == input_location
)
19439 DECL_SOURCE_LOCATION (decl
) = declarator
->id_loc
;
19442 /* Enter the SCOPE. That way unqualified names appearing in the
19443 initializer will be looked up in SCOPE. */
19444 pushed_scope
= push_scope (scope
);
19446 /* Perform deferred access control checks, now that we know in which
19447 SCOPE the declared entity resides. */
19448 if (!member_p
&& decl
)
19450 tree saved_current_function_decl
= NULL_TREE
;
19452 /* If the entity being declared is a function, pretend that we
19453 are in its scope. If it is a `friend', it may have access to
19454 things that would not otherwise be accessible. */
19455 if (TREE_CODE (decl
) == FUNCTION_DECL
)
19457 saved_current_function_decl
= current_function_decl
;
19458 current_function_decl
= decl
;
19461 /* Perform access checks for template parameters. */
19462 cp_parser_perform_template_parameter_access_checks (checks
);
19464 /* Perform the access control checks for the declarator and the
19465 decl-specifiers. */
19466 perform_deferred_access_checks (tf_warning_or_error
);
19468 /* Restore the saved value. */
19469 if (TREE_CODE (decl
) == FUNCTION_DECL
)
19470 current_function_decl
= saved_current_function_decl
;
19473 /* Parse the initializer. */
19474 initializer
= NULL_TREE
;
19475 is_direct_init
= false;
19476 is_non_constant_init
= true;
19477 if (is_initialized
)
19479 if (function_declarator_p (declarator
))
19481 if (initialization_kind
== CPP_EQ
)
19482 initializer
= cp_parser_pure_specifier (parser
);
19485 /* If the declaration was erroneous, we don't really
19486 know what the user intended, so just silently
19487 consume the initializer. */
19488 if (decl
!= error_mark_node
)
19489 error_at (tmp_init_loc
, "initializer provided for function");
19490 cp_parser_skip_to_closing_parenthesis (parser
,
19491 /*recovering=*/true,
19492 /*or_comma=*/false,
19493 /*consume_paren=*/true);
19498 /* We want to record the extra mangling scope for in-class
19499 initializers of class members and initializers of static data
19500 member templates. The former involves deferring
19501 parsing of the initializer until end of class as with default
19502 arguments. So right here we only handle the latter. */
19503 if (!member_p
&& processing_template_decl
)
19504 start_lambda_scope (decl
);
19505 initializer
= cp_parser_initializer (parser
,
19507 &is_non_constant_init
);
19508 if (!member_p
&& processing_template_decl
)
19509 finish_lambda_scope ();
19510 if (initializer
== error_mark_node
)
19511 cp_parser_skip_to_end_of_statement (parser
);
19515 /* The old parser allows attributes to appear after a parenthesized
19516 initializer. Mark Mitchell proposed removing this functionality
19517 on the GCC mailing lists on 2002-08-13. This parser accepts the
19518 attributes -- but ignores them. */
19519 if (cp_parser_allow_gnu_extensions_p (parser
)
19520 && initialization_kind
== CPP_OPEN_PAREN
)
19521 if (cp_parser_attributes_opt (parser
))
19522 warning (OPT_Wattributes
,
19523 "attributes after parenthesized initializer ignored");
19525 /* And now complain about a non-function implicit template. */
19526 if (bogus_implicit_tmpl
&& decl
!= error_mark_node
)
19527 error_at (DECL_SOURCE_LOCATION (decl
),
19528 "non-function %qD declared as implicit template", decl
);
19530 /* For an in-class declaration, use `grokfield' to create the
19536 pop_scope (pushed_scope
);
19537 pushed_scope
= NULL_TREE
;
19539 decl
= grokfield (declarator
, decl_specifiers
,
19540 initializer
, !is_non_constant_init
,
19541 /*asmspec=*/NULL_TREE
,
19542 chainon (attributes
, prefix_attributes
));
19543 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
19544 cp_parser_save_default_args (parser
, decl
);
19545 cp_finalize_omp_declare_simd (parser
, decl
);
19546 cp_finalize_oacc_routine (parser
, decl
, false);
19549 /* Finish processing the declaration. But, skip member
19551 if (!member_p
&& decl
&& decl
!= error_mark_node
&& !range_for_decl_p
)
19553 cp_finish_decl (decl
,
19554 initializer
, !is_non_constant_init
,
19556 /* If the initializer is in parentheses, then this is
19557 a direct-initialization, which means that an
19558 `explicit' constructor is OK. Otherwise, an
19559 `explicit' constructor cannot be used. */
19560 ((is_direct_init
|| !is_initialized
)
19561 ? LOOKUP_NORMAL
: LOOKUP_IMPLICIT
));
19563 else if ((cxx_dialect
!= cxx98
) && friend_p
19564 && decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
19565 /* Core issue #226 (C++0x only): A default template-argument
19566 shall not be specified in a friend class template
19568 check_default_tmpl_args (decl
, current_template_parms
, /*is_primary=*/true,
19569 /*is_partial=*/false, /*is_friend_decl=*/1);
19571 if (!friend_p
&& pushed_scope
)
19572 pop_scope (pushed_scope
);
19574 if (function_declarator_p (declarator
)
19575 && parser
->fully_implicit_function_template_p
)
19578 decl
= finish_fully_implicit_template (parser
, decl
);
19580 finish_fully_implicit_template (parser
, /*member_decl_opt=*/0);
19583 if (auto_result
&& is_initialized
&& decl_specifiers
->type
19584 && type_uses_auto (decl_specifiers
->type
))
19585 *auto_result
= strip_declarator_types (TREE_TYPE (decl
), declarator
);
19590 /* Parse a declarator.
19594 ptr-operator declarator
19596 abstract-declarator:
19597 ptr-operator abstract-declarator [opt]
19598 direct-abstract-declarator
19603 attributes [opt] direct-declarator
19604 attributes [opt] ptr-operator declarator
19606 abstract-declarator:
19607 attributes [opt] ptr-operator abstract-declarator [opt]
19608 attributes [opt] direct-abstract-declarator
19610 If CTOR_DTOR_OR_CONV_P is not NULL, *CTOR_DTOR_OR_CONV_P is used to
19611 detect constructors, destructors, deduction guides, or conversion operators.
19612 It is set to -1 if the declarator is a name, and +1 if it is a
19613 function. Otherwise it is set to zero. Usually you just want to
19614 test for >0, but internally the negative value is used.
19616 (The reason for CTOR_DTOR_OR_CONV_P is that a declaration must have
19617 a decl-specifier-seq unless it declares a constructor, destructor,
19618 or conversion. It might seem that we could check this condition in
19619 semantic analysis, rather than parsing, but that makes it difficult
19620 to handle something like `f()'. We want to notice that there are
19621 no decl-specifiers, and therefore realize that this is an
19622 expression, not a declaration.)
19624 If PARENTHESIZED_P is non-NULL, *PARENTHESIZED_P is set to true iff
19625 the declarator is a direct-declarator of the form "(...)".
19627 MEMBER_P is true iff this declarator is a member-declarator.
19629 FRIEND_P is true iff this declarator is a friend. */
19631 static cp_declarator
*
19632 cp_parser_declarator (cp_parser
* parser
,
19633 cp_parser_declarator_kind dcl_kind
,
19634 int* ctor_dtor_or_conv_p
,
19635 bool* parenthesized_p
,
19636 bool member_p
, bool friend_p
)
19638 cp_declarator
*declarator
;
19639 enum tree_code code
;
19640 cp_cv_quals cv_quals
;
19642 tree gnu_attributes
= NULL_TREE
, std_attributes
= NULL_TREE
;
19644 /* Assume this is not a constructor, destructor, or type-conversion
19646 if (ctor_dtor_or_conv_p
)
19647 *ctor_dtor_or_conv_p
= 0;
19649 if (cp_parser_allow_gnu_extensions_p (parser
))
19650 gnu_attributes
= cp_parser_gnu_attributes_opt (parser
);
19652 /* Check for the ptr-operator production. */
19653 cp_parser_parse_tentatively (parser
);
19654 /* Parse the ptr-operator. */
19655 code
= cp_parser_ptr_operator (parser
,
19660 /* If that worked, then we have a ptr-operator. */
19661 if (cp_parser_parse_definitely (parser
))
19663 /* If a ptr-operator was found, then this declarator was not
19665 if (parenthesized_p
)
19666 *parenthesized_p
= true;
19667 /* The dependent declarator is optional if we are parsing an
19668 abstract-declarator. */
19669 if (dcl_kind
!= CP_PARSER_DECLARATOR_NAMED
)
19670 cp_parser_parse_tentatively (parser
);
19672 /* Parse the dependent declarator. */
19673 declarator
= cp_parser_declarator (parser
, dcl_kind
,
19674 /*ctor_dtor_or_conv_p=*/NULL
,
19675 /*parenthesized_p=*/NULL
,
19676 /*member_p=*/false,
19679 /* If we are parsing an abstract-declarator, we must handle the
19680 case where the dependent declarator is absent. */
19681 if (dcl_kind
!= CP_PARSER_DECLARATOR_NAMED
19682 && !cp_parser_parse_definitely (parser
))
19685 declarator
= cp_parser_make_indirect_declarator
19686 (code
, class_type
, cv_quals
, declarator
, std_attributes
);
19688 /* Everything else is a direct-declarator. */
19691 if (parenthesized_p
)
19692 *parenthesized_p
= cp_lexer_next_token_is (parser
->lexer
,
19694 declarator
= cp_parser_direct_declarator (parser
, dcl_kind
,
19695 ctor_dtor_or_conv_p
,
19696 member_p
, friend_p
);
19699 if (gnu_attributes
&& declarator
&& declarator
!= cp_error_declarator
)
19700 declarator
->attributes
= gnu_attributes
;
19704 /* Parse a direct-declarator or direct-abstract-declarator.
19708 direct-declarator ( parameter-declaration-clause )
19709 cv-qualifier-seq [opt]
19710 ref-qualifier [opt]
19711 exception-specification [opt]
19712 direct-declarator [ constant-expression [opt] ]
19715 direct-abstract-declarator:
19716 direct-abstract-declarator [opt]
19717 ( parameter-declaration-clause )
19718 cv-qualifier-seq [opt]
19719 ref-qualifier [opt]
19720 exception-specification [opt]
19721 direct-abstract-declarator [opt] [ constant-expression [opt] ]
19722 ( abstract-declarator )
19724 Returns a representation of the declarator. DCL_KIND is
19725 CP_PARSER_DECLARATOR_ABSTRACT, if we are parsing a
19726 direct-abstract-declarator. It is CP_PARSER_DECLARATOR_NAMED, if
19727 we are parsing a direct-declarator. It is
19728 CP_PARSER_DECLARATOR_EITHER, if we can accept either - in the case
19729 of ambiguity we prefer an abstract declarator, as per
19730 [dcl.ambig.res]. CTOR_DTOR_OR_CONV_P, MEMBER_P, and FRIEND_P are
19731 as for cp_parser_declarator. */
19733 static cp_declarator
*
19734 cp_parser_direct_declarator (cp_parser
* parser
,
19735 cp_parser_declarator_kind dcl_kind
,
19736 int* ctor_dtor_or_conv_p
,
19737 bool member_p
, bool friend_p
)
19740 cp_declarator
*declarator
= NULL
;
19741 tree scope
= NULL_TREE
;
19742 bool saved_default_arg_ok_p
= parser
->default_arg_ok_p
;
19743 bool saved_in_declarator_p
= parser
->in_declarator_p
;
19745 tree pushed_scope
= NULL_TREE
;
19749 /* Peek at the next token. */
19750 token
= cp_lexer_peek_token (parser
->lexer
);
19751 if (token
->type
== CPP_OPEN_PAREN
)
19753 /* This is either a parameter-declaration-clause, or a
19754 parenthesized declarator. When we know we are parsing a
19755 named declarator, it must be a parenthesized declarator
19756 if FIRST is true. For instance, `(int)' is a
19757 parameter-declaration-clause, with an omitted
19758 direct-abstract-declarator. But `((*))', is a
19759 parenthesized abstract declarator. Finally, when T is a
19760 template parameter `(T)' is a
19761 parameter-declaration-clause, and not a parenthesized
19764 We first try and parse a parameter-declaration-clause,
19765 and then try a nested declarator (if FIRST is true).
19767 It is not an error for it not to be a
19768 parameter-declaration-clause, even when FIRST is
19774 The first is the declaration of a function while the
19775 second is the definition of a variable, including its
19778 Having seen only the parenthesis, we cannot know which of
19779 these two alternatives should be selected. Even more
19780 complex are examples like:
19785 The former is a function-declaration; the latter is a
19786 variable initialization.
19788 Thus again, we try a parameter-declaration-clause, and if
19789 that fails, we back out and return. */
19791 if (!first
|| dcl_kind
!= CP_PARSER_DECLARATOR_NAMED
)
19794 bool is_declarator
= false;
19796 /* In a member-declarator, the only valid interpretation
19797 of a parenthesis is the start of a
19798 parameter-declaration-clause. (It is invalid to
19799 initialize a static data member with a parenthesized
19800 initializer; only the "=" form of initialization is
19803 cp_parser_parse_tentatively (parser
);
19805 /* Consume the `('. */
19806 cp_lexer_consume_token (parser
->lexer
);
19809 /* If this is going to be an abstract declarator, we're
19810 in a declarator and we can't have default args. */
19811 parser
->default_arg_ok_p
= false;
19812 parser
->in_declarator_p
= true;
19815 begin_scope (sk_function_parms
, NULL_TREE
);
19817 /* Parse the parameter-declaration-clause. */
19818 params
= cp_parser_parameter_declaration_clause (parser
);
19820 /* Consume the `)'. */
19821 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
19823 /* If all went well, parse the cv-qualifier-seq,
19824 ref-qualifier and the exception-specification. */
19825 if (member_p
|| cp_parser_parse_definitely (parser
))
19827 cp_cv_quals cv_quals
;
19828 cp_virt_specifiers virt_specifiers
;
19829 cp_ref_qualifier ref_qual
;
19830 tree exception_specification
;
19833 bool memfn
= (member_p
|| (pushed_scope
19834 && CLASS_TYPE_P (pushed_scope
)));
19836 is_declarator
= true;
19838 if (ctor_dtor_or_conv_p
)
19839 *ctor_dtor_or_conv_p
= *ctor_dtor_or_conv_p
< 0;
19842 /* Parse the cv-qualifier-seq. */
19843 cv_quals
= cp_parser_cv_qualifier_seq_opt (parser
);
19844 /* Parse the ref-qualifier. */
19845 ref_qual
= cp_parser_ref_qualifier_opt (parser
);
19846 /* Parse the tx-qualifier. */
19847 tree tx_qual
= cp_parser_tx_qualifier_opt (parser
);
19848 /* And the exception-specification. */
19849 exception_specification
19850 = cp_parser_exception_specification_opt (parser
);
19852 attrs
= cp_parser_std_attribute_spec_seq (parser
);
19854 /* In here, we handle cases where attribute is used after
19855 the function declaration. For example:
19856 void func (int x) __attribute__((vector(..))); */
19857 tree gnu_attrs
= NULL_TREE
;
19859 && cp_next_tokens_can_be_gnu_attribute_p (parser
))
19861 cp_parser_parse_tentatively (parser
);
19862 tree attr
= cp_parser_gnu_attributes_opt (parser
);
19863 if (cp_lexer_next_token_is_not (parser
->lexer
,
19865 && cp_lexer_next_token_is_not (parser
->lexer
,
19867 cp_parser_abort_tentative_parse (parser
);
19868 else if (!cp_parser_parse_definitely (parser
))
19873 tree requires_clause
= NULL_TREE
;
19874 late_return
= (cp_parser_late_return_type_opt
19875 (parser
, declarator
, requires_clause
,
19876 memfn
? cv_quals
: -1));
19878 /* Parse the virt-specifier-seq. */
19879 virt_specifiers
= cp_parser_virt_specifier_seq_opt (parser
);
19881 /* Create the function-declarator. */
19882 declarator
= make_call_declarator (declarator
,
19888 exception_specification
,
19891 declarator
->std_attributes
= attrs
;
19892 declarator
->attributes
= gnu_attrs
;
19893 /* Any subsequent parameter lists are to do with
19894 return type, so are not those of the declared
19896 parser
->default_arg_ok_p
= false;
19899 /* Remove the function parms from scope. */
19900 pop_bindings_and_leave_scope ();
19903 /* Repeat the main loop. */
19907 /* If this is the first, we can try a parenthesized
19911 bool saved_in_type_id_in_expr_p
;
19913 parser
->default_arg_ok_p
= saved_default_arg_ok_p
;
19914 parser
->in_declarator_p
= saved_in_declarator_p
;
19916 /* Consume the `('. */
19917 cp_lexer_consume_token (parser
->lexer
);
19918 /* Parse the nested declarator. */
19919 saved_in_type_id_in_expr_p
= parser
->in_type_id_in_expr_p
;
19920 parser
->in_type_id_in_expr_p
= true;
19922 = cp_parser_declarator (parser
, dcl_kind
, ctor_dtor_or_conv_p
,
19923 /*parenthesized_p=*/NULL
,
19924 member_p
, friend_p
);
19925 parser
->in_type_id_in_expr_p
= saved_in_type_id_in_expr_p
;
19927 /* Expect a `)'. */
19928 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
19929 declarator
= cp_error_declarator
;
19930 if (declarator
== cp_error_declarator
)
19933 goto handle_declarator
;
19935 /* Otherwise, we must be done. */
19939 else if ((!first
|| dcl_kind
!= CP_PARSER_DECLARATOR_NAMED
)
19940 && token
->type
== CPP_OPEN_SQUARE
19941 && !cp_next_tokens_can_be_attribute_p (parser
))
19943 /* Parse an array-declarator. */
19944 tree bounds
, attrs
;
19946 if (ctor_dtor_or_conv_p
)
19947 *ctor_dtor_or_conv_p
= 0;
19950 parser
->default_arg_ok_p
= false;
19951 parser
->in_declarator_p
= true;
19952 /* Consume the `['. */
19953 cp_lexer_consume_token (parser
->lexer
);
19954 /* Peek at the next token. */
19955 token
= cp_lexer_peek_token (parser
->lexer
);
19956 /* If the next token is `]', then there is no
19957 constant-expression. */
19958 if (token
->type
!= CPP_CLOSE_SQUARE
)
19960 bool non_constant_p
;
19962 = cp_parser_constant_expression (parser
,
19963 /*allow_non_constant=*/true,
19965 if (!non_constant_p
)
19967 else if (error_operand_p (bounds
))
19968 /* Already gave an error. */;
19969 else if (!parser
->in_function_body
19970 || current_binding_level
->kind
== sk_function_parms
)
19972 /* Normally, the array bound must be an integral constant
19973 expression. However, as an extension, we allow VLAs
19974 in function scopes as long as they aren't part of a
19975 parameter declaration. */
19976 cp_parser_error (parser
,
19977 "array bound is not an integer constant");
19978 bounds
= error_mark_node
;
19980 else if (processing_template_decl
19981 && !type_dependent_expression_p (bounds
))
19983 /* Remember this wasn't a constant-expression. */
19984 bounds
= build_nop (TREE_TYPE (bounds
), bounds
);
19985 TREE_SIDE_EFFECTS (bounds
) = 1;
19989 bounds
= NULL_TREE
;
19990 /* Look for the closing `]'. */
19991 if (!cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
))
19993 declarator
= cp_error_declarator
;
19997 attrs
= cp_parser_std_attribute_spec_seq (parser
);
19998 declarator
= make_array_declarator (declarator
, bounds
);
19999 declarator
->std_attributes
= attrs
;
20001 else if (first
&& dcl_kind
!= CP_PARSER_DECLARATOR_ABSTRACT
)
20004 tree qualifying_scope
;
20005 tree unqualified_name
;
20007 special_function_kind sfk
;
20009 bool pack_expansion_p
= false;
20010 cp_token
*declarator_id_start_token
;
20012 /* Parse a declarator-id */
20013 abstract_ok
= (dcl_kind
== CP_PARSER_DECLARATOR_EITHER
);
20016 cp_parser_parse_tentatively (parser
);
20018 /* If we see an ellipsis, we should be looking at a
20020 if (token
->type
== CPP_ELLIPSIS
)
20022 /* Consume the `...' */
20023 cp_lexer_consume_token (parser
->lexer
);
20025 pack_expansion_p
= true;
20029 declarator_id_start_token
= cp_lexer_peek_token (parser
->lexer
);
20031 = cp_parser_declarator_id (parser
, /*optional_p=*/abstract_ok
);
20032 qualifying_scope
= parser
->scope
;
20037 if (!unqualified_name
&& pack_expansion_p
)
20039 /* Check whether an error occurred. */
20040 okay
= !cp_parser_error_occurred (parser
);
20042 /* We already consumed the ellipsis to mark a
20043 parameter pack, but we have no way to report it,
20044 so abort the tentative parse. We will be exiting
20045 immediately anyway. */
20046 cp_parser_abort_tentative_parse (parser
);
20049 okay
= cp_parser_parse_definitely (parser
);
20052 unqualified_name
= error_mark_node
;
20053 else if (unqualified_name
20054 && (qualifying_scope
20055 || (!identifier_p (unqualified_name
))))
20057 cp_parser_error (parser
, "expected unqualified-id");
20058 unqualified_name
= error_mark_node
;
20062 if (!unqualified_name
)
20064 if (unqualified_name
== error_mark_node
)
20066 declarator
= cp_error_declarator
;
20067 pack_expansion_p
= false;
20068 declarator
->parameter_pack_p
= false;
20072 attrs
= cp_parser_std_attribute_spec_seq (parser
);
20074 if (qualifying_scope
&& at_namespace_scope_p ()
20075 && TREE_CODE (qualifying_scope
) == TYPENAME_TYPE
)
20077 /* In the declaration of a member of a template class
20078 outside of the class itself, the SCOPE will sometimes
20079 be a TYPENAME_TYPE. For example, given:
20081 template <typename T>
20082 int S<T>::R::i = 3;
20084 the SCOPE will be a TYPENAME_TYPE for `S<T>::R'. In
20085 this context, we must resolve S<T>::R to an ordinary
20086 type, rather than a typename type.
20088 The reason we normally avoid resolving TYPENAME_TYPEs
20089 is that a specialization of `S' might render
20090 `S<T>::R' not a type. However, if `S' is
20091 specialized, then this `i' will not be used, so there
20092 is no harm in resolving the types here. */
20095 /* Resolve the TYPENAME_TYPE. */
20096 type
= resolve_typename_type (qualifying_scope
,
20097 /*only_current_p=*/false);
20098 /* If that failed, the declarator is invalid. */
20099 if (TREE_CODE (type
) == TYPENAME_TYPE
)
20101 if (typedef_variant_p (type
))
20102 error_at (declarator_id_start_token
->location
,
20103 "cannot define member of dependent typedef "
20106 error_at (declarator_id_start_token
->location
,
20107 "%<%T::%E%> is not a type",
20108 TYPE_CONTEXT (qualifying_scope
),
20109 TYPE_IDENTIFIER (qualifying_scope
));
20111 qualifying_scope
= type
;
20116 if (unqualified_name
)
20120 if (qualifying_scope
20121 && CLASS_TYPE_P (qualifying_scope
))
20122 class_type
= qualifying_scope
;
20124 class_type
= current_class_type
;
20126 if (TREE_CODE (unqualified_name
) == TYPE_DECL
)
20128 tree name_type
= TREE_TYPE (unqualified_name
);
20130 if (!class_type
|| !same_type_p (name_type
, class_type
))
20132 /* We do not attempt to print the declarator
20133 here because we do not have enough
20134 information about its original syntactic
20136 cp_parser_error (parser
, "invalid declarator");
20137 declarator
= cp_error_declarator
;
20140 else if (qualifying_scope
20141 && CLASSTYPE_USE_TEMPLATE (name_type
))
20143 error_at (declarator_id_start_token
->location
,
20144 "invalid use of constructor as a template");
20145 inform (declarator_id_start_token
->location
,
20146 "use %<%T::%D%> instead of %<%T::%D%> to "
20147 "name the constructor in a qualified name",
20149 DECL_NAME (TYPE_TI_TEMPLATE (class_type
)),
20150 class_type
, name_type
);
20151 declarator
= cp_error_declarator
;
20154 unqualified_name
= constructor_name (class_type
);
20159 if (TREE_CODE (unqualified_name
) == BIT_NOT_EXPR
)
20160 sfk
= sfk_destructor
;
20161 else if (identifier_p (unqualified_name
)
20162 && IDENTIFIER_CONV_OP_P (unqualified_name
))
20163 sfk
= sfk_conversion
;
20164 else if (/* There's no way to declare a constructor
20165 for an unnamed type, even if the type
20166 got a name for linkage purposes. */
20167 !TYPE_WAS_UNNAMED (class_type
)
20168 /* Handle correctly (c++/19200):
20182 friend void N::S();
20184 && (!friend_p
|| class_type
== qualifying_scope
)
20185 && constructor_name_p (unqualified_name
,
20187 sfk
= sfk_constructor
;
20188 else if (is_overloaded_fn (unqualified_name
)
20189 && DECL_CONSTRUCTOR_P (get_first_fn
20190 (unqualified_name
)))
20191 sfk
= sfk_constructor
;
20193 if (ctor_dtor_or_conv_p
&& sfk
!= sfk_none
)
20194 *ctor_dtor_or_conv_p
= -1;
20197 declarator
= make_id_declarator (qualifying_scope
,
20200 declarator
->std_attributes
= attrs
;
20201 declarator
->id_loc
= token
->location
;
20202 declarator
->parameter_pack_p
= pack_expansion_p
;
20204 if (pack_expansion_p
)
20205 maybe_warn_variadic_templates ();
20208 handle_declarator
:;
20209 scope
= get_scope_of_declarator (declarator
);
20212 /* Any names that appear after the declarator-id for a
20213 member are looked up in the containing scope. */
20214 if (at_function_scope_p ())
20216 /* But declarations with qualified-ids can't appear in a
20218 cp_parser_error (parser
, "qualified-id in declaration");
20219 declarator
= cp_error_declarator
;
20222 pushed_scope
= push_scope (scope
);
20224 parser
->in_declarator_p
= true;
20225 if ((ctor_dtor_or_conv_p
&& *ctor_dtor_or_conv_p
)
20226 || (declarator
&& declarator
->kind
== cdk_id
))
20227 /* Default args are only allowed on function
20229 parser
->default_arg_ok_p
= saved_default_arg_ok_p
;
20231 parser
->default_arg_ok_p
= false;
20240 /* For an abstract declarator, we might wind up with nothing at this
20241 point. That's an error; the declarator is not optional. */
20243 cp_parser_error (parser
, "expected declarator");
20245 /* If we entered a scope, we must exit it now. */
20247 pop_scope (pushed_scope
);
20249 parser
->default_arg_ok_p
= saved_default_arg_ok_p
;
20250 parser
->in_declarator_p
= saved_in_declarator_p
;
20255 /* Parse a ptr-operator.
20258 * attribute-specifier-seq [opt] cv-qualifier-seq [opt] (C++11)
20259 * cv-qualifier-seq [opt]
20261 :: [opt] nested-name-specifier * cv-qualifier-seq [opt]
20262 nested-name-specifier * attribute-specifier-seq [opt] cv-qualifier-seq [opt] (C++11)
20267 & cv-qualifier-seq [opt]
20269 Returns INDIRECT_REF if a pointer, or pointer-to-member, was used.
20270 Returns ADDR_EXPR if a reference was used, or NON_LVALUE_EXPR for
20271 an rvalue reference. In the case of a pointer-to-member, *TYPE is
20272 filled in with the TYPE containing the member. *CV_QUALS is
20273 filled in with the cv-qualifier-seq, or TYPE_UNQUALIFIED, if there
20274 are no cv-qualifiers. Returns ERROR_MARK if an error occurred.
20275 Note that the tree codes returned by this function have nothing
20276 to do with the types of trees that will be eventually be created
20277 to represent the pointer or reference type being parsed. They are
20278 just constants with suggestive names. */
20279 static enum tree_code
20280 cp_parser_ptr_operator (cp_parser
* parser
,
20282 cp_cv_quals
*cv_quals
,
20285 enum tree_code code
= ERROR_MARK
;
20287 tree attrs
= NULL_TREE
;
20289 /* Assume that it's not a pointer-to-member. */
20291 /* And that there are no cv-qualifiers. */
20292 *cv_quals
= TYPE_UNQUALIFIED
;
20294 /* Peek at the next token. */
20295 token
= cp_lexer_peek_token (parser
->lexer
);
20297 /* If it's a `*', `&' or `&&' we have a pointer or reference. */
20298 if (token
->type
== CPP_MULT
)
20299 code
= INDIRECT_REF
;
20300 else if (token
->type
== CPP_AND
)
20302 else if ((cxx_dialect
!= cxx98
) &&
20303 token
->type
== CPP_AND_AND
) /* C++0x only */
20304 code
= NON_LVALUE_EXPR
;
20306 if (code
!= ERROR_MARK
)
20308 /* Consume the `*', `&' or `&&'. */
20309 cp_lexer_consume_token (parser
->lexer
);
20311 /* A `*' can be followed by a cv-qualifier-seq, and so can a
20312 `&', if we are allowing GNU extensions. (The only qualifier
20313 that can legally appear after `&' is `restrict', but that is
20314 enforced during semantic analysis. */
20315 if (code
== INDIRECT_REF
20316 || cp_parser_allow_gnu_extensions_p (parser
))
20317 *cv_quals
= cp_parser_cv_qualifier_seq_opt (parser
);
20319 attrs
= cp_parser_std_attribute_spec_seq (parser
);
20320 if (attributes
!= NULL
)
20321 *attributes
= attrs
;
20325 /* Try the pointer-to-member case. */
20326 cp_parser_parse_tentatively (parser
);
20327 /* Look for the optional `::' operator. */
20328 cp_parser_global_scope_opt (parser
,
20329 /*current_scope_valid_p=*/false);
20330 /* Look for the nested-name specifier. */
20331 token
= cp_lexer_peek_token (parser
->lexer
);
20332 cp_parser_nested_name_specifier (parser
,
20333 /*typename_keyword_p=*/false,
20334 /*check_dependency_p=*/true,
20336 /*is_declaration=*/false);
20337 /* If we found it, and the next token is a `*', then we are
20338 indeed looking at a pointer-to-member operator. */
20339 if (!cp_parser_error_occurred (parser
)
20340 && cp_parser_require (parser
, CPP_MULT
, RT_MULT
))
20342 /* Indicate that the `*' operator was used. */
20343 code
= INDIRECT_REF
;
20345 if (TREE_CODE (parser
->scope
) == NAMESPACE_DECL
)
20346 error_at (token
->location
, "%qD is a namespace", parser
->scope
);
20347 else if (TREE_CODE (parser
->scope
) == ENUMERAL_TYPE
)
20348 error_at (token
->location
, "cannot form pointer to member of "
20349 "non-class %q#T", parser
->scope
);
20352 /* The type of which the member is a member is given by the
20354 *type
= parser
->scope
;
20355 /* The next name will not be qualified. */
20356 parser
->scope
= NULL_TREE
;
20357 parser
->qualifying_scope
= NULL_TREE
;
20358 parser
->object_scope
= NULL_TREE
;
20359 /* Look for optional c++11 attributes. */
20360 attrs
= cp_parser_std_attribute_spec_seq (parser
);
20361 if (attributes
!= NULL
)
20362 *attributes
= attrs
;
20363 /* Look for the optional cv-qualifier-seq. */
20364 *cv_quals
= cp_parser_cv_qualifier_seq_opt (parser
);
20367 /* If that didn't work we don't have a ptr-operator. */
20368 if (!cp_parser_parse_definitely (parser
))
20369 cp_parser_error (parser
, "expected ptr-operator");
20375 /* Parse an (optional) cv-qualifier-seq.
20378 cv-qualifier cv-qualifier-seq [opt]
20389 Returns a bitmask representing the cv-qualifiers. */
20392 cp_parser_cv_qualifier_seq_opt (cp_parser
* parser
)
20394 cp_cv_quals cv_quals
= TYPE_UNQUALIFIED
;
20399 cp_cv_quals cv_qualifier
;
20401 /* Peek at the next token. */
20402 token
= cp_lexer_peek_token (parser
->lexer
);
20403 /* See if it's a cv-qualifier. */
20404 switch (token
->keyword
)
20407 cv_qualifier
= TYPE_QUAL_CONST
;
20411 cv_qualifier
= TYPE_QUAL_VOLATILE
;
20415 cv_qualifier
= TYPE_QUAL_RESTRICT
;
20419 cv_qualifier
= TYPE_UNQUALIFIED
;
20426 if (cv_quals
& cv_qualifier
)
20428 gcc_rich_location
richloc (token
->location
);
20429 richloc
.add_fixit_remove ();
20430 error_at_rich_loc (&richloc
, "duplicate cv-qualifier");
20431 cp_lexer_purge_token (parser
->lexer
);
20435 cp_lexer_consume_token (parser
->lexer
);
20436 cv_quals
|= cv_qualifier
;
20443 /* Parse an (optional) ref-qualifier
20449 Returns cp_ref_qualifier representing ref-qualifier. */
20451 static cp_ref_qualifier
20452 cp_parser_ref_qualifier_opt (cp_parser
* parser
)
20454 cp_ref_qualifier ref_qual
= REF_QUAL_NONE
;
20456 /* Don't try to parse bitwise '&' as a ref-qualifier (c++/57532). */
20457 if (cxx_dialect
< cxx11
&& cp_parser_parsing_tentatively (parser
))
20462 cp_ref_qualifier curr_ref_qual
= REF_QUAL_NONE
;
20463 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
20465 switch (token
->type
)
20468 curr_ref_qual
= REF_QUAL_LVALUE
;
20472 curr_ref_qual
= REF_QUAL_RVALUE
;
20476 curr_ref_qual
= REF_QUAL_NONE
;
20480 if (!curr_ref_qual
)
20484 error_at (token
->location
, "multiple ref-qualifiers");
20485 cp_lexer_purge_token (parser
->lexer
);
20489 ref_qual
= curr_ref_qual
;
20490 cp_lexer_consume_token (parser
->lexer
);
20497 /* Parse an optional tx-qualifier.
20501 transaction_safe_dynamic */
20504 cp_parser_tx_qualifier_opt (cp_parser
*parser
)
20506 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
20507 if (token
->type
== CPP_NAME
)
20509 tree name
= token
->u
.value
;
20510 const char *p
= IDENTIFIER_POINTER (name
);
20511 const int len
= strlen ("transaction_safe");
20512 if (!strncmp (p
, "transaction_safe", len
))
20516 || !strcmp (p
, "_dynamic"))
20518 cp_lexer_consume_token (parser
->lexer
);
20521 error ("%qE requires %<-fgnu-tm%>", name
);
20532 /* Parse an (optional) virt-specifier-seq.
20534 virt-specifier-seq:
20535 virt-specifier virt-specifier-seq [opt]
20541 Returns a bitmask representing the virt-specifiers. */
20543 static cp_virt_specifiers
20544 cp_parser_virt_specifier_seq_opt (cp_parser
* parser
)
20546 cp_virt_specifiers virt_specifiers
= VIRT_SPEC_UNSPECIFIED
;
20551 cp_virt_specifiers virt_specifier
;
20553 /* Peek at the next token. */
20554 token
= cp_lexer_peek_token (parser
->lexer
);
20555 /* See if it's a virt-specifier-qualifier. */
20556 if (token
->type
!= CPP_NAME
)
20558 if (id_equal (token
->u
.value
, "override"))
20560 maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS
);
20561 virt_specifier
= VIRT_SPEC_OVERRIDE
;
20563 else if (id_equal (token
->u
.value
, "final"))
20565 maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS
);
20566 virt_specifier
= VIRT_SPEC_FINAL
;
20568 else if (id_equal (token
->u
.value
, "__final"))
20570 virt_specifier
= VIRT_SPEC_FINAL
;
20575 if (virt_specifiers
& virt_specifier
)
20577 gcc_rich_location
richloc (token
->location
);
20578 richloc
.add_fixit_remove ();
20579 error_at_rich_loc (&richloc
, "duplicate virt-specifier");
20580 cp_lexer_purge_token (parser
->lexer
);
20584 cp_lexer_consume_token (parser
->lexer
);
20585 virt_specifiers
|= virt_specifier
;
20588 return virt_specifiers
;
20591 /* Used by handling of trailing-return-types and NSDMI, in which 'this'
20592 is in scope even though it isn't real. */
20595 inject_this_parameter (tree ctype
, cp_cv_quals quals
)
20599 if (current_class_ptr
)
20601 /* We don't clear this between NSDMIs. Is it already what we want? */
20602 tree type
= TREE_TYPE (TREE_TYPE (current_class_ptr
));
20603 if (same_type_ignoring_top_level_qualifiers_p (ctype
, type
)
20604 && cp_type_quals (type
) == quals
)
20608 this_parm
= build_this_parm (NULL_TREE
, ctype
, quals
);
20609 /* Clear this first to avoid shortcut in cp_build_indirect_ref. */
20610 current_class_ptr
= NULL_TREE
;
20612 = cp_build_indirect_ref (this_parm
, RO_NULL
, tf_warning_or_error
);
20613 current_class_ptr
= this_parm
;
20616 /* Return true iff our current scope is a non-static data member
20620 parsing_nsdmi (void)
20622 /* We recognize NSDMI context by the context-less 'this' pointer set up
20623 by the function above. */
20624 if (current_class_ptr
20625 && TREE_CODE (current_class_ptr
) == PARM_DECL
20626 && DECL_CONTEXT (current_class_ptr
) == NULL_TREE
)
20631 /* Return true iff our current scope is a default capturing generic lambda
20632 defined within a template. FIXME: This is part of a workaround (see
20633 semantics.c) to handle building lambda closure types correctly in templates
20634 which we ultimately want to defer to instantiation time. */
20637 parsing_default_capturing_generic_lambda_in_template (void)
20639 if (!processing_template_decl
|| !current_class_type
)
20642 tree lam
= CLASSTYPE_LAMBDA_EXPR (current_class_type
);
20643 if (!lam
|| LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
) == CPLD_NONE
)
20646 tree callop
= lambda_function (lam
);
20650 return (DECL_TEMPLATE_INFO (callop
)
20651 && (DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (callop
)) == callop
)
20652 && ((current_nonlambda_class_type ()
20653 && CLASSTYPE_TEMPLATE_INFO (current_nonlambda_class_type ()))
20654 || ((current_nonlambda_function ()
20655 && DECL_TEMPLATE_INFO (current_nonlambda_function ())))));
20658 /* Parse a late-specified return type, if any. This is not a separate
20659 non-terminal, but part of a function declarator, which looks like
20661 -> trailing-type-specifier-seq abstract-declarator(opt)
20663 Returns the type indicated by the type-id.
20665 In addition to this, parse any queued up #pragma omp declare simd
20666 clauses, Cilk Plus SIMD-enabled functions' vector attributes, and
20667 #pragma acc routine clauses.
20669 QUALS is either a bitmask of cv_qualifiers or -1 for a non-member
20673 cp_parser_late_return_type_opt (cp_parser
* parser
, cp_declarator
*declarator
,
20674 tree
& requires_clause
, cp_cv_quals quals
)
20677 tree type
= NULL_TREE
;
20678 bool declare_simd_p
= (parser
->omp_declare_simd
20680 && declarator
->kind
== cdk_id
);
20682 bool cilk_simd_fn_vector_p
= (parser
->cilk_simd_fn_info
20683 && declarator
&& declarator
->kind
== cdk_id
);
20685 bool oacc_routine_p
= (parser
->oacc_routine
20687 && declarator
->kind
== cdk_id
);
20689 /* Peek at the next token. */
20690 token
= cp_lexer_peek_token (parser
->lexer
);
20691 /* A late-specified return type is indicated by an initial '->'. */
20692 if (token
->type
!= CPP_DEREF
20693 && token
->keyword
!= RID_REQUIRES
20694 && !(token
->type
== CPP_NAME
20695 && token
->u
.value
== ridpointers
[RID_REQUIRES
])
20696 && !(declare_simd_p
|| cilk_simd_fn_vector_p
|| oacc_routine_p
))
20699 tree save_ccp
= current_class_ptr
;
20700 tree save_ccr
= current_class_ref
;
20703 /* DR 1207: 'this' is in scope in the trailing return type. */
20704 inject_this_parameter (current_class_type
, quals
);
20707 if (token
->type
== CPP_DEREF
)
20709 /* Consume the ->. */
20710 cp_lexer_consume_token (parser
->lexer
);
20712 type
= cp_parser_trailing_type_id (parser
);
20715 /* Function declarations may be followed by a trailing
20716 requires-clause. */
20717 requires_clause
= cp_parser_requires_clause_opt (parser
);
20719 if (cilk_simd_fn_vector_p
)
20720 declarator
->attributes
20721 = cp_parser_late_parsing_cilk_simd_fn_info (parser
,
20722 declarator
->attributes
);
20723 if (declare_simd_p
)
20724 declarator
->attributes
20725 = cp_parser_late_parsing_omp_declare_simd (parser
,
20726 declarator
->attributes
);
20727 if (oacc_routine_p
)
20728 declarator
->attributes
20729 = cp_parser_late_parsing_oacc_routine (parser
,
20730 declarator
->attributes
);
20734 current_class_ptr
= save_ccp
;
20735 current_class_ref
= save_ccr
;
20741 /* Parse a declarator-id.
20745 :: [opt] nested-name-specifier [opt] type-name
20747 In the `id-expression' case, the value returned is as for
20748 cp_parser_id_expression if the id-expression was an unqualified-id.
20749 If the id-expression was a qualified-id, then a SCOPE_REF is
20750 returned. The first operand is the scope (either a NAMESPACE_DECL
20751 or TREE_TYPE), but the second is still just a representation of an
20755 cp_parser_declarator_id (cp_parser
* parser
, bool optional_p
)
20758 /* The expression must be an id-expression. Assume that qualified
20759 names are the names of types so that:
20762 int S<T>::R::i = 3;
20764 will work; we must treat `S<T>::R' as the name of a type.
20765 Similarly, assume that qualified names are templates, where
20769 int S<T>::R<T>::i = 3;
20772 id
= cp_parser_id_expression (parser
,
20773 /*template_keyword_p=*/false,
20774 /*check_dependency_p=*/false,
20775 /*template_p=*/NULL
,
20776 /*declarator_p=*/true,
20778 if (id
&& BASELINK_P (id
))
20779 id
= BASELINK_FUNCTIONS (id
);
20783 /* Parse a type-id.
20786 type-specifier-seq abstract-declarator [opt]
20788 Returns the TYPE specified. */
20791 cp_parser_type_id_1 (cp_parser
* parser
, bool is_template_arg
,
20792 bool is_trailing_return
)
20794 cp_decl_specifier_seq type_specifier_seq
;
20795 cp_declarator
*abstract_declarator
;
20797 /* Parse the type-specifier-seq. */
20798 cp_parser_type_specifier_seq (parser
, /*is_declaration=*/false,
20799 is_trailing_return
,
20800 &type_specifier_seq
);
20801 if (is_template_arg
&& type_specifier_seq
.type
20802 && TREE_CODE (type_specifier_seq
.type
) == TEMPLATE_TYPE_PARM
20803 && CLASS_PLACEHOLDER_TEMPLATE (type_specifier_seq
.type
))
20804 /* A bare template name as a template argument is a template template
20805 argument, not a placeholder, so fail parsing it as a type argument. */
20807 gcc_assert (cp_parser_uncommitted_to_tentative_parse_p (parser
));
20808 cp_parser_simulate_error (parser
);
20809 return error_mark_node
;
20811 if (type_specifier_seq
.type
== error_mark_node
)
20812 return error_mark_node
;
20814 /* There might or might not be an abstract declarator. */
20815 cp_parser_parse_tentatively (parser
);
20816 /* Look for the declarator. */
20817 abstract_declarator
20818 = cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_ABSTRACT
, NULL
,
20819 /*parenthesized_p=*/NULL
,
20820 /*member_p=*/false,
20821 /*friend_p=*/false);
20822 /* Check to see if there really was a declarator. */
20823 if (!cp_parser_parse_definitely (parser
))
20824 abstract_declarator
= NULL
;
20826 if (type_specifier_seq
.type
20827 /* The concepts TS allows 'auto' as a type-id. */
20828 && (!flag_concepts
|| parser
->in_type_id_in_expr_p
)
20829 /* None of the valid uses of 'auto' in C++14 involve the type-id
20830 nonterminal, but it is valid in a trailing-return-type. */
20831 && !(cxx_dialect
>= cxx14
&& is_trailing_return
))
20832 if (tree auto_node
= type_uses_auto (type_specifier_seq
.type
))
20834 /* A type-id with type 'auto' is only ok if the abstract declarator
20835 is a function declarator with a late-specified return type.
20837 A type-id with 'auto' is also valid in a trailing-return-type
20838 in a compound-requirement. */
20839 if (abstract_declarator
20840 && abstract_declarator
->kind
== cdk_function
20841 && abstract_declarator
->u
.function
.late_return_type
)
20843 else if (parser
->in_result_type_constraint_p
)
20847 location_t loc
= type_specifier_seq
.locations
[ds_type_spec
];
20848 if (tree tmpl
= CLASS_PLACEHOLDER_TEMPLATE (auto_node
))
20850 error_at (loc
, "missing template arguments after %qT",
20852 inform (DECL_SOURCE_LOCATION (tmpl
), "%qD declared here",
20856 error_at (loc
, "invalid use of %qT", auto_node
);
20857 return error_mark_node
;
20861 return groktypename (&type_specifier_seq
, abstract_declarator
,
20866 cp_parser_type_id (cp_parser
*parser
)
20868 return cp_parser_type_id_1 (parser
, false, false);
20872 cp_parser_template_type_arg (cp_parser
*parser
)
20875 const char *saved_message
= parser
->type_definition_forbidden_message
;
20876 parser
->type_definition_forbidden_message
20877 = G_("types may not be defined in template arguments");
20878 r
= cp_parser_type_id_1 (parser
, true, false);
20879 parser
->type_definition_forbidden_message
= saved_message
;
20880 if (cxx_dialect
>= cxx14
&& !flag_concepts
&& type_uses_auto (r
))
20882 error ("invalid use of %<auto%> in template argument");
20883 r
= error_mark_node
;
20889 cp_parser_trailing_type_id (cp_parser
*parser
)
20891 return cp_parser_type_id_1 (parser
, false, true);
20894 /* Parse a type-specifier-seq.
20896 type-specifier-seq:
20897 type-specifier type-specifier-seq [opt]
20901 type-specifier-seq:
20902 attributes type-specifier-seq [opt]
20904 If IS_DECLARATION is true, we are at the start of a "condition" or
20905 exception-declaration, so we might be followed by a declarator-id.
20907 If IS_TRAILING_RETURN is true, we are in a trailing-return-type,
20908 i.e. we've just seen "->".
20910 Sets *TYPE_SPECIFIER_SEQ to represent the sequence. */
20913 cp_parser_type_specifier_seq (cp_parser
* parser
,
20914 bool is_declaration
,
20915 bool is_trailing_return
,
20916 cp_decl_specifier_seq
*type_specifier_seq
)
20918 bool seen_type_specifier
= false;
20919 cp_parser_flags flags
= CP_PARSER_FLAGS_OPTIONAL
;
20920 cp_token
*start_token
= NULL
;
20922 /* Clear the TYPE_SPECIFIER_SEQ. */
20923 clear_decl_specs (type_specifier_seq
);
20925 /* In the context of a trailing return type, enum E { } is an
20926 elaborated-type-specifier followed by a function-body, not an
20928 if (is_trailing_return
)
20929 flags
|= CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
;
20931 /* Parse the type-specifiers and attributes. */
20934 tree type_specifier
;
20935 bool is_cv_qualifier
;
20937 /* Check for attributes first. */
20938 if (cp_next_tokens_can_be_attribute_p (parser
))
20940 type_specifier_seq
->attributes
=
20941 chainon (type_specifier_seq
->attributes
,
20942 cp_parser_attributes_opt (parser
));
20946 /* record the token of the beginning of the type specifier seq,
20947 for error reporting purposes*/
20949 start_token
= cp_lexer_peek_token (parser
->lexer
);
20951 /* Look for the type-specifier. */
20952 type_specifier
= cp_parser_type_specifier (parser
,
20954 type_specifier_seq
,
20955 /*is_declaration=*/false,
20958 if (!type_specifier
)
20960 /* If the first type-specifier could not be found, this is not a
20961 type-specifier-seq at all. */
20962 if (!seen_type_specifier
)
20964 /* Set in_declarator_p to avoid skipping to the semicolon. */
20965 int in_decl
= parser
->in_declarator_p
;
20966 parser
->in_declarator_p
= true;
20968 if (cp_parser_uncommitted_to_tentative_parse_p (parser
)
20969 || !cp_parser_parse_and_diagnose_invalid_type_name (parser
))
20970 cp_parser_error (parser
, "expected type-specifier");
20972 parser
->in_declarator_p
= in_decl
;
20974 type_specifier_seq
->type
= error_mark_node
;
20977 /* If subsequent type-specifiers could not be found, the
20978 type-specifier-seq is complete. */
20982 seen_type_specifier
= true;
20983 /* The standard says that a condition can be:
20985 type-specifier-seq declarator = assignment-expression
20992 we should treat the "S" as a declarator, not as a
20993 type-specifier. The standard doesn't say that explicitly for
20994 type-specifier-seq, but it does say that for
20995 decl-specifier-seq in an ordinary declaration. Perhaps it
20996 would be clearer just to allow a decl-specifier-seq here, and
20997 then add a semantic restriction that if any decl-specifiers
20998 that are not type-specifiers appear, the program is invalid. */
20999 if (is_declaration
&& !is_cv_qualifier
)
21000 flags
|= CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES
;
21004 /* Return whether the function currently being declared has an associated
21005 template parameter list. */
21008 function_being_declared_is_template_p (cp_parser
* parser
)
21010 if (!current_template_parms
|| processing_template_parmlist
)
21013 if (parser
->implicit_template_scope
)
21016 if (at_class_scope_p ()
21017 && TYPE_BEING_DEFINED (current_class_type
))
21018 return parser
->num_template_parameter_lists
!= 0;
21020 return ((int) parser
->num_template_parameter_lists
> template_class_depth
21021 (current_class_type
));
21024 /* Parse a parameter-declaration-clause.
21026 parameter-declaration-clause:
21027 parameter-declaration-list [opt] ... [opt]
21028 parameter-declaration-list , ...
21030 Returns a representation for the parameter declarations. A return
21031 value of NULL indicates a parameter-declaration-clause consisting
21032 only of an ellipsis. */
21035 cp_parser_parameter_declaration_clause (cp_parser
* parser
)
21044 int auto_is_implicit_function_template_parm_p
;
21046 parser
->auto_is_implicit_function_template_parm_p
21047 = auto_is_implicit_function_template_parm_p
;
21049 } cleanup
= { parser
, parser
->auto_is_implicit_function_template_parm_p
};
21053 if (!processing_specialization
21054 && !processing_template_parmlist
21055 && !processing_explicit_instantiation
)
21056 if (!current_function_decl
21057 || (current_class_type
&& LAMBDA_TYPE_P (current_class_type
)))
21058 parser
->auto_is_implicit_function_template_parm_p
= true;
21060 /* Peek at the next token. */
21061 token
= cp_lexer_peek_token (parser
->lexer
);
21062 /* Check for trivial parameter-declaration-clauses. */
21063 if (token
->type
== CPP_ELLIPSIS
)
21065 /* Consume the `...' token. */
21066 cp_lexer_consume_token (parser
->lexer
);
21069 else if (token
->type
== CPP_CLOSE_PAREN
)
21070 /* There are no parameters. */
21072 #ifndef NO_IMPLICIT_EXTERN_C
21073 if (in_system_header_at (input_location
)
21074 && current_class_type
== NULL
21075 && current_lang_name
== lang_name_c
)
21079 return void_list_node
;
21081 /* Check for `(void)', too, which is a special case. */
21082 else if (token
->keyword
== RID_VOID
21083 && (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
21084 == CPP_CLOSE_PAREN
))
21086 /* Consume the `void' token. */
21087 cp_lexer_consume_token (parser
->lexer
);
21088 /* There are no parameters. */
21089 return void_list_node
;
21092 /* Parse the parameter-declaration-list. */
21093 parameters
= cp_parser_parameter_declaration_list (parser
, &is_error
);
21094 /* If a parse error occurred while parsing the
21095 parameter-declaration-list, then the entire
21096 parameter-declaration-clause is erroneous. */
21100 /* Peek at the next token. */
21101 token
= cp_lexer_peek_token (parser
->lexer
);
21102 /* If it's a `,', the clause should terminate with an ellipsis. */
21103 if (token
->type
== CPP_COMMA
)
21105 /* Consume the `,'. */
21106 cp_lexer_consume_token (parser
->lexer
);
21107 /* Expect an ellipsis. */
21109 = (cp_parser_require (parser
, CPP_ELLIPSIS
, RT_ELLIPSIS
) != NULL
);
21111 /* It might also be `...' if the optional trailing `,' was
21113 else if (token
->type
== CPP_ELLIPSIS
)
21115 /* Consume the `...' token. */
21116 cp_lexer_consume_token (parser
->lexer
);
21117 /* And remember that we saw it. */
21121 ellipsis_p
= false;
21123 /* Finish the parameter list. */
21125 parameters
= chainon (parameters
, void_list_node
);
21130 /* Parse a parameter-declaration-list.
21132 parameter-declaration-list:
21133 parameter-declaration
21134 parameter-declaration-list , parameter-declaration
21136 Returns a representation of the parameter-declaration-list, as for
21137 cp_parser_parameter_declaration_clause. However, the
21138 `void_list_node' is never appended to the list. Upon return,
21139 *IS_ERROR will be true iff an error occurred. */
21142 cp_parser_parameter_declaration_list (cp_parser
* parser
, bool *is_error
)
21144 tree parameters
= NULL_TREE
;
21145 tree
*tail
= ¶meters
;
21146 bool saved_in_unbraced_linkage_specification_p
;
21149 /* Assume all will go well. */
21151 /* The special considerations that apply to a function within an
21152 unbraced linkage specifications do not apply to the parameters
21153 to the function. */
21154 saved_in_unbraced_linkage_specification_p
21155 = parser
->in_unbraced_linkage_specification_p
;
21156 parser
->in_unbraced_linkage_specification_p
= false;
21158 /* Look for more parameters. */
21161 cp_parameter_declarator
*parameter
;
21162 tree decl
= error_mark_node
;
21163 bool parenthesized_p
= false;
21164 int template_parm_idx
= (function_being_declared_is_template_p (parser
)?
21165 TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS
21166 (current_template_parms
)) : 0);
21168 /* Parse the parameter. */
21170 = cp_parser_parameter_declaration (parser
,
21171 /*template_parm_p=*/false,
21174 /* We don't know yet if the enclosing context is deprecated, so wait
21175 and warn in grokparms if appropriate. */
21176 deprecated_state
= DEPRECATED_SUPPRESS
;
21180 /* If a function parameter pack was specified and an implicit template
21181 parameter was introduced during cp_parser_parameter_declaration,
21182 change any implicit parameters introduced into packs. */
21183 if (parser
->implicit_template_parms
21184 && parameter
->declarator
21185 && parameter
->declarator
->parameter_pack_p
)
21187 int latest_template_parm_idx
= TREE_VEC_LENGTH
21188 (INNERMOST_TEMPLATE_PARMS (current_template_parms
));
21190 if (latest_template_parm_idx
!= template_parm_idx
)
21191 parameter
->decl_specifiers
.type
= convert_generic_types_to_packs
21192 (parameter
->decl_specifiers
.type
,
21193 template_parm_idx
, latest_template_parm_idx
);
21196 decl
= grokdeclarator (parameter
->declarator
,
21197 ¶meter
->decl_specifiers
,
21199 parameter
->default_argument
!= NULL_TREE
,
21200 ¶meter
->decl_specifiers
.attributes
);
21203 deprecated_state
= DEPRECATED_NORMAL
;
21205 /* If a parse error occurred parsing the parameter declaration,
21206 then the entire parameter-declaration-list is erroneous. */
21207 if (decl
== error_mark_node
)
21210 parameters
= error_mark_node
;
21214 if (parameter
->decl_specifiers
.attributes
)
21215 cplus_decl_attributes (&decl
,
21216 parameter
->decl_specifiers
.attributes
,
21218 if (DECL_NAME (decl
))
21219 decl
= pushdecl (decl
);
21221 if (decl
!= error_mark_node
)
21223 retrofit_lang_decl (decl
);
21224 DECL_PARM_INDEX (decl
) = ++index
;
21225 DECL_PARM_LEVEL (decl
) = function_parm_depth ();
21228 /* Add the new parameter to the list. */
21229 *tail
= build_tree_list (parameter
->default_argument
, decl
);
21230 tail
= &TREE_CHAIN (*tail
);
21232 /* Peek at the next token. */
21233 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_PAREN
)
21234 || cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
)
21235 /* These are for Objective-C++ */
21236 || cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
)
21237 || cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
21238 /* The parameter-declaration-list is complete. */
21240 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
21244 /* Peek at the next token. */
21245 token
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
21246 /* If it's an ellipsis, then the list is complete. */
21247 if (token
->type
== CPP_ELLIPSIS
)
21249 /* Otherwise, there must be more parameters. Consume the
21251 cp_lexer_consume_token (parser
->lexer
);
21252 /* When parsing something like:
21254 int i(float f, double d)
21256 we can tell after seeing the declaration for "f" that we
21257 are not looking at an initialization of a variable "i",
21258 but rather at the declaration of a function "i".
21260 Due to the fact that the parsing of template arguments
21261 (as specified to a template-id) requires backtracking we
21262 cannot use this technique when inside a template argument
21264 if (!parser
->in_template_argument_list_p
21265 && !parser
->in_type_id_in_expr_p
21266 && cp_parser_uncommitted_to_tentative_parse_p (parser
)
21267 /* However, a parameter-declaration of the form
21268 "float(f)" (which is a valid declaration of a
21269 parameter "f") can also be interpreted as an
21270 expression (the conversion of "f" to "float"). */
21271 && !parenthesized_p
)
21272 cp_parser_commit_to_tentative_parse (parser
);
21276 cp_parser_error (parser
, "expected %<,%> or %<...%>");
21277 if (!cp_parser_uncommitted_to_tentative_parse_p (parser
))
21278 cp_parser_skip_to_closing_parenthesis (parser
,
21279 /*recovering=*/true,
21280 /*or_comma=*/false,
21281 /*consume_paren=*/false);
21286 parser
->in_unbraced_linkage_specification_p
21287 = saved_in_unbraced_linkage_specification_p
;
21289 /* Reset implicit_template_scope if we are about to leave the function
21290 parameter list that introduced it. Note that for out-of-line member
21291 definitions, there will be one or more class scopes before we get to
21292 the template parameter scope. */
21294 if (cp_binding_level
*its
= parser
->implicit_template_scope
)
21295 if (cp_binding_level
*maybe_its
= current_binding_level
->level_chain
)
21297 while (maybe_its
->kind
== sk_class
)
21298 maybe_its
= maybe_its
->level_chain
;
21299 if (maybe_its
== its
)
21301 parser
->implicit_template_parms
= 0;
21302 parser
->implicit_template_scope
= 0;
21309 /* Parse a parameter declaration.
21311 parameter-declaration:
21312 decl-specifier-seq ... [opt] declarator
21313 decl-specifier-seq declarator = assignment-expression
21314 decl-specifier-seq ... [opt] abstract-declarator [opt]
21315 decl-specifier-seq abstract-declarator [opt] = assignment-expression
21317 If TEMPLATE_PARM_P is TRUE, then this parameter-declaration
21318 declares a template parameter. (In that case, a non-nested `>'
21319 token encountered during the parsing of the assignment-expression
21320 is not interpreted as a greater-than operator.)
21322 Returns a representation of the parameter, or NULL if an error
21323 occurs. If PARENTHESIZED_P is non-NULL, *PARENTHESIZED_P is set to
21324 true iff the declarator is of the form "(p)". */
21326 static cp_parameter_declarator
*
21327 cp_parser_parameter_declaration (cp_parser
*parser
,
21328 bool template_parm_p
,
21329 bool *parenthesized_p
)
21331 int declares_class_or_enum
;
21332 cp_decl_specifier_seq decl_specifiers
;
21333 cp_declarator
*declarator
;
21334 tree default_argument
;
21335 cp_token
*token
= NULL
, *declarator_token_start
= NULL
;
21336 const char *saved_message
;
21337 bool template_parameter_pack_p
= false;
21339 /* In a template parameter, `>' is not an operator.
21343 When parsing a default template-argument for a non-type
21344 template-parameter, the first non-nested `>' is taken as the end
21345 of the template parameter-list rather than a greater-than
21348 /* Type definitions may not appear in parameter types. */
21349 saved_message
= parser
->type_definition_forbidden_message
;
21350 parser
->type_definition_forbidden_message
21351 = G_("types may not be defined in parameter types");
21353 /* Parse the declaration-specifiers. */
21354 cp_parser_decl_specifier_seq (parser
,
21355 CP_PARSER_FLAGS_NONE
,
21357 &declares_class_or_enum
);
21359 /* Complain about missing 'typename' or other invalid type names. */
21360 if (!decl_specifiers
.any_type_specifiers_p
21361 && cp_parser_parse_and_diagnose_invalid_type_name (parser
))
21362 decl_specifiers
.type
= error_mark_node
;
21364 /* If an error occurred, there's no reason to attempt to parse the
21365 rest of the declaration. */
21366 if (cp_parser_error_occurred (parser
))
21368 parser
->type_definition_forbidden_message
= saved_message
;
21372 /* Peek at the next token. */
21373 token
= cp_lexer_peek_token (parser
->lexer
);
21375 /* If the next token is a `)', `,', `=', `>', or `...', then there
21376 is no declarator. However, when variadic templates are enabled,
21377 there may be a declarator following `...'. */
21378 if (token
->type
== CPP_CLOSE_PAREN
21379 || token
->type
== CPP_COMMA
21380 || token
->type
== CPP_EQ
21381 || token
->type
== CPP_GREATER
)
21384 if (parenthesized_p
)
21385 *parenthesized_p
= false;
21387 /* Otherwise, there should be a declarator. */
21390 bool saved_default_arg_ok_p
= parser
->default_arg_ok_p
;
21391 parser
->default_arg_ok_p
= false;
21393 /* After seeing a decl-specifier-seq, if the next token is not a
21394 "(", there is no possibility that the code is a valid
21395 expression. Therefore, if parsing tentatively, we commit at
21397 if (!parser
->in_template_argument_list_p
21398 /* In an expression context, having seen:
21402 we cannot be sure whether we are looking at a
21403 function-type (taking a "char" as a parameter) or a cast
21404 of some object of type "char" to "int". */
21405 && !parser
->in_type_id_in_expr_p
21406 && cp_parser_uncommitted_to_tentative_parse_p (parser
)
21407 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_BRACE
)
21408 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_PAREN
))
21409 cp_parser_commit_to_tentative_parse (parser
);
21410 /* Parse the declarator. */
21411 declarator_token_start
= token
;
21412 declarator
= cp_parser_declarator (parser
,
21413 CP_PARSER_DECLARATOR_EITHER
,
21414 /*ctor_dtor_or_conv_p=*/NULL
,
21416 /*member_p=*/false,
21417 /*friend_p=*/false);
21418 parser
->default_arg_ok_p
= saved_default_arg_ok_p
;
21419 /* After the declarator, allow more attributes. */
21420 decl_specifiers
.attributes
21421 = chainon (decl_specifiers
.attributes
,
21422 cp_parser_attributes_opt (parser
));
21424 /* If the declarator is a template parameter pack, remember that and
21425 clear the flag in the declarator itself so we don't get errors
21426 from grokdeclarator. */
21427 if (template_parm_p
&& declarator
&& declarator
->parameter_pack_p
)
21429 declarator
->parameter_pack_p
= false;
21430 template_parameter_pack_p
= true;
21434 /* If the next token is an ellipsis, and we have not seen a declarator
21435 name, and if either the type of the declarator contains parameter
21436 packs but it is not a TYPE_PACK_EXPANSION or is null (this happens
21437 for, eg, abbreviated integral type names), then we actually have a
21438 parameter pack expansion expression. Otherwise, leave the ellipsis
21439 for a C-style variadic function. */
21440 token
= cp_lexer_peek_token (parser
->lexer
);
21441 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
21443 tree type
= decl_specifiers
.type
;
21445 if (type
&& DECL_P (type
))
21446 type
= TREE_TYPE (type
);
21449 && TREE_CODE (type
) != TYPE_PACK_EXPANSION
21450 && (template_parm_p
|| uses_parameter_packs (type
)))
21451 || (!type
&& template_parm_p
))
21452 && declarator_can_be_parameter_pack (declarator
))
21454 /* Consume the `...'. */
21455 cp_lexer_consume_token (parser
->lexer
);
21456 maybe_warn_variadic_templates ();
21458 /* Build a pack expansion type */
21459 if (template_parm_p
)
21460 template_parameter_pack_p
= true;
21461 else if (declarator
)
21462 declarator
->parameter_pack_p
= true;
21464 decl_specifiers
.type
= make_pack_expansion (type
);
21468 /* The restriction on defining new types applies only to the type
21469 of the parameter, not to the default argument. */
21470 parser
->type_definition_forbidden_message
= saved_message
;
21472 /* If the next token is `=', then process a default argument. */
21473 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
))
21475 tree type
= decl_specifiers
.type
;
21476 token
= cp_lexer_peek_token (parser
->lexer
);
21477 /* If we are defining a class, then the tokens that make up the
21478 default argument must be saved and processed later. */
21479 if (!template_parm_p
&& at_class_scope_p ()
21480 && TYPE_BEING_DEFINED (current_class_type
)
21481 && !LAMBDA_TYPE_P (current_class_type
))
21482 default_argument
= cp_parser_cache_defarg (parser
, /*nsdmi=*/false);
21484 // A constrained-type-specifier may declare a type template-parameter.
21485 else if (declares_constrained_type_template_parameter (type
))
21487 = cp_parser_default_type_template_argument (parser
);
21489 // A constrained-type-specifier may declare a template-template-parameter.
21490 else if (declares_constrained_template_template_parameter (type
))
21492 = cp_parser_default_template_template_argument (parser
);
21494 /* Outside of a class definition, we can just parse the
21495 assignment-expression. */
21498 = cp_parser_default_argument (parser
, template_parm_p
);
21500 if (!parser
->default_arg_ok_p
)
21502 permerror (token
->location
,
21503 "default arguments are only "
21504 "permitted for function parameters");
21506 else if ((declarator
&& declarator
->parameter_pack_p
)
21507 || template_parameter_pack_p
21508 || (decl_specifiers
.type
21509 && PACK_EXPANSION_P (decl_specifiers
.type
)))
21511 /* Find the name of the parameter pack. */
21512 cp_declarator
*id_declarator
= declarator
;
21513 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
21514 id_declarator
= id_declarator
->declarator
;
21516 if (id_declarator
&& id_declarator
->kind
== cdk_id
)
21517 error_at (declarator_token_start
->location
,
21519 ? G_("template parameter pack %qD "
21520 "cannot have a default argument")
21521 : G_("parameter pack %qD cannot have "
21522 "a default argument"),
21523 id_declarator
->u
.id
.unqualified_name
);
21525 error_at (declarator_token_start
->location
,
21527 ? G_("template parameter pack cannot have "
21528 "a default argument")
21529 : G_("parameter pack cannot have a "
21530 "default argument"));
21532 default_argument
= NULL_TREE
;
21536 default_argument
= NULL_TREE
;
21538 return make_parameter_declarator (&decl_specifiers
,
21541 template_parameter_pack_p
);
21544 /* Parse a default argument and return it.
21546 TEMPLATE_PARM_P is true if this is a default argument for a
21547 non-type template parameter. */
21549 cp_parser_default_argument (cp_parser
*parser
, bool template_parm_p
)
21551 tree default_argument
= NULL_TREE
;
21552 bool saved_greater_than_is_operator_p
;
21553 bool saved_local_variables_forbidden_p
;
21554 bool non_constant_p
, is_direct_init
;
21556 /* Make sure that PARSER->GREATER_THAN_IS_OPERATOR_P is
21558 saved_greater_than_is_operator_p
= parser
->greater_than_is_operator_p
;
21559 parser
->greater_than_is_operator_p
= !template_parm_p
;
21560 /* Local variable names (and the `this' keyword) may not
21561 appear in a default argument. */
21562 saved_local_variables_forbidden_p
= parser
->local_variables_forbidden_p
;
21563 parser
->local_variables_forbidden_p
= true;
21564 /* Parse the assignment-expression. */
21565 if (template_parm_p
)
21566 push_deferring_access_checks (dk_no_deferred
);
21567 tree saved_class_ptr
= NULL_TREE
;
21568 tree saved_class_ref
= NULL_TREE
;
21569 /* The "this" pointer is not valid in a default argument. */
21572 saved_class_ptr
= current_class_ptr
;
21573 cp_function_chain
->x_current_class_ptr
= NULL_TREE
;
21574 saved_class_ref
= current_class_ref
;
21575 cp_function_chain
->x_current_class_ref
= NULL_TREE
;
21578 = cp_parser_initializer (parser
, &is_direct_init
, &non_constant_p
);
21579 /* Restore the "this" pointer. */
21582 cp_function_chain
->x_current_class_ptr
= saved_class_ptr
;
21583 cp_function_chain
->x_current_class_ref
= saved_class_ref
;
21585 if (BRACE_ENCLOSED_INITIALIZER_P (default_argument
))
21586 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
21587 if (template_parm_p
)
21588 pop_deferring_access_checks ();
21589 parser
->greater_than_is_operator_p
= saved_greater_than_is_operator_p
;
21590 parser
->local_variables_forbidden_p
= saved_local_variables_forbidden_p
;
21592 return default_argument
;
21595 /* Parse a function-body.
21598 compound_statement */
21601 cp_parser_function_body (cp_parser
*parser
, bool in_function_try_block
)
21603 cp_parser_compound_statement (parser
, NULL
, (in_function_try_block
21604 ? BCS_TRY_BLOCK
: BCS_NORMAL
),
21608 /* Parse a ctor-initializer-opt followed by a function-body. Return
21609 true if a ctor-initializer was present. When IN_FUNCTION_TRY_BLOCK
21610 is true we are parsing a function-try-block. */
21613 cp_parser_ctor_initializer_opt_and_function_body (cp_parser
*parser
,
21614 bool in_function_try_block
)
21617 bool ctor_initializer_p
;
21618 const bool check_body_p
=
21619 DECL_CONSTRUCTOR_P (current_function_decl
)
21620 && DECL_DECLARED_CONSTEXPR_P (current_function_decl
);
21623 /* Begin the function body. */
21624 body
= begin_function_body ();
21625 /* Parse the optional ctor-initializer. */
21626 ctor_initializer_p
= cp_parser_ctor_initializer_opt (parser
);
21628 /* If we're parsing a constexpr constructor definition, we need
21629 to check that the constructor body is indeed empty. However,
21630 before we get to cp_parser_function_body lot of junk has been
21631 generated, so we can't just check that we have an empty block.
21632 Rather we take a snapshot of the outermost block, and check whether
21633 cp_parser_function_body changed its state. */
21636 list
= cur_stmt_list
;
21637 if (STATEMENT_LIST_TAIL (list
))
21638 last
= STATEMENT_LIST_TAIL (list
)->stmt
;
21640 /* Parse the function-body. */
21641 cp_parser_function_body (parser
, in_function_try_block
);
21643 check_constexpr_ctor_body (last
, list
, /*complain=*/true);
21644 /* Finish the function body. */
21645 finish_function_body (body
);
21647 return ctor_initializer_p
;
21650 /* Parse an initializer.
21653 = initializer-clause
21654 ( expression-list )
21656 Returns an expression representing the initializer. If no
21657 initializer is present, NULL_TREE is returned.
21659 *IS_DIRECT_INIT is set to FALSE if the `= initializer-clause'
21660 production is used, and TRUE otherwise. *IS_DIRECT_INIT is
21661 set to TRUE if there is no initializer present. If there is an
21662 initializer, and it is not a constant-expression, *NON_CONSTANT_P
21663 is set to true; otherwise it is set to false. */
21666 cp_parser_initializer (cp_parser
* parser
, bool* is_direct_init
,
21667 bool* non_constant_p
)
21672 /* Peek at the next token. */
21673 token
= cp_lexer_peek_token (parser
->lexer
);
21675 /* Let our caller know whether or not this initializer was
21677 *is_direct_init
= (token
->type
!= CPP_EQ
);
21678 /* Assume that the initializer is constant. */
21679 *non_constant_p
= false;
21681 if (token
->type
== CPP_EQ
)
21683 /* Consume the `='. */
21684 cp_lexer_consume_token (parser
->lexer
);
21685 /* Parse the initializer-clause. */
21686 init
= cp_parser_initializer_clause (parser
, non_constant_p
);
21688 else if (token
->type
== CPP_OPEN_PAREN
)
21690 vec
<tree
, va_gc
> *vec
;
21691 vec
= cp_parser_parenthesized_expression_list (parser
, non_attr
,
21693 /*allow_expansion_p=*/true,
21696 return error_mark_node
;
21697 init
= build_tree_list_vec (vec
);
21698 release_tree_vector (vec
);
21700 else if (token
->type
== CPP_OPEN_BRACE
)
21702 cp_lexer_set_source_position (parser
->lexer
);
21703 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
21704 init
= cp_parser_braced_list (parser
, non_constant_p
);
21705 CONSTRUCTOR_IS_DIRECT_INIT (init
) = 1;
21709 /* Anything else is an error. */
21710 cp_parser_error (parser
, "expected initializer");
21711 init
= error_mark_node
;
21714 if (check_for_bare_parameter_packs (init
))
21715 init
= error_mark_node
;
21720 /* Parse an initializer-clause.
21722 initializer-clause:
21723 assignment-expression
21726 Returns an expression representing the initializer.
21728 If the `assignment-expression' production is used the value
21729 returned is simply a representation for the expression.
21731 Otherwise, calls cp_parser_braced_list. */
21734 cp_parser_initializer_clause (cp_parser
* parser
, bool* non_constant_p
)
21736 cp_expr initializer
;
21738 /* Assume the expression is constant. */
21739 *non_constant_p
= false;
21741 /* If it is not a `{', then we are looking at an
21742 assignment-expression. */
21743 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_BRACE
))
21746 = cp_parser_constant_expression (parser
,
21747 /*allow_non_constant_p=*/true,
21751 initializer
= cp_parser_braced_list (parser
, non_constant_p
);
21753 return initializer
;
21756 /* Parse a brace-enclosed initializer list.
21759 { initializer-list , [opt] }
21762 Returns a CONSTRUCTOR. The CONSTRUCTOR_ELTS will be
21763 the elements of the initializer-list (or NULL, if the last
21764 production is used). The TREE_TYPE for the CONSTRUCTOR will be
21765 NULL_TREE. There is no way to detect whether or not the optional
21766 trailing `,' was provided. NON_CONSTANT_P is as for
21767 cp_parser_initializer. */
21770 cp_parser_braced_list (cp_parser
* parser
, bool* non_constant_p
)
21773 location_t start_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
21775 /* Consume the `{' token. */
21776 cp_lexer_consume_token (parser
->lexer
);
21777 /* Create a CONSTRUCTOR to represent the braced-initializer. */
21778 initializer
= make_node (CONSTRUCTOR
);
21779 /* If it's not a `}', then there is a non-trivial initializer. */
21780 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_BRACE
))
21782 /* Parse the initializer list. */
21783 CONSTRUCTOR_ELTS (initializer
)
21784 = cp_parser_initializer_list (parser
, non_constant_p
);
21785 /* A trailing `,' token is allowed. */
21786 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
21787 cp_lexer_consume_token (parser
->lexer
);
21790 *non_constant_p
= false;
21791 /* Now, there should be a trailing `}'. */
21792 location_t finish_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
21793 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
21794 TREE_TYPE (initializer
) = init_list_type_node
;
21796 cp_expr
result (initializer
);
21797 /* Build a location of the form:
21800 with caret==start at the open brace, finish at the close brace. */
21801 location_t combined_loc
= make_location (start_loc
, start_loc
, finish_loc
);
21802 result
.set_location (combined_loc
);
21806 /* Consume tokens up to, and including, the next non-nested closing `]'.
21807 Returns true iff we found a closing `]'. */
21810 cp_parser_skip_to_closing_square_bracket (cp_parser
*parser
)
21812 unsigned square_depth
= 0;
21816 cp_token
* token
= cp_lexer_peek_token (parser
->lexer
);
21818 switch (token
->type
)
21821 case CPP_PRAGMA_EOL
:
21822 /* If we've run out of tokens, then there is no closing `]'. */
21825 case CPP_OPEN_SQUARE
:
21829 case CPP_CLOSE_SQUARE
:
21830 if (!square_depth
--)
21832 cp_lexer_consume_token (parser
->lexer
);
21841 /* Consume the token. */
21842 cp_lexer_consume_token (parser
->lexer
);
21846 /* Return true if we are looking at an array-designator, false otherwise. */
21849 cp_parser_array_designator_p (cp_parser
*parser
)
21851 /* Consume the `['. */
21852 cp_lexer_consume_token (parser
->lexer
);
21854 cp_lexer_save_tokens (parser
->lexer
);
21856 /* Skip tokens until the next token is a closing square bracket.
21857 If we find the closing `]', and the next token is a `=', then
21858 we are looking at an array designator. */
21859 bool array_designator_p
21860 = (cp_parser_skip_to_closing_square_bracket (parser
)
21861 && cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
));
21863 /* Roll back the tokens we skipped. */
21864 cp_lexer_rollback_tokens (parser
->lexer
);
21866 return array_designator_p
;
21869 /* Parse an initializer-list.
21872 initializer-clause ... [opt]
21873 initializer-list , initializer-clause ... [opt]
21878 designation initializer-clause ...[opt]
21879 initializer-list , designation initializer-clause ...[opt]
21884 [ constant-expression ] =
21886 Returns a vec of constructor_elt. The VALUE of each elt is an expression
21887 for the initializer. If the INDEX of the elt is non-NULL, it is the
21888 IDENTIFIER_NODE naming the field to initialize. NON_CONSTANT_P is
21889 as for cp_parser_initializer. */
21891 static vec
<constructor_elt
, va_gc
> *
21892 cp_parser_initializer_list (cp_parser
* parser
, bool* non_constant_p
)
21894 vec
<constructor_elt
, va_gc
> *v
= NULL
;
21896 /* Assume all of the expressions are constant. */
21897 *non_constant_p
= false;
21899 /* Parse the rest of the list. */
21905 bool clause_non_constant_p
;
21907 /* If the next token is an identifier and the following one is a
21908 colon, we are looking at the GNU designated-initializer
21910 if (cp_parser_allow_gnu_extensions_p (parser
)
21911 && cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
)
21912 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_COLON
)
21914 /* Warn the user that they are using an extension. */
21915 pedwarn (input_location
, OPT_Wpedantic
,
21916 "ISO C++ does not allow designated initializers");
21917 /* Consume the identifier. */
21918 designator
= cp_lexer_consume_token (parser
->lexer
)->u
.value
;
21919 /* Consume the `:'. */
21920 cp_lexer_consume_token (parser
->lexer
);
21922 /* Also handle the C99 syntax, '. id ='. */
21923 else if (cp_parser_allow_gnu_extensions_p (parser
)
21924 && cp_lexer_next_token_is (parser
->lexer
, CPP_DOT
)
21925 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_NAME
21926 && cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
== CPP_EQ
)
21928 /* Warn the user that they are using an extension. */
21929 pedwarn (input_location
, OPT_Wpedantic
,
21930 "ISO C++ does not allow C99 designated initializers");
21931 /* Consume the `.'. */
21932 cp_lexer_consume_token (parser
->lexer
);
21933 /* Consume the identifier. */
21934 designator
= cp_lexer_consume_token (parser
->lexer
)->u
.value
;
21935 /* Consume the `='. */
21936 cp_lexer_consume_token (parser
->lexer
);
21938 /* Also handle C99 array designators, '[ const ] ='. */
21939 else if (cp_parser_allow_gnu_extensions_p (parser
)
21940 && !c_dialect_objc ()
21941 && cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_SQUARE
))
21943 /* In C++11, [ could start a lambda-introducer. */
21944 bool non_const
= false;
21946 cp_parser_parse_tentatively (parser
);
21948 if (!cp_parser_array_designator_p (parser
))
21950 cp_parser_simulate_error (parser
);
21951 designator
= NULL_TREE
;
21955 designator
= cp_parser_constant_expression (parser
, true,
21957 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
21958 cp_parser_require (parser
, CPP_EQ
, RT_EQ
);
21961 if (!cp_parser_parse_definitely (parser
))
21962 designator
= NULL_TREE
;
21963 else if (non_const
)
21964 require_potential_rvalue_constant_expression (designator
);
21967 designator
= NULL_TREE
;
21969 /* Parse the initializer. */
21970 initializer
= cp_parser_initializer_clause (parser
,
21971 &clause_non_constant_p
);
21972 /* If any clause is non-constant, so is the entire initializer. */
21973 if (clause_non_constant_p
)
21974 *non_constant_p
= true;
21976 /* If we have an ellipsis, this is an initializer pack
21978 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
21980 /* Consume the `...'. */
21981 cp_lexer_consume_token (parser
->lexer
);
21983 /* Turn the initializer into an initializer expansion. */
21984 initializer
= make_pack_expansion (initializer
);
21987 /* Add it to the vector. */
21988 CONSTRUCTOR_APPEND_ELT (v
, designator
, initializer
);
21990 /* If the next token is not a comma, we have reached the end of
21992 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
21995 /* Peek at the next token. */
21996 token
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
21997 /* If the next token is a `}', then we're still done. An
21998 initializer-clause can have a trailing `,' after the
21999 initializer-list and before the closing `}'. */
22000 if (token
->type
== CPP_CLOSE_BRACE
)
22003 /* Consume the `,' token. */
22004 cp_lexer_consume_token (parser
->lexer
);
22010 /* Classes [gram.class] */
22012 /* Parse a class-name.
22018 TYPENAME_KEYWORD_P is true iff the `typename' keyword has been used
22019 to indicate that names looked up in dependent types should be
22020 assumed to be types. TEMPLATE_KEYWORD_P is true iff the `template'
22021 keyword has been used to indicate that the name that appears next
22022 is a template. TAG_TYPE indicates the explicit tag given before
22023 the type name, if any. If CHECK_DEPENDENCY_P is FALSE, names are
22024 looked up in dependent scopes. If CLASS_HEAD_P is TRUE, this class
22025 is the class being defined in a class-head. If ENUM_OK is TRUE,
22026 enum-names are also accepted.
22028 Returns the TYPE_DECL representing the class. */
22031 cp_parser_class_name (cp_parser
*parser
,
22032 bool typename_keyword_p
,
22033 bool template_keyword_p
,
22034 enum tag_types tag_type
,
22035 bool check_dependency_p
,
22037 bool is_declaration
,
22044 tree identifier
= NULL_TREE
;
22046 /* All class-names start with an identifier. */
22047 token
= cp_lexer_peek_token (parser
->lexer
);
22048 if (token
->type
!= CPP_NAME
&& token
->type
!= CPP_TEMPLATE_ID
)
22050 cp_parser_error (parser
, "expected class-name");
22051 return error_mark_node
;
22054 /* PARSER->SCOPE can be cleared when parsing the template-arguments
22055 to a template-id, so we save it here. */
22056 scope
= parser
->scope
;
22057 if (scope
== error_mark_node
)
22058 return error_mark_node
;
22060 /* Any name names a type if we're following the `typename' keyword
22061 in a qualified name where the enclosing scope is type-dependent. */
22062 typename_p
= (typename_keyword_p
&& scope
&& TYPE_P (scope
)
22063 && dependent_type_p (scope
));
22064 /* Handle the common case (an identifier, but not a template-id)
22066 if (token
->type
== CPP_NAME
22067 && !cp_parser_nth_token_starts_template_argument_list_p (parser
, 2))
22069 cp_token
*identifier_token
;
22072 /* Look for the identifier. */
22073 identifier_token
= cp_lexer_peek_token (parser
->lexer
);
22074 ambiguous_p
= identifier_token
->error_reported
;
22075 identifier
= cp_parser_identifier (parser
);
22076 /* If the next token isn't an identifier, we are certainly not
22077 looking at a class-name. */
22078 if (identifier
== error_mark_node
)
22079 decl
= error_mark_node
;
22080 /* If we know this is a type-name, there's no need to look it
22082 else if (typename_p
)
22086 tree ambiguous_decls
;
22087 /* If we already know that this lookup is ambiguous, then
22088 we've already issued an error message; there's no reason
22092 cp_parser_simulate_error (parser
);
22093 return error_mark_node
;
22095 /* If the next token is a `::', then the name must be a type
22098 [basic.lookup.qual]
22100 During the lookup for a name preceding the :: scope
22101 resolution operator, object, function, and enumerator
22102 names are ignored. */
22103 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SCOPE
))
22104 tag_type
= scope_type
;
22105 /* Look up the name. */
22106 decl
= cp_parser_lookup_name (parser
, identifier
,
22108 /*is_template=*/false,
22109 /*is_namespace=*/false,
22110 check_dependency_p
,
22112 identifier_token
->location
);
22113 if (ambiguous_decls
)
22115 if (cp_parser_parsing_tentatively (parser
))
22116 cp_parser_simulate_error (parser
);
22117 return error_mark_node
;
22123 /* Try a template-id. */
22124 decl
= cp_parser_template_id (parser
, template_keyword_p
,
22125 check_dependency_p
,
22128 if (decl
== error_mark_node
)
22129 return error_mark_node
;
22132 decl
= cp_parser_maybe_treat_template_as_class (decl
, class_head_p
);
22134 /* If this is a typename, create a TYPENAME_TYPE. */
22135 if (typename_p
&& decl
!= error_mark_node
)
22137 decl
= make_typename_type (scope
, decl
, typename_type
,
22138 /*complain=*/tf_error
);
22139 if (decl
!= error_mark_node
)
22140 decl
= TYPE_NAME (decl
);
22143 decl
= strip_using_decl (decl
);
22145 /* Check to see that it is really the name of a class. */
22146 if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
22147 && identifier_p (TREE_OPERAND (decl
, 0))
22148 && cp_lexer_next_token_is (parser
->lexer
, CPP_SCOPE
))
22149 /* Situations like this:
22151 template <typename T> struct A {
22152 typename T::template X<int>::I i;
22155 are problematic. Is `T::template X<int>' a class-name? The
22156 standard does not seem to be definitive, but there is no other
22157 valid interpretation of the following `::'. Therefore, those
22158 names are considered class-names. */
22160 decl
= make_typename_type (scope
, decl
, tag_type
, tf_error
);
22161 if (decl
!= error_mark_node
)
22162 decl
= TYPE_NAME (decl
);
22164 else if (TREE_CODE (decl
) != TYPE_DECL
22165 || TREE_TYPE (decl
) == error_mark_node
22166 || !(MAYBE_CLASS_TYPE_P (TREE_TYPE (decl
))
22167 || (enum_ok
&& TREE_CODE (TREE_TYPE (decl
)) == ENUMERAL_TYPE
))
22168 /* In Objective-C 2.0, a classname followed by '.' starts a
22169 dot-syntax expression, and it's not a type-name. */
22170 || (c_dialect_objc ()
22171 && cp_lexer_peek_token (parser
->lexer
)->type
== CPP_DOT
22172 && objc_is_class_name (decl
)))
22173 decl
= error_mark_node
;
22175 if (decl
== error_mark_node
)
22176 cp_parser_error (parser
, "expected class-name");
22177 else if (identifier
&& !parser
->scope
)
22178 maybe_note_name_used_in_class (identifier
, decl
);
22183 /* Parse a class-specifier.
22186 class-head { member-specification [opt] }
22188 Returns the TREE_TYPE representing the class. */
22191 cp_parser_class_specifier_1 (cp_parser
* parser
)
22194 tree attributes
= NULL_TREE
;
22195 bool nested_name_specifier_p
;
22196 unsigned saved_num_template_parameter_lists
;
22197 bool saved_in_function_body
;
22198 unsigned char in_statement
;
22199 bool in_switch_statement_p
;
22200 bool saved_in_unbraced_linkage_specification_p
;
22201 tree old_scope
= NULL_TREE
;
22202 tree scope
= NULL_TREE
;
22203 cp_token
*closing_brace
;
22205 push_deferring_access_checks (dk_no_deferred
);
22207 /* Parse the class-head. */
22208 type
= cp_parser_class_head (parser
,
22209 &nested_name_specifier_p
);
22210 /* If the class-head was a semantic disaster, skip the entire body
22214 cp_parser_skip_to_end_of_block_or_statement (parser
);
22215 pop_deferring_access_checks ();
22216 return error_mark_node
;
22219 /* Look for the `{'. */
22220 if (!cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
))
22222 pop_deferring_access_checks ();
22223 return error_mark_node
;
22226 cp_ensure_no_omp_declare_simd (parser
);
22227 cp_ensure_no_oacc_routine (parser
);
22229 /* Issue an error message if type-definitions are forbidden here. */
22230 cp_parser_check_type_definition (parser
);
22231 /* Remember that we are defining one more class. */
22232 ++parser
->num_classes_being_defined
;
22233 /* Inside the class, surrounding template-parameter-lists do not
22235 saved_num_template_parameter_lists
22236 = parser
->num_template_parameter_lists
;
22237 parser
->num_template_parameter_lists
= 0;
22238 /* We are not in a function body. */
22239 saved_in_function_body
= parser
->in_function_body
;
22240 parser
->in_function_body
= false;
22241 /* Or in a loop. */
22242 in_statement
= parser
->in_statement
;
22243 parser
->in_statement
= 0;
22244 /* Or in a switch. */
22245 in_switch_statement_p
= parser
->in_switch_statement_p
;
22246 parser
->in_switch_statement_p
= false;
22247 /* We are not immediately inside an extern "lang" block. */
22248 saved_in_unbraced_linkage_specification_p
22249 = parser
->in_unbraced_linkage_specification_p
;
22250 parser
->in_unbraced_linkage_specification_p
= false;
22252 // Associate constraints with the type.
22254 type
= associate_classtype_constraints (type
);
22256 /* Start the class. */
22257 if (nested_name_specifier_p
)
22259 scope
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (type
));
22260 old_scope
= push_inner_scope (scope
);
22262 type
= begin_class_definition (type
);
22264 if (type
== error_mark_node
)
22265 /* If the type is erroneous, skip the entire body of the class. */
22266 cp_parser_skip_to_closing_brace (parser
);
22268 /* Parse the member-specification. */
22269 cp_parser_member_specification_opt (parser
);
22271 /* Look for the trailing `}'. */
22272 closing_brace
= cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
22273 /* Look for trailing attributes to apply to this class. */
22274 if (cp_parser_allow_gnu_extensions_p (parser
))
22275 attributes
= cp_parser_gnu_attributes_opt (parser
);
22276 if (type
!= error_mark_node
)
22277 type
= finish_struct (type
, attributes
);
22278 if (nested_name_specifier_p
)
22279 pop_inner_scope (old_scope
, scope
);
22281 /* We've finished a type definition. Check for the common syntax
22282 error of forgetting a semicolon after the definition. We need to
22283 be careful, as we can't just check for not-a-semicolon and be done
22284 with it; the user might have typed:
22286 class X { } c = ...;
22287 class X { } *p = ...;
22289 and so forth. Instead, enumerate all the possible tokens that
22290 might follow this production; if we don't see one of them, then
22291 complain and silently insert the semicolon. */
22293 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
22294 bool want_semicolon
= true;
22296 if (cp_next_tokens_can_be_std_attribute_p (parser
))
22297 /* Don't try to parse c++11 attributes here. As per the
22298 grammar, that should be a task for
22299 cp_parser_decl_specifier_seq. */
22300 want_semicolon
= false;
22302 switch (token
->type
)
22305 case CPP_SEMICOLON
:
22308 case CPP_OPEN_PAREN
:
22309 case CPP_CLOSE_PAREN
:
22311 want_semicolon
= false;
22314 /* While it's legal for type qualifiers and storage class
22315 specifiers to follow type definitions in the grammar, only
22316 compiler testsuites contain code like that. Assume that if
22317 we see such code, then what we're really seeing is a case
22321 const <type> var = ...;
22326 static <type> func (...) ...
22328 i.e. the qualifier or specifier applies to the next
22329 declaration. To do so, however, we need to look ahead one
22330 more token to see if *that* token is a type specifier.
22332 This code could be improved to handle:
22335 static const <type> var = ...; */
22337 if (keyword_is_decl_specifier (token
->keyword
))
22339 cp_token
*lookahead
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
22341 /* Handling user-defined types here would be nice, but very
22344 = (lookahead
->type
== CPP_KEYWORD
22345 && keyword_begins_type_specifier (lookahead
->keyword
));
22352 /* If we don't have a type, then something is very wrong and we
22353 shouldn't try to do anything clever. Likewise for not seeing the
22355 if (closing_brace
&& TYPE_P (type
) && want_semicolon
)
22357 /* Locate the closing brace. */
22358 cp_token_position prev
22359 = cp_lexer_previous_token_position (parser
->lexer
);
22360 cp_token
*prev_token
= cp_lexer_token_at (parser
->lexer
, prev
);
22361 location_t loc
= prev_token
->location
;
22363 /* We want to suggest insertion of a ';' immediately *after* the
22364 closing brace, so, if we can, offset the location by 1 column. */
22365 location_t next_loc
= loc
;
22366 if (!linemap_location_from_macro_expansion_p (line_table
, loc
))
22367 next_loc
= linemap_position_for_loc_and_offset (line_table
, loc
, 1);
22369 rich_location
richloc (line_table
, next_loc
);
22371 /* If we successfully offset the location, suggest the fix-it. */
22372 if (next_loc
!= loc
)
22373 richloc
.add_fixit_insert_before (next_loc
, ";");
22375 if (CLASSTYPE_DECLARED_CLASS (type
))
22376 error_at_rich_loc (&richloc
,
22377 "expected %<;%> after class definition");
22378 else if (TREE_CODE (type
) == RECORD_TYPE
)
22379 error_at_rich_loc (&richloc
,
22380 "expected %<;%> after struct definition");
22381 else if (TREE_CODE (type
) == UNION_TYPE
)
22382 error_at_rich_loc (&richloc
,
22383 "expected %<;%> after union definition");
22385 gcc_unreachable ();
22387 /* Unget one token and smash it to look as though we encountered
22388 a semicolon in the input stream. */
22389 cp_lexer_set_token_position (parser
->lexer
, prev
);
22390 token
= cp_lexer_peek_token (parser
->lexer
);
22391 token
->type
= CPP_SEMICOLON
;
22392 token
->keyword
= RID_MAX
;
22396 /* If this class is not itself within the scope of another class,
22397 then we need to parse the bodies of all of the queued function
22398 definitions. Note that the queued functions defined in a class
22399 are not always processed immediately following the
22400 class-specifier for that class. Consider:
22403 struct B { void f() { sizeof (A); } };
22406 If `f' were processed before the processing of `A' were
22407 completed, there would be no way to compute the size of `A'.
22408 Note that the nesting we are interested in here is lexical --
22409 not the semantic nesting given by TYPE_CONTEXT. In particular,
22412 struct A { struct B; };
22413 struct A::B { void f() { } };
22415 there is no need to delay the parsing of `A::B::f'. */
22416 if (--parser
->num_classes_being_defined
== 0)
22419 tree class_type
= NULL_TREE
;
22420 tree pushed_scope
= NULL_TREE
;
22422 cp_default_arg_entry
*e
;
22423 tree save_ccp
, save_ccr
;
22425 /* In a first pass, parse default arguments to the functions.
22426 Then, in a second pass, parse the bodies of the functions.
22427 This two-phased approach handles cases like:
22435 FOR_EACH_VEC_SAFE_ELT (unparsed_funs_with_default_args
, ix
, e
)
22438 /* If there are default arguments that have not yet been processed,
22439 take care of them now. */
22440 if (class_type
!= e
->class_type
)
22443 pop_scope (pushed_scope
);
22444 class_type
= e
->class_type
;
22445 pushed_scope
= push_scope (class_type
);
22447 /* Make sure that any template parameters are in scope. */
22448 maybe_begin_member_template_processing (decl
);
22449 /* Parse the default argument expressions. */
22450 cp_parser_late_parsing_default_args (parser
, decl
);
22451 /* Remove any template parameters from the symbol table. */
22452 maybe_end_member_template_processing ();
22454 vec_safe_truncate (unparsed_funs_with_default_args
, 0);
22455 /* Now parse any NSDMIs. */
22456 save_ccp
= current_class_ptr
;
22457 save_ccr
= current_class_ref
;
22458 FOR_EACH_VEC_SAFE_ELT (unparsed_nsdmis
, ix
, decl
)
22460 if (class_type
!= DECL_CONTEXT (decl
))
22463 pop_scope (pushed_scope
);
22464 class_type
= DECL_CONTEXT (decl
);
22465 pushed_scope
= push_scope (class_type
);
22467 inject_this_parameter (class_type
, TYPE_UNQUALIFIED
);
22468 cp_parser_late_parsing_nsdmi (parser
, decl
);
22470 vec_safe_truncate (unparsed_nsdmis
, 0);
22471 current_class_ptr
= save_ccp
;
22472 current_class_ref
= save_ccr
;
22474 pop_scope (pushed_scope
);
22476 /* Now do some post-NSDMI bookkeeping. */
22477 FOR_EACH_VEC_SAFE_ELT (unparsed_classes
, ix
, class_type
)
22478 after_nsdmi_defaulted_late_checks (class_type
);
22479 vec_safe_truncate (unparsed_classes
, 0);
22480 after_nsdmi_defaulted_late_checks (type
);
22482 /* Now parse the body of the functions. */
22485 /* OpenMP UDRs need to be parsed before all other functions. */
22486 FOR_EACH_VEC_SAFE_ELT (unparsed_funs_with_definitions
, ix
, decl
)
22487 if (DECL_OMP_DECLARE_REDUCTION_P (decl
))
22488 cp_parser_late_parsing_for_member (parser
, decl
);
22489 FOR_EACH_VEC_SAFE_ELT (unparsed_funs_with_definitions
, ix
, decl
)
22490 if (!DECL_OMP_DECLARE_REDUCTION_P (decl
))
22491 cp_parser_late_parsing_for_member (parser
, decl
);
22494 FOR_EACH_VEC_SAFE_ELT (unparsed_funs_with_definitions
, ix
, decl
)
22495 cp_parser_late_parsing_for_member (parser
, decl
);
22496 vec_safe_truncate (unparsed_funs_with_definitions
, 0);
22499 vec_safe_push (unparsed_classes
, type
);
22501 /* Put back any saved access checks. */
22502 pop_deferring_access_checks ();
22504 /* Restore saved state. */
22505 parser
->in_switch_statement_p
= in_switch_statement_p
;
22506 parser
->in_statement
= in_statement
;
22507 parser
->in_function_body
= saved_in_function_body
;
22508 parser
->num_template_parameter_lists
22509 = saved_num_template_parameter_lists
;
22510 parser
->in_unbraced_linkage_specification_p
22511 = saved_in_unbraced_linkage_specification_p
;
22517 cp_parser_class_specifier (cp_parser
* parser
)
22520 timevar_push (TV_PARSE_STRUCT
);
22521 ret
= cp_parser_class_specifier_1 (parser
);
22522 timevar_pop (TV_PARSE_STRUCT
);
22526 /* Parse a class-head.
22529 class-key identifier [opt] base-clause [opt]
22530 class-key nested-name-specifier identifier class-virt-specifier [opt] base-clause [opt]
22531 class-key nested-name-specifier [opt] template-id
22534 class-virt-specifier:
22538 class-key attributes identifier [opt] base-clause [opt]
22539 class-key attributes nested-name-specifier identifier base-clause [opt]
22540 class-key attributes nested-name-specifier [opt] template-id
22543 Upon return BASES is initialized to the list of base classes (or
22544 NULL, if there are none) in the same form returned by
22545 cp_parser_base_clause.
22547 Returns the TYPE of the indicated class. Sets
22548 *NESTED_NAME_SPECIFIER_P to TRUE iff one of the productions
22549 involving a nested-name-specifier was used, and FALSE otherwise.
22551 Returns error_mark_node if this is not a class-head.
22553 Returns NULL_TREE if the class-head is syntactically valid, but
22554 semantically invalid in a way that means we should skip the entire
22555 body of the class. */
22558 cp_parser_class_head (cp_parser
* parser
,
22559 bool* nested_name_specifier_p
)
22561 tree nested_name_specifier
;
22562 enum tag_types class_key
;
22563 tree id
= NULL_TREE
;
22564 tree type
= NULL_TREE
;
22567 cp_virt_specifiers virt_specifiers
= VIRT_SPEC_UNSPECIFIED
;
22568 bool template_id_p
= false;
22569 bool qualified_p
= false;
22570 bool invalid_nested_name_p
= false;
22571 bool invalid_explicit_specialization_p
= false;
22572 bool saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
22573 tree pushed_scope
= NULL_TREE
;
22574 unsigned num_templates
;
22575 cp_token
*type_start_token
= NULL
, *nested_name_specifier_token_start
= NULL
;
22576 /* Assume no nested-name-specifier will be present. */
22577 *nested_name_specifier_p
= false;
22578 /* Assume no template parameter lists will be used in defining the
22581 parser
->colon_corrects_to_scope_p
= false;
22583 /* Look for the class-key. */
22584 class_key
= cp_parser_class_key (parser
);
22585 if (class_key
== none_type
)
22586 return error_mark_node
;
22588 location_t class_head_start_location
= input_location
;
22590 /* Parse the attributes. */
22591 attributes
= cp_parser_attributes_opt (parser
);
22593 /* If the next token is `::', that is invalid -- but sometimes
22594 people do try to write:
22598 Handle this gracefully by accepting the extra qualifier, and then
22599 issuing an error about it later if this really is a
22600 class-head. If it turns out just to be an elaborated type
22601 specifier, remain silent. */
22602 if (cp_parser_global_scope_opt (parser
, /*current_scope_valid_p=*/false))
22603 qualified_p
= true;
22605 push_deferring_access_checks (dk_no_check
);
22607 /* Determine the name of the class. Begin by looking for an
22608 optional nested-name-specifier. */
22609 nested_name_specifier_token_start
= cp_lexer_peek_token (parser
->lexer
);
22610 nested_name_specifier
22611 = cp_parser_nested_name_specifier_opt (parser
,
22612 /*typename_keyword_p=*/false,
22613 /*check_dependency_p=*/false,
22615 /*is_declaration=*/false);
22616 /* If there was a nested-name-specifier, then there *must* be an
22619 cp_token
*bad_template_keyword
= NULL
;
22621 if (nested_name_specifier
)
22623 type_start_token
= cp_lexer_peek_token (parser
->lexer
);
22624 /* Although the grammar says `identifier', it really means
22625 `class-name' or `template-name'. You are only allowed to
22626 define a class that has already been declared with this
22629 The proposed resolution for Core Issue 180 says that wherever
22630 you see `class T::X' you should treat `X' as a type-name.
22632 It is OK to define an inaccessible class; for example:
22634 class A { class B; };
22637 We do not know if we will see a class-name, or a
22638 template-name. We look for a class-name first, in case the
22639 class-name is a template-id; if we looked for the
22640 template-name first we would stop after the template-name. */
22641 cp_parser_parse_tentatively (parser
);
22642 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TEMPLATE
))
22643 bad_template_keyword
= cp_lexer_consume_token (parser
->lexer
);
22644 type
= cp_parser_class_name (parser
,
22645 /*typename_keyword_p=*/false,
22646 /*template_keyword_p=*/false,
22648 /*check_dependency_p=*/false,
22649 /*class_head_p=*/true,
22650 /*is_declaration=*/false);
22651 /* If that didn't work, ignore the nested-name-specifier. */
22652 if (!cp_parser_parse_definitely (parser
))
22654 invalid_nested_name_p
= true;
22655 type_start_token
= cp_lexer_peek_token (parser
->lexer
);
22656 id
= cp_parser_identifier (parser
);
22657 if (id
== error_mark_node
)
22660 /* If we could not find a corresponding TYPE, treat this
22661 declaration like an unqualified declaration. */
22662 if (type
== error_mark_node
)
22663 nested_name_specifier
= NULL_TREE
;
22664 /* Otherwise, count the number of templates used in TYPE and its
22665 containing scopes. */
22670 for (scope
= TREE_TYPE (type
);
22671 scope
&& TREE_CODE (scope
) != NAMESPACE_DECL
;
22672 scope
= get_containing_scope (scope
))
22674 && CLASS_TYPE_P (scope
)
22675 && CLASSTYPE_TEMPLATE_INFO (scope
)
22676 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (scope
))
22677 && (!CLASSTYPE_TEMPLATE_SPECIALIZATION (scope
)
22678 || uses_template_parms (CLASSTYPE_TI_ARGS (scope
))))
22682 /* Otherwise, the identifier is optional. */
22685 /* We don't know whether what comes next is a template-id,
22686 an identifier, or nothing at all. */
22687 cp_parser_parse_tentatively (parser
);
22688 /* Check for a template-id. */
22689 type_start_token
= cp_lexer_peek_token (parser
->lexer
);
22690 id
= cp_parser_template_id (parser
,
22691 /*template_keyword_p=*/false,
22692 /*check_dependency_p=*/true,
22694 /*is_declaration=*/true);
22695 /* If that didn't work, it could still be an identifier. */
22696 if (!cp_parser_parse_definitely (parser
))
22698 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
22700 type_start_token
= cp_lexer_peek_token (parser
->lexer
);
22701 id
= cp_parser_identifier (parser
);
22708 template_id_p
= true;
22713 pop_deferring_access_checks ();
22717 cp_parser_check_for_invalid_template_id (parser
, id
,
22719 type_start_token
->location
);
22721 virt_specifiers
= cp_parser_virt_specifier_seq_opt (parser
);
22723 /* If it's not a `:' or a `{' then we can't really be looking at a
22724 class-head, since a class-head only appears as part of a
22725 class-specifier. We have to detect this situation before calling
22726 xref_tag, since that has irreversible side-effects. */
22727 if (!cp_parser_next_token_starts_class_definition_p (parser
))
22729 cp_parser_error (parser
, "expected %<{%> or %<:%>");
22730 type
= error_mark_node
;
22734 /* At this point, we're going ahead with the class-specifier, even
22735 if some other problem occurs. */
22736 cp_parser_commit_to_tentative_parse (parser
);
22737 if (virt_specifiers
& VIRT_SPEC_OVERRIDE
)
22739 cp_parser_error (parser
,
22740 "cannot specify %<override%> for a class");
22741 type
= error_mark_node
;
22744 /* Issue the error about the overly-qualified name now. */
22747 cp_parser_error (parser
,
22748 "global qualification of class name is invalid");
22749 type
= error_mark_node
;
22752 else if (invalid_nested_name_p
)
22754 cp_parser_error (parser
,
22755 "qualified name does not name a class");
22756 type
= error_mark_node
;
22759 else if (nested_name_specifier
)
22763 if (bad_template_keyword
)
22764 /* [temp.names]: in a qualified-id formed by a class-head-name, the
22765 keyword template shall not appear at the top level. */
22766 pedwarn (bad_template_keyword
->location
, OPT_Wpedantic
,
22767 "keyword %<template%> not allowed in class-head-name");
22769 /* Reject typedef-names in class heads. */
22770 if (!DECL_IMPLICIT_TYPEDEF_P (type
))
22772 error_at (type_start_token
->location
,
22773 "invalid class name in declaration of %qD",
22779 /* Figure out in what scope the declaration is being placed. */
22780 scope
= current_scope ();
22781 /* If that scope does not contain the scope in which the
22782 class was originally declared, the program is invalid. */
22783 if (scope
&& !is_ancestor (scope
, nested_name_specifier
))
22785 if (at_namespace_scope_p ())
22786 error_at (type_start_token
->location
,
22787 "declaration of %qD in namespace %qD which does not "
22789 type
, scope
, nested_name_specifier
);
22791 error_at (type_start_token
->location
,
22792 "declaration of %qD in %qD which does not enclose %qD",
22793 type
, scope
, nested_name_specifier
);
22799 A declarator-id shall not be qualified except for the
22800 definition of a ... nested class outside of its class
22801 ... [or] the definition or explicit instantiation of a
22802 class member of a namespace outside of its namespace. */
22803 if (scope
== nested_name_specifier
)
22805 permerror (nested_name_specifier_token_start
->location
,
22806 "extra qualification not allowed");
22807 nested_name_specifier
= NULL_TREE
;
22811 /* An explicit-specialization must be preceded by "template <>". If
22812 it is not, try to recover gracefully. */
22813 if (at_namespace_scope_p ()
22814 && parser
->num_template_parameter_lists
== 0
22815 && !processing_template_parmlist
22818 /* Build a location of this form:
22819 struct typename <ARGS>
22820 ^~~~~~~~~~~~~~~~~~~~~~
22821 with caret==start at the start token, and
22822 finishing at the end of the type. */
22823 location_t reported_loc
22824 = make_location (class_head_start_location
,
22825 class_head_start_location
,
22826 get_finish (type_start_token
->location
));
22827 rich_location
richloc (line_table
, reported_loc
);
22828 richloc
.add_fixit_insert_before (class_head_start_location
,
22832 "an explicit specialization must be preceded by %<template <>%>");
22833 invalid_explicit_specialization_p
= true;
22834 /* Take the same action that would have been taken by
22835 cp_parser_explicit_specialization. */
22836 ++parser
->num_template_parameter_lists
;
22837 begin_specialization ();
22839 /* There must be no "return" statements between this point and the
22840 end of this function; set "type "to the correct return value and
22841 use "goto done;" to return. */
22842 /* Make sure that the right number of template parameters were
22844 if (!cp_parser_check_template_parameters (parser
, num_templates
,
22845 type_start_token
->location
,
22846 /*declarator=*/NULL
))
22848 /* If something went wrong, there is no point in even trying to
22849 process the class-definition. */
22854 /* Look up the type. */
22857 if (TREE_CODE (id
) == TEMPLATE_ID_EXPR
22858 && (DECL_FUNCTION_TEMPLATE_P (TREE_OPERAND (id
, 0))
22859 || TREE_CODE (TREE_OPERAND (id
, 0)) == OVERLOAD
))
22861 error_at (type_start_token
->location
,
22862 "function template %qD redeclared as a class template", id
);
22863 type
= error_mark_node
;
22867 type
= TREE_TYPE (id
);
22868 type
= maybe_process_partial_specialization (type
);
22870 /* Check the scope while we still know whether or not we had a
22871 nested-name-specifier. */
22872 if (type
!= error_mark_node
)
22873 check_unqualified_spec_or_inst (type
, type_start_token
->location
);
22875 if (nested_name_specifier
)
22876 pushed_scope
= push_scope (nested_name_specifier
);
22878 else if (nested_name_specifier
)
22884 template <typename T> struct S { struct T };
22885 template <typename T> struct S<T>::T { };
22887 we will get a TYPENAME_TYPE when processing the definition of
22888 `S::T'. We need to resolve it to the actual type before we
22889 try to define it. */
22890 if (TREE_CODE (TREE_TYPE (type
)) == TYPENAME_TYPE
)
22892 class_type
= resolve_typename_type (TREE_TYPE (type
),
22893 /*only_current_p=*/false);
22894 if (TREE_CODE (class_type
) != TYPENAME_TYPE
)
22895 type
= TYPE_NAME (class_type
);
22898 cp_parser_error (parser
, "could not resolve typename type");
22899 type
= error_mark_node
;
22903 if (maybe_process_partial_specialization (TREE_TYPE (type
))
22904 == error_mark_node
)
22910 class_type
= current_class_type
;
22911 /* Enter the scope indicated by the nested-name-specifier. */
22912 pushed_scope
= push_scope (nested_name_specifier
);
22913 /* Get the canonical version of this type. */
22914 type
= TYPE_MAIN_DECL (TREE_TYPE (type
));
22915 /* Call push_template_decl if it seems like we should be defining a
22916 template either from the template headers or the type we're
22917 defining, so that we diagnose both extra and missing headers. */
22918 if ((PROCESSING_REAL_TEMPLATE_DECL_P ()
22919 || CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (type
)))
22920 && !CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (type
)))
22922 type
= push_template_decl (type
);
22923 if (type
== error_mark_node
)
22930 type
= TREE_TYPE (type
);
22931 *nested_name_specifier_p
= true;
22933 else /* The name is not a nested name. */
22935 /* If the class was unnamed, create a dummy name. */
22937 id
= make_anon_name ();
22938 tag_scope tag_scope
= (parser
->in_type_id_in_expr_p
22939 ? ts_within_enclosing_non_class
22941 type
= xref_tag (class_key
, id
, tag_scope
,
22942 parser
->num_template_parameter_lists
);
22945 /* Indicate whether this class was declared as a `class' or as a
22947 if (TREE_CODE (type
) == RECORD_TYPE
)
22948 CLASSTYPE_DECLARED_CLASS (type
) = (class_key
== class_type
);
22949 cp_parser_check_class_key (class_key
, type
);
22951 /* If this type was already complete, and we see another definition,
22952 that's an error. */
22953 if (type
!= error_mark_node
&& COMPLETE_TYPE_P (type
))
22955 error_at (type_start_token
->location
, "redefinition of %q#T",
22957 inform (location_of (type
), "previous definition of %q#T",
22962 else if (type
== error_mark_node
)
22967 /* Apply attributes now, before any use of the class as a template
22968 argument in its base list. */
22969 cplus_decl_attributes (&type
, attributes
, (int)ATTR_FLAG_TYPE_IN_PLACE
);
22970 fixup_attribute_variants (type
);
22973 /* We will have entered the scope containing the class; the names of
22974 base classes should be looked up in that context. For example:
22976 struct A { struct B {}; struct C; };
22977 struct A::C : B {};
22981 /* Get the list of base-classes, if there is one. */
22982 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
22984 /* PR59482: enter the class scope so that base-specifiers are looked
22988 bases
= cp_parser_base_clause (parser
);
22989 /* PR59482: get out of the previously pushed class scope so that the
22990 subsequent pops pop the right thing. */
22997 /* If we're really defining a class, process the base classes.
22998 If they're invalid, fail. */
22999 if (type
&& cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
23000 xref_basetypes (type
, bases
);
23003 /* Leave the scope given by the nested-name-specifier. We will
23004 enter the class scope itself while processing the members. */
23006 pop_scope (pushed_scope
);
23008 if (invalid_explicit_specialization_p
)
23010 end_specialization ();
23011 --parser
->num_template_parameter_lists
;
23015 DECL_SOURCE_LOCATION (TYPE_NAME (type
)) = type_start_token
->location
;
23016 if (type
&& (virt_specifiers
& VIRT_SPEC_FINAL
))
23017 CLASSTYPE_FINAL (type
) = 1;
23019 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
23023 /* Parse a class-key.
23030 Returns the kind of class-key specified, or none_type to indicate
23033 static enum tag_types
23034 cp_parser_class_key (cp_parser
* parser
)
23037 enum tag_types tag_type
;
23039 /* Look for the class-key. */
23040 token
= cp_parser_require (parser
, CPP_KEYWORD
, RT_CLASS_KEY
);
23044 /* Check to see if the TOKEN is a class-key. */
23045 tag_type
= cp_parser_token_is_class_key (token
);
23047 cp_parser_error (parser
, "expected class-key");
23051 /* Parse a type-parameter-key.
23053 type-parameter-key:
23059 cp_parser_type_parameter_key (cp_parser
* parser
)
23061 /* Look for the type-parameter-key. */
23062 enum tag_types tag_type
= none_type
;
23063 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
23064 if ((tag_type
= cp_parser_token_is_type_parameter_key (token
)) != none_type
)
23066 cp_lexer_consume_token (parser
->lexer
);
23067 if (pedantic
&& tag_type
== typename_type
&& cxx_dialect
< cxx1z
)
23068 /* typename is not allowed in a template template parameter
23069 by the standard until C++1Z. */
23070 pedwarn (token
->location
, OPT_Wpedantic
,
23071 "ISO C++ forbids typename key in template template parameter;"
23072 " use -std=c++1z or -std=gnu++1z");
23075 cp_parser_error (parser
, "expected %<class%> or %<typename%>");
23080 /* Parse an (optional) member-specification.
23082 member-specification:
23083 member-declaration member-specification [opt]
23084 access-specifier : member-specification [opt] */
23087 cp_parser_member_specification_opt (cp_parser
* parser
)
23094 /* Peek at the next token. */
23095 token
= cp_lexer_peek_token (parser
->lexer
);
23096 /* If it's a `}', or EOF then we've seen all the members. */
23097 if (token
->type
== CPP_CLOSE_BRACE
23098 || token
->type
== CPP_EOF
23099 || token
->type
== CPP_PRAGMA_EOL
)
23102 /* See if this token is a keyword. */
23103 keyword
= token
->keyword
;
23107 case RID_PROTECTED
:
23109 /* Consume the access-specifier. */
23110 cp_lexer_consume_token (parser
->lexer
);
23111 /* Remember which access-specifier is active. */
23112 current_access_specifier
= token
->u
.value
;
23113 /* Look for the `:'. */
23114 cp_parser_require (parser
, CPP_COLON
, RT_COLON
);
23118 /* Accept #pragmas at class scope. */
23119 if (token
->type
== CPP_PRAGMA
)
23121 cp_parser_pragma (parser
, pragma_member
, NULL
);
23125 /* Otherwise, the next construction must be a
23126 member-declaration. */
23127 cp_parser_member_declaration (parser
);
23132 /* Parse a member-declaration.
23134 member-declaration:
23135 decl-specifier-seq [opt] member-declarator-list [opt] ;
23136 function-definition ; [opt]
23137 :: [opt] nested-name-specifier template [opt] unqualified-id ;
23139 template-declaration
23142 member-declarator-list:
23144 member-declarator-list , member-declarator
23147 declarator pure-specifier [opt]
23148 declarator constant-initializer [opt]
23149 identifier [opt] : constant-expression
23153 member-declaration:
23154 __extension__ member-declaration
23157 declarator attributes [opt] pure-specifier [opt]
23158 declarator attributes [opt] constant-initializer [opt]
23159 identifier [opt] attributes [opt] : constant-expression
23163 member-declaration:
23164 static_assert-declaration */
23167 cp_parser_member_declaration (cp_parser
* parser
)
23169 cp_decl_specifier_seq decl_specifiers
;
23170 tree prefix_attributes
;
23172 int declares_class_or_enum
;
23174 cp_token
*token
= NULL
;
23175 cp_token
*decl_spec_token_start
= NULL
;
23176 cp_token
*initializer_token_start
= NULL
;
23177 int saved_pedantic
;
23178 bool saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
23180 /* Check for the `__extension__' keyword. */
23181 if (cp_parser_extension_opt (parser
, &saved_pedantic
))
23184 cp_parser_member_declaration (parser
);
23185 /* Restore the old value of the PEDANTIC flag. */
23186 pedantic
= saved_pedantic
;
23191 /* Check for a template-declaration. */
23192 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TEMPLATE
))
23194 /* An explicit specialization here is an error condition, and we
23195 expect the specialization handler to detect and report this. */
23196 if (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_LESS
23197 && cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
== CPP_GREATER
)
23198 cp_parser_explicit_specialization (parser
);
23200 cp_parser_template_declaration (parser
, /*member_p=*/true);
23204 /* Check for a template introduction. */
23205 else if (cp_parser_template_declaration_after_export (parser
, true))
23208 /* Check for a using-declaration. */
23209 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_USING
))
23211 if (cxx_dialect
< cxx11
)
23213 /* Parse the using-declaration. */
23214 cp_parser_using_declaration (parser
,
23215 /*access_declaration_p=*/false);
23221 bool alias_decl_expected
;
23222 cp_parser_parse_tentatively (parser
);
23223 decl
= cp_parser_alias_declaration (parser
);
23224 /* Note that if we actually see the '=' token after the
23225 identifier, cp_parser_alias_declaration commits the
23226 tentative parse. In that case, we really expect an
23227 alias-declaration. Otherwise, we expect a using
23229 alias_decl_expected
=
23230 !cp_parser_uncommitted_to_tentative_parse_p (parser
);
23231 cp_parser_parse_definitely (parser
);
23233 if (alias_decl_expected
)
23234 finish_member_declaration (decl
);
23236 cp_parser_using_declaration (parser
,
23237 /*access_declaration_p=*/false);
23242 /* Check for @defs. */
23243 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_AT_DEFS
))
23246 tree ivar_chains
= cp_parser_objc_defs_expression (parser
);
23247 ivar
= ivar_chains
;
23251 ivar
= TREE_CHAIN (member
);
23252 TREE_CHAIN (member
) = NULL_TREE
;
23253 finish_member_declaration (member
);
23258 /* If the next token is `static_assert' we have a static assertion. */
23259 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_STATIC_ASSERT
))
23261 cp_parser_static_assert (parser
, /*member_p=*/true);
23265 parser
->colon_corrects_to_scope_p
= false;
23267 if (cp_parser_using_declaration (parser
, /*access_declaration=*/true))
23270 /* Parse the decl-specifier-seq. */
23271 decl_spec_token_start
= cp_lexer_peek_token (parser
->lexer
);
23272 cp_parser_decl_specifier_seq (parser
,
23273 CP_PARSER_FLAGS_OPTIONAL
,
23275 &declares_class_or_enum
);
23276 /* Check for an invalid type-name. */
23277 if (!decl_specifiers
.any_type_specifiers_p
23278 && cp_parser_parse_and_diagnose_invalid_type_name (parser
))
23280 /* If there is no declarator, then the decl-specifier-seq should
23282 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
23284 /* If there was no decl-specifier-seq, and the next token is a
23285 `;', then we have something like:
23291 Each member-declaration shall declare at least one member
23292 name of the class. */
23293 if (!decl_specifiers
.any_specifiers_p
)
23295 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
23296 if (!in_system_header_at (token
->location
))
23298 gcc_rich_location
richloc (token
->location
);
23299 richloc
.add_fixit_remove ();
23300 pedwarn_at_rich_loc (&richloc
, OPT_Wpedantic
, "extra %<;%>");
23307 /* See if this declaration is a friend. */
23308 friend_p
= cp_parser_friend_p (&decl_specifiers
);
23309 /* If there were decl-specifiers, check to see if there was
23310 a class-declaration. */
23311 type
= check_tag_decl (&decl_specifiers
,
23312 /*explicit_type_instantiation_p=*/false);
23313 /* Nested classes have already been added to the class, but
23314 a `friend' needs to be explicitly registered. */
23317 /* If the `friend' keyword was present, the friend must
23318 be introduced with a class-key. */
23319 if (!declares_class_or_enum
&& cxx_dialect
< cxx11
)
23320 pedwarn (decl_spec_token_start
->location
, OPT_Wpedantic
,
23321 "in C++03 a class-key must be used "
23322 "when declaring a friend");
23325 template <typename T> struct A {
23326 friend struct A<T>::B;
23329 A<T>::B will be represented by a TYPENAME_TYPE, and
23330 therefore not recognized by check_tag_decl. */
23333 type
= decl_specifiers
.type
;
23334 if (type
&& TREE_CODE (type
) == TYPE_DECL
)
23335 type
= TREE_TYPE (type
);
23337 if (!type
|| !TYPE_P (type
))
23338 error_at (decl_spec_token_start
->location
,
23339 "friend declaration does not name a class or "
23342 make_friend_class (current_class_type
, type
,
23343 /*complain=*/true);
23345 /* If there is no TYPE, an error message will already have
23347 else if (!type
|| type
== error_mark_node
)
23349 /* An anonymous aggregate has to be handled specially; such
23350 a declaration really declares a data member (with a
23351 particular type), as opposed to a nested class. */
23352 else if (ANON_AGGR_TYPE_P (type
))
23355 if (decl_specifiers
.storage_class
!= sc_none
)
23356 error_at (decl_spec_token_start
->location
,
23357 "a storage class on an anonymous aggregate "
23358 "in class scope is not allowed");
23360 /* Remove constructors and such from TYPE, now that we
23361 know it is an anonymous aggregate. */
23362 fixup_anonymous_aggr (type
);
23363 /* And make the corresponding data member. */
23364 decl
= build_decl (decl_spec_token_start
->location
,
23365 FIELD_DECL
, NULL_TREE
, type
);
23366 /* Add it to the class. */
23367 finish_member_declaration (decl
);
23370 cp_parser_check_access_in_redeclaration
23372 decl_spec_token_start
->location
);
23377 bool assume_semicolon
= false;
23379 /* Clear attributes from the decl_specifiers but keep them
23380 around as prefix attributes that apply them to the entity
23382 prefix_attributes
= decl_specifiers
.attributes
;
23383 decl_specifiers
.attributes
= NULL_TREE
;
23385 /* See if these declarations will be friends. */
23386 friend_p
= cp_parser_friend_p (&decl_specifiers
);
23388 /* Keep going until we hit the `;' at the end of the
23390 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
23392 tree attributes
= NULL_TREE
;
23393 tree first_attribute
;
23395 /* Peek at the next token. */
23396 token
= cp_lexer_peek_token (parser
->lexer
);
23398 /* Check for a bitfield declaration. */
23399 if (token
->type
== CPP_COLON
23400 || (token
->type
== CPP_NAME
23401 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
23407 /* Get the name of the bitfield. Note that we cannot just
23408 check TOKEN here because it may have been invalidated by
23409 the call to cp_lexer_peek_nth_token above. */
23410 if (cp_lexer_peek_token (parser
->lexer
)->type
!= CPP_COLON
)
23411 identifier
= cp_parser_identifier (parser
);
23413 identifier
= NULL_TREE
;
23415 /* Consume the `:' token. */
23416 cp_lexer_consume_token (parser
->lexer
);
23417 /* Get the width of the bitfield. */
23419 = cp_parser_constant_expression (parser
);
23421 /* Look for attributes that apply to the bitfield. */
23422 attributes
= cp_parser_attributes_opt (parser
);
23423 /* Remember which attributes are prefix attributes and
23425 first_attribute
= attributes
;
23426 /* Combine the attributes. */
23427 attributes
= chainon (prefix_attributes
, attributes
);
23429 /* Create the bitfield declaration. */
23430 decl
= grokbitfield (identifier
23431 ? make_id_declarator (NULL_TREE
,
23441 cp_declarator
*declarator
;
23443 tree asm_specification
;
23444 int ctor_dtor_or_conv_p
;
23446 /* Parse the declarator. */
23448 = cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_NAMED
,
23449 &ctor_dtor_or_conv_p
,
23450 /*parenthesized_p=*/NULL
,
23454 /* If something went wrong parsing the declarator, make sure
23455 that we at least consume some tokens. */
23456 if (declarator
== cp_error_declarator
)
23458 /* Skip to the end of the statement. */
23459 cp_parser_skip_to_end_of_statement (parser
);
23460 /* If the next token is not a semicolon, that is
23461 probably because we just skipped over the body of
23462 a function. So, we consume a semicolon if
23463 present, but do not issue an error message if it
23465 if (cp_lexer_next_token_is (parser
->lexer
,
23467 cp_lexer_consume_token (parser
->lexer
);
23471 if (declares_class_or_enum
& 2)
23472 cp_parser_check_for_definition_in_return_type
23473 (declarator
, decl_specifiers
.type
,
23474 decl_specifiers
.locations
[ds_type_spec
]);
23476 /* Look for an asm-specification. */
23477 asm_specification
= cp_parser_asm_specification_opt (parser
);
23478 /* Look for attributes that apply to the declaration. */
23479 attributes
= cp_parser_attributes_opt (parser
);
23480 /* Remember which attributes are prefix attributes and
23482 first_attribute
= attributes
;
23483 /* Combine the attributes. */
23484 attributes
= chainon (prefix_attributes
, attributes
);
23486 /* If it's an `=', then we have a constant-initializer or a
23487 pure-specifier. It is not correct to parse the
23488 initializer before registering the member declaration
23489 since the member declaration should be in scope while
23490 its initializer is processed. However, the rest of the
23491 front end does not yet provide an interface that allows
23492 us to handle this correctly. */
23493 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
))
23497 A pure-specifier shall be used only in the declaration of
23498 a virtual function.
23500 A member-declarator can contain a constant-initializer
23501 only if it declares a static member of integral or
23504 Therefore, if the DECLARATOR is for a function, we look
23505 for a pure-specifier; otherwise, we look for a
23506 constant-initializer. When we call `grokfield', it will
23507 perform more stringent semantics checks. */
23508 initializer_token_start
= cp_lexer_peek_token (parser
->lexer
);
23509 if (function_declarator_p (declarator
)
23510 || (decl_specifiers
.type
23511 && TREE_CODE (decl_specifiers
.type
) == TYPE_DECL
23512 && declarator
->kind
== cdk_id
23513 && (TREE_CODE (TREE_TYPE (decl_specifiers
.type
))
23514 == FUNCTION_TYPE
)))
23515 initializer
= cp_parser_pure_specifier (parser
);
23516 else if (decl_specifiers
.storage_class
!= sc_static
)
23517 initializer
= cp_parser_save_nsdmi (parser
);
23518 else if (cxx_dialect
>= cxx11
)
23521 /* Don't require a constant rvalue in C++11, since we
23522 might want a reference constant. We'll enforce
23523 constancy later. */
23524 cp_lexer_consume_token (parser
->lexer
);
23525 /* Parse the initializer. */
23526 initializer
= cp_parser_initializer_clause (parser
,
23530 /* Parse the initializer. */
23531 initializer
= cp_parser_constant_initializer (parser
);
23533 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
)
23534 && !function_declarator_p (declarator
))
23537 if (decl_specifiers
.storage_class
!= sc_static
)
23538 initializer
= cp_parser_save_nsdmi (parser
);
23540 initializer
= cp_parser_initializer (parser
, &x
, &x
);
23542 /* Otherwise, there is no initializer. */
23544 initializer
= NULL_TREE
;
23546 /* See if we are probably looking at a function
23547 definition. We are certainly not looking at a
23548 member-declarator. Calling `grokfield' has
23549 side-effects, so we must not do it unless we are sure
23550 that we are looking at a member-declarator. */
23551 if (cp_parser_token_starts_function_definition_p
23552 (cp_lexer_peek_token (parser
->lexer
)))
23554 /* The grammar does not allow a pure-specifier to be
23555 used when a member function is defined. (It is
23556 possible that this fact is an oversight in the
23557 standard, since a pure function may be defined
23558 outside of the class-specifier. */
23559 if (initializer
&& initializer_token_start
)
23560 error_at (initializer_token_start
->location
,
23561 "pure-specifier on function-definition");
23562 decl
= cp_parser_save_member_function_body (parser
,
23566 if (parser
->fully_implicit_function_template_p
)
23567 decl
= finish_fully_implicit_template (parser
, decl
);
23568 /* If the member was not a friend, declare it here. */
23570 finish_member_declaration (decl
);
23571 /* Peek at the next token. */
23572 token
= cp_lexer_peek_token (parser
->lexer
);
23573 /* If the next token is a semicolon, consume it. */
23574 if (token
->type
== CPP_SEMICOLON
)
23576 location_t semicolon_loc
23577 = cp_lexer_consume_token (parser
->lexer
)->location
;
23578 gcc_rich_location
richloc (semicolon_loc
);
23579 richloc
.add_fixit_remove ();
23580 warning_at_rich_loc (&richloc
, OPT_Wextra_semi
,
23581 "extra %<;%> after in-class "
23582 "function definition");
23587 if (declarator
->kind
== cdk_function
)
23588 declarator
->id_loc
= token
->location
;
23589 /* Create the declaration. */
23590 decl
= grokfield (declarator
, &decl_specifiers
,
23591 initializer
, /*init_const_expr_p=*/true,
23592 asm_specification
, attributes
);
23593 if (parser
->fully_implicit_function_template_p
)
23596 finish_fully_implicit_template (parser
, 0);
23598 decl
= finish_fully_implicit_template (parser
, decl
);
23602 cp_finalize_omp_declare_simd (parser
, decl
);
23603 cp_finalize_oacc_routine (parser
, decl
, false);
23605 /* Reset PREFIX_ATTRIBUTES. */
23606 while (attributes
&& TREE_CHAIN (attributes
) != first_attribute
)
23607 attributes
= TREE_CHAIN (attributes
);
23609 TREE_CHAIN (attributes
) = NULL_TREE
;
23611 /* If there is any qualification still in effect, clear it
23612 now; we will be starting fresh with the next declarator. */
23613 parser
->scope
= NULL_TREE
;
23614 parser
->qualifying_scope
= NULL_TREE
;
23615 parser
->object_scope
= NULL_TREE
;
23616 /* If it's a `,', then there are more declarators. */
23617 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
23619 cp_lexer_consume_token (parser
->lexer
);
23620 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
23622 cp_token
*token
= cp_lexer_previous_token (parser
->lexer
);
23623 gcc_rich_location
richloc (token
->location
);
23624 richloc
.add_fixit_remove ();
23625 error_at_rich_loc (&richloc
, "stray %<,%> at end of "
23626 "member declaration");
23629 /* If the next token isn't a `;', then we have a parse error. */
23630 else if (cp_lexer_next_token_is_not (parser
->lexer
,
23633 /* The next token might be a ways away from where the
23634 actual semicolon is missing. Find the previous token
23635 and use that for our error position. */
23636 cp_token
*token
= cp_lexer_previous_token (parser
->lexer
);
23637 gcc_rich_location
richloc (token
->location
);
23638 richloc
.add_fixit_insert_after (";");
23639 error_at_rich_loc (&richloc
, "expected %<;%> at end of "
23640 "member declaration");
23642 /* Assume that the user meant to provide a semicolon. If
23643 we were to cp_parser_skip_to_end_of_statement, we might
23644 skip to a semicolon inside a member function definition
23645 and issue nonsensical error messages. */
23646 assume_semicolon
= true;
23651 /* Add DECL to the list of members. */
23653 /* Explicitly include, eg, NSDMIs, for better error
23654 recovery (c++/58650). */
23655 || !DECL_DECLARES_FUNCTION_P (decl
))
23656 finish_member_declaration (decl
);
23658 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23659 cp_parser_save_default_args (parser
, decl
);
23660 else if (TREE_CODE (decl
) == FIELD_DECL
23661 && !DECL_C_BIT_FIELD (decl
)
23662 && DECL_INITIAL (decl
))
23663 /* Add DECL to the queue of NSDMI to be parsed later. */
23664 vec_safe_push (unparsed_nsdmis
, decl
);
23667 if (assume_semicolon
)
23672 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
23674 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
23677 /* Parse a pure-specifier.
23682 Returns INTEGER_ZERO_NODE if a pure specifier is found.
23683 Otherwise, ERROR_MARK_NODE is returned. */
23686 cp_parser_pure_specifier (cp_parser
* parser
)
23690 /* Look for the `=' token. */
23691 if (!cp_parser_require (parser
, CPP_EQ
, RT_EQ
))
23692 return error_mark_node
;
23693 /* Look for the `0' token. */
23694 token
= cp_lexer_peek_token (parser
->lexer
);
23696 if (token
->type
== CPP_EOF
23697 || token
->type
== CPP_PRAGMA_EOL
)
23698 return error_mark_node
;
23700 cp_lexer_consume_token (parser
->lexer
);
23702 /* Accept = default or = delete in c++0x mode. */
23703 if (token
->keyword
== RID_DEFAULT
23704 || token
->keyword
== RID_DELETE
)
23706 maybe_warn_cpp0x (CPP0X_DEFAULTED_DELETED
);
23707 return token
->u
.value
;
23710 /* c_lex_with_flags marks a single digit '0' with PURE_ZERO. */
23711 if (token
->type
!= CPP_NUMBER
|| !(token
->flags
& PURE_ZERO
))
23713 cp_parser_error (parser
,
23714 "invalid pure specifier (only %<= 0%> is allowed)");
23715 cp_parser_skip_to_end_of_statement (parser
);
23716 return error_mark_node
;
23718 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
23720 error_at (token
->location
, "templates may not be %<virtual%>");
23721 return error_mark_node
;
23724 return integer_zero_node
;
23727 /* Parse a constant-initializer.
23729 constant-initializer:
23730 = constant-expression
23732 Returns a representation of the constant-expression. */
23735 cp_parser_constant_initializer (cp_parser
* parser
)
23737 /* Look for the `=' token. */
23738 if (!cp_parser_require (parser
, CPP_EQ
, RT_EQ
))
23739 return error_mark_node
;
23741 /* It is invalid to write:
23743 struct S { static const int i = { 7 }; };
23746 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
23748 cp_parser_error (parser
,
23749 "a brace-enclosed initializer is not allowed here");
23750 /* Consume the opening brace. */
23751 cp_lexer_consume_token (parser
->lexer
);
23752 /* Skip the initializer. */
23753 cp_parser_skip_to_closing_brace (parser
);
23754 /* Look for the trailing `}'. */
23755 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
23757 return error_mark_node
;
23760 return cp_parser_constant_expression (parser
);
23763 /* Derived classes [gram.class.derived] */
23765 /* Parse a base-clause.
23768 : base-specifier-list
23770 base-specifier-list:
23771 base-specifier ... [opt]
23772 base-specifier-list , base-specifier ... [opt]
23774 Returns a TREE_LIST representing the base-classes, in the order in
23775 which they were declared. The representation of each node is as
23776 described by cp_parser_base_specifier.
23778 In the case that no bases are specified, this function will return
23779 NULL_TREE, not ERROR_MARK_NODE. */
23782 cp_parser_base_clause (cp_parser
* parser
)
23784 tree bases
= NULL_TREE
;
23786 /* Look for the `:' that begins the list. */
23787 cp_parser_require (parser
, CPP_COLON
, RT_COLON
);
23789 /* Scan the base-specifier-list. */
23794 bool pack_expansion_p
= false;
23796 /* Look for the base-specifier. */
23797 base
= cp_parser_base_specifier (parser
);
23798 /* Look for the (optional) ellipsis. */
23799 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
23801 /* Consume the `...'. */
23802 cp_lexer_consume_token (parser
->lexer
);
23804 pack_expansion_p
= true;
23807 /* Add BASE to the front of the list. */
23808 if (base
&& base
!= error_mark_node
)
23810 if (pack_expansion_p
)
23811 /* Make this a pack expansion type. */
23812 TREE_VALUE (base
) = make_pack_expansion (TREE_VALUE (base
));
23814 if (!check_for_bare_parameter_packs (TREE_VALUE (base
)))
23816 TREE_CHAIN (base
) = bases
;
23820 /* Peek at the next token. */
23821 token
= cp_lexer_peek_token (parser
->lexer
);
23822 /* If it's not a comma, then the list is complete. */
23823 if (token
->type
!= CPP_COMMA
)
23825 /* Consume the `,'. */
23826 cp_lexer_consume_token (parser
->lexer
);
23829 /* PARSER->SCOPE may still be non-NULL at this point, if the last
23830 base class had a qualified name. However, the next name that
23831 appears is certainly not qualified. */
23832 parser
->scope
= NULL_TREE
;
23833 parser
->qualifying_scope
= NULL_TREE
;
23834 parser
->object_scope
= NULL_TREE
;
23836 return nreverse (bases
);
23839 /* Parse a base-specifier.
23842 :: [opt] nested-name-specifier [opt] class-name
23843 virtual access-specifier [opt] :: [opt] nested-name-specifier
23845 access-specifier virtual [opt] :: [opt] nested-name-specifier
23848 Returns a TREE_LIST. The TREE_PURPOSE will be one of
23849 ACCESS_{DEFAULT,PUBLIC,PROTECTED,PRIVATE}_[VIRTUAL]_NODE to
23850 indicate the specifiers provided. The TREE_VALUE will be a TYPE
23851 (or the ERROR_MARK_NODE) indicating the type that was specified. */
23854 cp_parser_base_specifier (cp_parser
* parser
)
23858 bool virtual_p
= false;
23859 bool duplicate_virtual_error_issued_p
= false;
23860 bool duplicate_access_error_issued_p
= false;
23861 bool class_scope_p
, template_p
;
23862 tree access
= access_default_node
;
23865 /* Process the optional `virtual' and `access-specifier'. */
23868 /* Peek at the next token. */
23869 token
= cp_lexer_peek_token (parser
->lexer
);
23870 /* Process `virtual'. */
23871 switch (token
->keyword
)
23874 /* If `virtual' appears more than once, issue an error. */
23875 if (virtual_p
&& !duplicate_virtual_error_issued_p
)
23877 cp_parser_error (parser
,
23878 "%<virtual%> specified more than once in base-specifier");
23879 duplicate_virtual_error_issued_p
= true;
23884 /* Consume the `virtual' token. */
23885 cp_lexer_consume_token (parser
->lexer
);
23890 case RID_PROTECTED
:
23892 /* If more than one access specifier appears, issue an
23894 if (access
!= access_default_node
23895 && !duplicate_access_error_issued_p
)
23897 cp_parser_error (parser
,
23898 "more than one access specifier in base-specifier");
23899 duplicate_access_error_issued_p
= true;
23902 access
= ridpointers
[(int) token
->keyword
];
23904 /* Consume the access-specifier. */
23905 cp_lexer_consume_token (parser
->lexer
);
23914 /* It is not uncommon to see programs mechanically, erroneously, use
23915 the 'typename' keyword to denote (dependent) qualified types
23916 as base classes. */
23917 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TYPENAME
))
23919 token
= cp_lexer_peek_token (parser
->lexer
);
23920 if (!processing_template_decl
)
23921 error_at (token
->location
,
23922 "keyword %<typename%> not allowed outside of templates");
23924 error_at (token
->location
,
23925 "keyword %<typename%> not allowed in this context "
23926 "(the base class is implicitly a type)");
23927 cp_lexer_consume_token (parser
->lexer
);
23930 /* Look for the optional `::' operator. */
23931 cp_parser_global_scope_opt (parser
, /*current_scope_valid_p=*/false);
23932 /* Look for the nested-name-specifier. The simplest way to
23937 The keyword `typename' is not permitted in a base-specifier or
23938 mem-initializer; in these contexts a qualified name that
23939 depends on a template-parameter is implicitly assumed to be a
23942 is to pretend that we have seen the `typename' keyword at this
23944 cp_parser_nested_name_specifier_opt (parser
,
23945 /*typename_keyword_p=*/true,
23946 /*check_dependency_p=*/true,
23948 /*is_declaration=*/true);
23949 /* If the base class is given by a qualified name, assume that names
23950 we see are type names or templates, as appropriate. */
23951 class_scope_p
= (parser
->scope
&& TYPE_P (parser
->scope
));
23952 template_p
= class_scope_p
&& cp_parser_optional_template_keyword (parser
);
23955 && cp_lexer_next_token_is_decltype (parser
->lexer
))
23956 /* DR 950 allows decltype as a base-specifier. */
23957 type
= cp_parser_decltype (parser
);
23960 /* Otherwise, look for the class-name. */
23961 type
= cp_parser_class_name (parser
,
23965 /*check_dependency_p=*/true,
23966 /*class_head_p=*/false,
23967 /*is_declaration=*/true);
23968 type
= TREE_TYPE (type
);
23971 if (type
== error_mark_node
)
23972 return error_mark_node
;
23974 return finish_base_specifier (type
, access
, virtual_p
);
23977 /* Exception handling [gram.exception] */
23979 /* Parse an (optional) noexcept-specification.
23981 noexcept-specification:
23982 noexcept ( constant-expression ) [opt]
23984 If no noexcept-specification is present, returns NULL_TREE.
23985 Otherwise, if REQUIRE_CONSTEXPR is false, then either parse and return any
23986 expression if parentheses follow noexcept, or return BOOLEAN_TRUE_NODE if
23987 there are no parentheses. CONSUMED_EXPR will be set accordingly.
23988 Otherwise, returns a noexcept specification unless RETURN_COND is true,
23989 in which case a boolean condition is returned instead. */
23992 cp_parser_noexcept_specification_opt (cp_parser
* parser
,
23993 bool require_constexpr
,
23994 bool* consumed_expr
,
23998 const char *saved_message
;
24000 /* Peek at the next token. */
24001 token
= cp_lexer_peek_token (parser
->lexer
);
24003 /* Is it a noexcept-specification? */
24004 if (cp_parser_is_keyword (token
, RID_NOEXCEPT
))
24007 cp_lexer_consume_token (parser
->lexer
);
24009 if (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_OPEN_PAREN
)
24011 cp_lexer_consume_token (parser
->lexer
);
24013 if (require_constexpr
)
24015 /* Types may not be defined in an exception-specification. */
24016 saved_message
= parser
->type_definition_forbidden_message
;
24017 parser
->type_definition_forbidden_message
24018 = G_("types may not be defined in an exception-specification");
24020 expr
= cp_parser_constant_expression (parser
);
24022 /* Restore the saved message. */
24023 parser
->type_definition_forbidden_message
= saved_message
;
24027 expr
= cp_parser_expression (parser
);
24028 *consumed_expr
= true;
24031 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
24035 expr
= boolean_true_node
;
24036 if (!require_constexpr
)
24037 *consumed_expr
= false;
24040 /* We cannot build a noexcept-spec right away because this will check
24041 that expr is a constexpr. */
24043 return build_noexcept_spec (expr
, tf_warning_or_error
);
24051 /* Parse an (optional) exception-specification.
24053 exception-specification:
24054 throw ( type-id-list [opt] )
24056 Returns a TREE_LIST representing the exception-specification. The
24057 TREE_VALUE of each node is a type. */
24060 cp_parser_exception_specification_opt (cp_parser
* parser
)
24064 const char *saved_message
;
24066 /* Peek at the next token. */
24067 token
= cp_lexer_peek_token (parser
->lexer
);
24069 /* Is it a noexcept-specification? */
24070 type_id_list
= cp_parser_noexcept_specification_opt (parser
, true, NULL
,
24072 if (type_id_list
!= NULL_TREE
)
24073 return type_id_list
;
24075 /* If it's not `throw', then there's no exception-specification. */
24076 if (!cp_parser_is_keyword (token
, RID_THROW
))
24079 location_t loc
= token
->location
;
24081 /* Consume the `throw'. */
24082 cp_lexer_consume_token (parser
->lexer
);
24084 /* Look for the `('. */
24085 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
24087 /* Peek at the next token. */
24088 token
= cp_lexer_peek_token (parser
->lexer
);
24089 /* If it's not a `)', then there is a type-id-list. */
24090 if (token
->type
!= CPP_CLOSE_PAREN
)
24092 /* Types may not be defined in an exception-specification. */
24093 saved_message
= parser
->type_definition_forbidden_message
;
24094 parser
->type_definition_forbidden_message
24095 = G_("types may not be defined in an exception-specification");
24096 /* Parse the type-id-list. */
24097 type_id_list
= cp_parser_type_id_list (parser
);
24098 /* Restore the saved message. */
24099 parser
->type_definition_forbidden_message
= saved_message
;
24101 if (cxx_dialect
>= cxx1z
)
24103 error_at (loc
, "ISO C++1z does not allow dynamic exception "
24105 type_id_list
= NULL_TREE
;
24107 else if (cxx_dialect
>= cxx11
&& !in_system_header_at (loc
))
24108 warning_at (loc
, OPT_Wdeprecated
,
24109 "dynamic exception specifications are deprecated in "
24112 /* In C++17, throw() is equivalent to noexcept (true). throw()
24113 is deprecated in C++11 and above as well, but is still widely used,
24114 so don't warn about it yet. */
24115 else if (cxx_dialect
>= cxx1z
)
24116 type_id_list
= noexcept_true_spec
;
24118 type_id_list
= empty_except_spec
;
24120 /* Look for the `)'. */
24121 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
24123 return type_id_list
;
24126 /* Parse an (optional) type-id-list.
24130 type-id-list , type-id ... [opt]
24132 Returns a TREE_LIST. The TREE_VALUE of each node is a TYPE,
24133 in the order that the types were presented. */
24136 cp_parser_type_id_list (cp_parser
* parser
)
24138 tree types
= NULL_TREE
;
24145 token
= cp_lexer_peek_token (parser
->lexer
);
24147 /* Get the next type-id. */
24148 type
= cp_parser_type_id (parser
);
24149 /* Check for invalid 'auto'. */
24150 if (flag_concepts
&& type_uses_auto (type
))
24152 error_at (token
->location
,
24153 "invalid use of %<auto%> in exception-specification");
24154 type
= error_mark_node
;
24156 /* Parse the optional ellipsis. */
24157 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
24159 /* Consume the `...'. */
24160 cp_lexer_consume_token (parser
->lexer
);
24162 /* Turn the type into a pack expansion expression. */
24163 type
= make_pack_expansion (type
);
24165 /* Add it to the list. */
24166 types
= add_exception_specifier (types
, type
, /*complain=*/1);
24167 /* Peek at the next token. */
24168 token
= cp_lexer_peek_token (parser
->lexer
);
24169 /* If it is not a `,', we are done. */
24170 if (token
->type
!= CPP_COMMA
)
24172 /* Consume the `,'. */
24173 cp_lexer_consume_token (parser
->lexer
);
24176 return nreverse (types
);
24179 /* Parse a try-block.
24182 try compound-statement handler-seq */
24185 cp_parser_try_block (cp_parser
* parser
)
24189 cp_parser_require_keyword (parser
, RID_TRY
, RT_TRY
);
24190 if (parser
->in_function_body
24191 && DECL_DECLARED_CONSTEXPR_P (current_function_decl
))
24192 error ("%<try%> in %<constexpr%> function");
24194 try_block
= begin_try_block ();
24195 cp_parser_compound_statement (parser
, NULL
, BCS_TRY_BLOCK
, false);
24196 finish_try_block (try_block
);
24197 cp_parser_handler_seq (parser
);
24198 finish_handler_sequence (try_block
);
24203 /* Parse a function-try-block.
24205 function-try-block:
24206 try ctor-initializer [opt] function-body handler-seq */
24209 cp_parser_function_try_block (cp_parser
* parser
)
24211 tree compound_stmt
;
24213 bool ctor_initializer_p
;
24215 /* Look for the `try' keyword. */
24216 if (!cp_parser_require_keyword (parser
, RID_TRY
, RT_TRY
))
24218 /* Let the rest of the front end know where we are. */
24219 try_block
= begin_function_try_block (&compound_stmt
);
24220 /* Parse the function-body. */
24221 ctor_initializer_p
= cp_parser_ctor_initializer_opt_and_function_body
24222 (parser
, /*in_function_try_block=*/true);
24223 /* We're done with the `try' part. */
24224 finish_function_try_block (try_block
);
24225 /* Parse the handlers. */
24226 cp_parser_handler_seq (parser
);
24227 /* We're done with the handlers. */
24228 finish_function_handler_sequence (try_block
, compound_stmt
);
24230 return ctor_initializer_p
;
24233 /* Parse a handler-seq.
24236 handler handler-seq [opt] */
24239 cp_parser_handler_seq (cp_parser
* parser
)
24245 /* Parse the handler. */
24246 cp_parser_handler (parser
);
24247 /* Peek at the next token. */
24248 token
= cp_lexer_peek_token (parser
->lexer
);
24249 /* If it's not `catch' then there are no more handlers. */
24250 if (!cp_parser_is_keyword (token
, RID_CATCH
))
24255 /* Parse a handler.
24258 catch ( exception-declaration ) compound-statement */
24261 cp_parser_handler (cp_parser
* parser
)
24266 cp_parser_require_keyword (parser
, RID_CATCH
, RT_CATCH
);
24267 handler
= begin_handler ();
24268 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
24269 declaration
= cp_parser_exception_declaration (parser
);
24270 finish_handler_parms (declaration
, handler
);
24271 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
24272 cp_parser_compound_statement (parser
, NULL
, BCS_NORMAL
, false);
24273 finish_handler (handler
);
24276 /* Parse an exception-declaration.
24278 exception-declaration:
24279 type-specifier-seq declarator
24280 type-specifier-seq abstract-declarator
24284 Returns a VAR_DECL for the declaration, or NULL_TREE if the
24285 ellipsis variant is used. */
24288 cp_parser_exception_declaration (cp_parser
* parser
)
24290 cp_decl_specifier_seq type_specifiers
;
24291 cp_declarator
*declarator
;
24292 const char *saved_message
;
24294 /* If it's an ellipsis, it's easy to handle. */
24295 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
24297 /* Consume the `...' token. */
24298 cp_lexer_consume_token (parser
->lexer
);
24302 /* Types may not be defined in exception-declarations. */
24303 saved_message
= parser
->type_definition_forbidden_message
;
24304 parser
->type_definition_forbidden_message
24305 = G_("types may not be defined in exception-declarations");
24307 /* Parse the type-specifier-seq. */
24308 cp_parser_type_specifier_seq (parser
, /*is_declaration=*/true,
24309 /*is_trailing_return=*/false,
24311 /* If it's a `)', then there is no declarator. */
24312 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_PAREN
))
24315 declarator
= cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_EITHER
,
24316 /*ctor_dtor_or_conv_p=*/NULL
,
24317 /*parenthesized_p=*/NULL
,
24318 /*member_p=*/false,
24319 /*friend_p=*/false);
24321 /* Restore the saved message. */
24322 parser
->type_definition_forbidden_message
= saved_message
;
24324 if (!type_specifiers
.any_specifiers_p
)
24325 return error_mark_node
;
24327 return grokdeclarator (declarator
, &type_specifiers
, CATCHPARM
, 1, NULL
);
24330 /* Parse a throw-expression.
24333 throw assignment-expression [opt]
24335 Returns a THROW_EXPR representing the throw-expression. */
24338 cp_parser_throw_expression (cp_parser
* parser
)
24343 cp_parser_require_keyword (parser
, RID_THROW
, RT_THROW
);
24344 token
= cp_lexer_peek_token (parser
->lexer
);
24345 /* Figure out whether or not there is an assignment-expression
24346 following the "throw" keyword. */
24347 if (token
->type
== CPP_COMMA
24348 || token
->type
== CPP_SEMICOLON
24349 || token
->type
== CPP_CLOSE_PAREN
24350 || token
->type
== CPP_CLOSE_SQUARE
24351 || token
->type
== CPP_CLOSE_BRACE
24352 || token
->type
== CPP_COLON
)
24353 expression
= NULL_TREE
;
24355 expression
= cp_parser_assignment_expression (parser
);
24357 return build_throw (expression
);
24360 /* GNU Extensions */
24362 /* Parse an (optional) asm-specification.
24365 asm ( string-literal )
24367 If the asm-specification is present, returns a STRING_CST
24368 corresponding to the string-literal. Otherwise, returns
24372 cp_parser_asm_specification_opt (cp_parser
* parser
)
24375 tree asm_specification
;
24377 /* Peek at the next token. */
24378 token
= cp_lexer_peek_token (parser
->lexer
);
24379 /* If the next token isn't the `asm' keyword, then there's no
24380 asm-specification. */
24381 if (!cp_parser_is_keyword (token
, RID_ASM
))
24384 /* Consume the `asm' token. */
24385 cp_lexer_consume_token (parser
->lexer
);
24386 /* Look for the `('. */
24387 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
24389 /* Look for the string-literal. */
24390 asm_specification
= cp_parser_string_literal (parser
, false, false);
24392 /* Look for the `)'. */
24393 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
24395 return asm_specification
;
24398 /* Parse an asm-operand-list.
24402 asm-operand-list , asm-operand
24405 string-literal ( expression )
24406 [ string-literal ] string-literal ( expression )
24408 Returns a TREE_LIST representing the operands. The TREE_VALUE of
24409 each node is the expression. The TREE_PURPOSE is itself a
24410 TREE_LIST whose TREE_PURPOSE is a STRING_CST for the bracketed
24411 string-literal (or NULL_TREE if not present) and whose TREE_VALUE
24412 is a STRING_CST for the string literal before the parenthesis. Returns
24413 ERROR_MARK_NODE if any of the operands are invalid. */
24416 cp_parser_asm_operand_list (cp_parser
* parser
)
24418 tree asm_operands
= NULL_TREE
;
24419 bool invalid_operands
= false;
24423 tree string_literal
;
24427 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_SQUARE
))
24429 /* Consume the `[' token. */
24430 cp_lexer_consume_token (parser
->lexer
);
24431 /* Read the operand name. */
24432 name
= cp_parser_identifier (parser
);
24433 if (name
!= error_mark_node
)
24434 name
= build_string (IDENTIFIER_LENGTH (name
),
24435 IDENTIFIER_POINTER (name
));
24436 /* Look for the closing `]'. */
24437 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
24441 /* Look for the string-literal. */
24442 string_literal
= cp_parser_string_literal (parser
, false, false);
24444 /* Look for the `('. */
24445 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
24446 /* Parse the expression. */
24447 expression
= cp_parser_expression (parser
);
24448 /* Look for the `)'. */
24449 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
24451 if (name
== error_mark_node
24452 || string_literal
== error_mark_node
24453 || expression
== error_mark_node
)
24454 invalid_operands
= true;
24456 /* Add this operand to the list. */
24457 asm_operands
= tree_cons (build_tree_list (name
, string_literal
),
24460 /* If the next token is not a `,', there are no more
24462 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
24464 /* Consume the `,'. */
24465 cp_lexer_consume_token (parser
->lexer
);
24468 return invalid_operands
? error_mark_node
: nreverse (asm_operands
);
24471 /* Parse an asm-clobber-list.
24475 asm-clobber-list , string-literal
24477 Returns a TREE_LIST, indicating the clobbers in the order that they
24478 appeared. The TREE_VALUE of each node is a STRING_CST. */
24481 cp_parser_asm_clobber_list (cp_parser
* parser
)
24483 tree clobbers
= NULL_TREE
;
24487 tree string_literal
;
24489 /* Look for the string literal. */
24490 string_literal
= cp_parser_string_literal (parser
, false, false);
24491 /* Add it to the list. */
24492 clobbers
= tree_cons (NULL_TREE
, string_literal
, clobbers
);
24493 /* If the next token is not a `,', then the list is
24495 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
24497 /* Consume the `,' token. */
24498 cp_lexer_consume_token (parser
->lexer
);
24504 /* Parse an asm-label-list.
24508 asm-label-list , identifier
24510 Returns a TREE_LIST, indicating the labels in the order that they
24511 appeared. The TREE_VALUE of each node is a label. */
24514 cp_parser_asm_label_list (cp_parser
* parser
)
24516 tree labels
= NULL_TREE
;
24520 tree identifier
, label
, name
;
24522 /* Look for the identifier. */
24523 identifier
= cp_parser_identifier (parser
);
24524 if (!error_operand_p (identifier
))
24526 label
= lookup_label (identifier
);
24527 if (TREE_CODE (label
) == LABEL_DECL
)
24529 TREE_USED (label
) = 1;
24530 check_goto (label
);
24531 name
= build_string (IDENTIFIER_LENGTH (identifier
),
24532 IDENTIFIER_POINTER (identifier
));
24533 labels
= tree_cons (name
, label
, labels
);
24536 /* If the next token is not a `,', then the list is
24538 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
24540 /* Consume the `,' token. */
24541 cp_lexer_consume_token (parser
->lexer
);
24544 return nreverse (labels
);
24547 /* Return TRUE iff the next tokens in the stream are possibly the
24548 beginning of a GNU extension attribute. */
24551 cp_next_tokens_can_be_gnu_attribute_p (cp_parser
*parser
)
24553 return cp_nth_tokens_can_be_gnu_attribute_p (parser
, 1);
24556 /* Return TRUE iff the next tokens in the stream are possibly the
24557 beginning of a standard C++-11 attribute specifier. */
24560 cp_next_tokens_can_be_std_attribute_p (cp_parser
*parser
)
24562 return cp_nth_tokens_can_be_std_attribute_p (parser
, 1);
24565 /* Return TRUE iff the next Nth tokens in the stream are possibly the
24566 beginning of a standard C++-11 attribute specifier. */
24569 cp_nth_tokens_can_be_std_attribute_p (cp_parser
*parser
, size_t n
)
24571 cp_token
*token
= cp_lexer_peek_nth_token (parser
->lexer
, n
);
24573 return (cxx_dialect
>= cxx11
24574 && ((token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_ALIGNAS
)
24575 || (token
->type
== CPP_OPEN_SQUARE
24576 && (token
= cp_lexer_peek_nth_token (parser
->lexer
, n
+ 1))
24577 && token
->type
== CPP_OPEN_SQUARE
)));
24580 /* Return TRUE iff the next Nth tokens in the stream are possibly the
24581 beginning of a GNU extension attribute. */
24584 cp_nth_tokens_can_be_gnu_attribute_p (cp_parser
*parser
, size_t n
)
24586 cp_token
*token
= cp_lexer_peek_nth_token (parser
->lexer
, n
);
24588 return token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_ATTRIBUTE
;
24591 /* Return true iff the next tokens can be the beginning of either a
24592 GNU attribute list, or a standard C++11 attribute sequence. */
24595 cp_next_tokens_can_be_attribute_p (cp_parser
*parser
)
24597 return (cp_next_tokens_can_be_gnu_attribute_p (parser
)
24598 || cp_next_tokens_can_be_std_attribute_p (parser
));
24601 /* Return true iff the next Nth tokens can be the beginning of either
24602 a GNU attribute list, or a standard C++11 attribute sequence. */
24605 cp_nth_tokens_can_be_attribute_p (cp_parser
*parser
, size_t n
)
24607 return (cp_nth_tokens_can_be_gnu_attribute_p (parser
, n
)
24608 || cp_nth_tokens_can_be_std_attribute_p (parser
, n
));
24611 /* Parse either a standard C++-11 attribute-specifier-seq, or a series
24612 of GNU attributes, or return NULL. */
24615 cp_parser_attributes_opt (cp_parser
*parser
)
24617 if (cp_next_tokens_can_be_gnu_attribute_p (parser
))
24618 return cp_parser_gnu_attributes_opt (parser
);
24619 return cp_parser_std_attribute_spec_seq (parser
);
24622 #define CILK_SIMD_FN_CLAUSE_MASK \
24623 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
24624 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
24625 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
24626 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
24627 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
24629 /* Parses the Cilk Plus SIMD-enabled function's attribute. Syntax:
24630 vector [(<clauses>)] */
24633 cp_parser_cilk_simd_fn_vector_attrs (cp_parser
*parser
, cp_token
*v_token
)
24635 bool first_p
= parser
->cilk_simd_fn_info
== NULL
;
24636 cp_token
*token
= v_token
;
24639 parser
->cilk_simd_fn_info
= XNEW (cp_omp_declare_simd_data
);
24640 parser
->cilk_simd_fn_info
->error_seen
= false;
24641 parser
->cilk_simd_fn_info
->fndecl_seen
= false;
24642 parser
->cilk_simd_fn_info
->tokens
= vNULL
;
24643 parser
->cilk_simd_fn_info
->clauses
= NULL_TREE
;
24645 int paren_scope
= 0;
24646 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
24648 cp_lexer_consume_token (parser
->lexer
);
24649 v_token
= cp_lexer_peek_token (parser
->lexer
);
24652 while (paren_scope
> 0)
24654 token
= cp_lexer_peek_token (parser
->lexer
);
24655 if (token
->type
== CPP_OPEN_PAREN
)
24657 else if (token
->type
== CPP_CLOSE_PAREN
)
24659 /* Do not push the last ')' */
24660 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
24661 cp_lexer_consume_token (parser
->lexer
);
24664 token
->type
= CPP_PRAGMA_EOL
;
24665 parser
->lexer
->next_token
= token
;
24666 cp_lexer_consume_token (parser
->lexer
);
24668 struct cp_token_cache
*cp
24669 = cp_token_cache_new (v_token
, cp_lexer_peek_token (parser
->lexer
));
24670 parser
->cilk_simd_fn_info
->tokens
.safe_push (cp
);
24673 /* Parse an (optional) series of attributes.
24676 attributes attribute
24679 __attribute__ (( attribute-list [opt] ))
24681 The return value is as for cp_parser_gnu_attribute_list. */
24684 cp_parser_gnu_attributes_opt (cp_parser
* parser
)
24686 tree attributes
= NULL_TREE
;
24691 tree attribute_list
;
24694 /* Peek at the next token. */
24695 token
= cp_lexer_peek_token (parser
->lexer
);
24696 /* If it's not `__attribute__', then we're done. */
24697 if (token
->keyword
!= RID_ATTRIBUTE
)
24700 /* Consume the `__attribute__' keyword. */
24701 cp_lexer_consume_token (parser
->lexer
);
24702 /* Look for the two `(' tokens. */
24703 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
24704 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
24706 /* Peek at the next token. */
24707 token
= cp_lexer_peek_token (parser
->lexer
);
24708 if (token
->type
!= CPP_CLOSE_PAREN
)
24709 /* Parse the attribute-list. */
24710 attribute_list
= cp_parser_gnu_attribute_list (parser
);
24712 /* If the next token is a `)', then there is no attribute
24714 attribute_list
= NULL
;
24716 /* Look for the two `)' tokens. */
24717 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
24719 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
24722 cp_parser_skip_to_end_of_statement (parser
);
24724 /* Add these new attributes to the list. */
24725 attributes
= chainon (attributes
, attribute_list
);
24731 /* Parse a GNU attribute-list.
24735 attribute-list , attribute
24739 identifier ( identifier )
24740 identifier ( identifier , expression-list )
24741 identifier ( expression-list )
24743 Returns a TREE_LIST, or NULL_TREE on error. Each node corresponds
24744 to an attribute. The TREE_PURPOSE of each node is the identifier
24745 indicating which attribute is in use. The TREE_VALUE represents
24746 the arguments, if any. */
24749 cp_parser_gnu_attribute_list (cp_parser
* parser
)
24751 tree attribute_list
= NULL_TREE
;
24752 bool save_translate_strings_p
= parser
->translate_strings_p
;
24754 parser
->translate_strings_p
= false;
24761 /* Look for the identifier. We also allow keywords here; for
24762 example `__attribute__ ((const))' is legal. */
24763 token
= cp_lexer_peek_token (parser
->lexer
);
24764 if (token
->type
== CPP_NAME
24765 || token
->type
== CPP_KEYWORD
)
24767 tree arguments
= NULL_TREE
;
24769 /* Consume the token, but save it since we need it for the
24770 SIMD enabled function parsing. */
24771 cp_token
*id_token
= cp_lexer_consume_token (parser
->lexer
);
24773 /* Save away the identifier that indicates which attribute
24775 identifier
= (token
->type
== CPP_KEYWORD
)
24776 /* For keywords, use the canonical spelling, not the
24777 parsed identifier. */
24778 ? ridpointers
[(int) token
->keyword
]
24779 : id_token
->u
.value
;
24781 attribute
= build_tree_list (identifier
, NULL_TREE
);
24783 /* Peek at the next token. */
24784 token
= cp_lexer_peek_token (parser
->lexer
);
24785 /* If it's an `(', then parse the attribute arguments. */
24786 if (token
->type
== CPP_OPEN_PAREN
)
24788 vec
<tree
, va_gc
> *vec
;
24789 int attr_flag
= (attribute_takes_identifier_p (identifier
)
24790 ? id_attr
: normal_attr
);
24791 if (is_cilkplus_vector_p (identifier
))
24793 cp_parser_cilk_simd_fn_vector_attrs (parser
, id_token
);
24797 vec
= cp_parser_parenthesized_expression_list
24798 (parser
, attr_flag
, /*cast_p=*/false,
24799 /*allow_expansion_p=*/false,
24800 /*non_constant_p=*/NULL
);
24802 arguments
= error_mark_node
;
24805 arguments
= build_tree_list_vec (vec
);
24806 release_tree_vector (vec
);
24808 /* Save the arguments away. */
24809 TREE_VALUE (attribute
) = arguments
;
24811 else if (is_cilkplus_vector_p (identifier
))
24813 cp_parser_cilk_simd_fn_vector_attrs (parser
, id_token
);
24817 if (arguments
!= error_mark_node
)
24819 /* Add this attribute to the list. */
24820 TREE_CHAIN (attribute
) = attribute_list
;
24821 attribute_list
= attribute
;
24824 token
= cp_lexer_peek_token (parser
->lexer
);
24826 /* Now, look for more attributes. If the next token isn't a
24827 `,', we're done. */
24828 if (token
->type
!= CPP_COMMA
)
24831 /* Consume the comma and keep going. */
24832 cp_lexer_consume_token (parser
->lexer
);
24834 parser
->translate_strings_p
= save_translate_strings_p
;
24836 /* We built up the list in reverse order. */
24837 return nreverse (attribute_list
);
24840 /* Parse a standard C++11 attribute.
24842 The returned representation is a TREE_LIST which TREE_PURPOSE is
24843 the scoped name of the attribute, and the TREE_VALUE is its
24846 Note that the scoped name of the attribute is itself a TREE_LIST
24847 which TREE_PURPOSE is the namespace of the attribute, and
24848 TREE_VALUE its name. This is unlike a GNU attribute -- as parsed
24849 by cp_parser_gnu_attribute_list -- that doesn't have any namespace
24850 and which TREE_PURPOSE is directly the attribute name.
24852 Clients of the attribute code should use get_attribute_namespace
24853 and get_attribute_name to get the actual namespace and name of
24854 attributes, regardless of their being GNU or C++11 attributes.
24857 attribute-token attribute-argument-clause [opt]
24861 attribute-scoped-token
24863 attribute-scoped-token:
24864 attribute-namespace :: identifier
24866 attribute-namespace:
24869 attribute-argument-clause:
24870 ( balanced-token-seq )
24872 balanced-token-seq:
24873 balanced-token [opt]
24874 balanced-token-seq balanced-token
24877 ( balanced-token-seq )
24878 [ balanced-token-seq ]
24879 { balanced-token-seq }. */
24882 cp_parser_std_attribute (cp_parser
*parser
, tree attr_ns
)
24884 tree attribute
, attr_id
= NULL_TREE
, arguments
;
24887 /* First, parse name of the attribute, a.k.a attribute-token. */
24889 token
= cp_lexer_peek_token (parser
->lexer
);
24890 if (token
->type
== CPP_NAME
)
24891 attr_id
= token
->u
.value
;
24892 else if (token
->type
== CPP_KEYWORD
)
24893 attr_id
= ridpointers
[(int) token
->keyword
];
24894 else if (token
->flags
& NAMED_OP
)
24895 attr_id
= get_identifier (cpp_type2name (token
->type
, token
->flags
));
24897 if (attr_id
== NULL_TREE
)
24900 cp_lexer_consume_token (parser
->lexer
);
24902 token
= cp_lexer_peek_token (parser
->lexer
);
24903 if (token
->type
== CPP_SCOPE
)
24905 /* We are seeing a scoped attribute token. */
24907 cp_lexer_consume_token (parser
->lexer
);
24909 error_at (token
->location
, "attribute using prefix used together "
24910 "with scoped attribute token");
24913 token
= cp_lexer_consume_token (parser
->lexer
);
24914 if (token
->type
== CPP_NAME
)
24915 attr_id
= token
->u
.value
;
24916 else if (token
->type
== CPP_KEYWORD
)
24917 attr_id
= ridpointers
[(int) token
->keyword
];
24918 else if (token
->flags
& NAMED_OP
)
24919 attr_id
= get_identifier (cpp_type2name (token
->type
, token
->flags
));
24922 error_at (token
->location
,
24923 "expected an identifier for the attribute name");
24924 return error_mark_node
;
24926 attribute
= build_tree_list (build_tree_list (attr_ns
, attr_id
),
24928 token
= cp_lexer_peek_token (parser
->lexer
);
24931 attribute
= build_tree_list (build_tree_list (attr_ns
, attr_id
),
24935 attribute
= build_tree_list (build_tree_list (NULL_TREE
, attr_id
),
24937 /* C++11 noreturn attribute is equivalent to GNU's. */
24938 if (is_attribute_p ("noreturn", attr_id
))
24939 TREE_PURPOSE (TREE_PURPOSE (attribute
)) = get_identifier ("gnu");
24940 /* C++14 deprecated attribute is equivalent to GNU's. */
24941 else if (is_attribute_p ("deprecated", attr_id
))
24942 TREE_PURPOSE (TREE_PURPOSE (attribute
)) = get_identifier ("gnu");
24943 /* C++17 fallthrough attribute is equivalent to GNU's. */
24944 else if (is_attribute_p ("fallthrough", attr_id
))
24945 TREE_PURPOSE (TREE_PURPOSE (attribute
)) = get_identifier ("gnu");
24946 /* Transactional Memory TS optimize_for_synchronized attribute is
24947 equivalent to GNU transaction_callable. */
24948 else if (is_attribute_p ("optimize_for_synchronized", attr_id
))
24949 TREE_PURPOSE (attribute
)
24950 = get_identifier ("transaction_callable");
24951 /* Transactional Memory attributes are GNU attributes. */
24952 else if (tm_attr_to_mask (attr_id
))
24953 TREE_PURPOSE (attribute
) = attr_id
;
24956 /* Now parse the optional argument clause of the attribute. */
24958 if (token
->type
!= CPP_OPEN_PAREN
)
24962 vec
<tree
, va_gc
> *vec
;
24963 int attr_flag
= normal_attr
;
24965 if (attr_ns
== get_identifier ("gnu")
24966 && attribute_takes_identifier_p (attr_id
))
24967 /* A GNU attribute that takes an identifier in parameter. */
24968 attr_flag
= id_attr
;
24970 vec
= cp_parser_parenthesized_expression_list
24971 (parser
, attr_flag
, /*cast_p=*/false,
24972 /*allow_expansion_p=*/true,
24973 /*non_constant_p=*/NULL
);
24975 arguments
= error_mark_node
;
24978 arguments
= build_tree_list_vec (vec
);
24979 release_tree_vector (vec
);
24982 if (arguments
== error_mark_node
)
24983 attribute
= error_mark_node
;
24985 TREE_VALUE (attribute
) = arguments
;
24991 /* Check that the attribute ATTRIBUTE appears at most once in the
24992 attribute-list ATTRIBUTES. This is enforced for noreturn (7.6.3)
24993 and deprecated (7.6.5). Note that carries_dependency (7.6.4)
24994 isn't implemented yet in GCC. */
24997 cp_parser_check_std_attribute (tree attributes
, tree attribute
)
25001 tree name
= get_attribute_name (attribute
);
25002 if (is_attribute_p ("noreturn", name
)
25003 && lookup_attribute ("noreturn", attributes
))
25004 error ("attribute %<noreturn%> can appear at most once "
25005 "in an attribute-list");
25006 else if (is_attribute_p ("deprecated", name
)
25007 && lookup_attribute ("deprecated", attributes
))
25008 error ("attribute %<deprecated%> can appear at most once "
25009 "in an attribute-list");
25013 /* Parse a list of standard C++-11 attributes.
25017 attribute-list , attribute[opt]
25019 attribute-list , attribute ...
25023 cp_parser_std_attribute_list (cp_parser
*parser
, tree attr_ns
)
25025 tree attributes
= NULL_TREE
, attribute
= NULL_TREE
;
25026 cp_token
*token
= NULL
;
25030 attribute
= cp_parser_std_attribute (parser
, attr_ns
);
25031 if (attribute
== error_mark_node
)
25033 if (attribute
!= NULL_TREE
)
25035 cp_parser_check_std_attribute (attributes
, attribute
);
25036 TREE_CHAIN (attribute
) = attributes
;
25037 attributes
= attribute
;
25039 token
= cp_lexer_peek_token (parser
->lexer
);
25040 if (token
->type
== CPP_ELLIPSIS
)
25042 cp_lexer_consume_token (parser
->lexer
);
25043 if (attribute
== NULL_TREE
)
25044 error_at (token
->location
,
25045 "expected attribute before %<...%>");
25048 tree pack
= make_pack_expansion (TREE_VALUE (attribute
));
25049 if (pack
== error_mark_node
)
25050 return error_mark_node
;
25051 TREE_VALUE (attribute
) = pack
;
25053 token
= cp_lexer_peek_token (parser
->lexer
);
25055 if (token
->type
!= CPP_COMMA
)
25057 cp_lexer_consume_token (parser
->lexer
);
25059 attributes
= nreverse (attributes
);
25063 /* Parse a standard C++-11 attribute specifier.
25065 attribute-specifier:
25066 [ [ attribute-using-prefix [opt] attribute-list ] ]
25067 alignment-specifier
25069 attribute-using-prefix:
25070 using attribute-namespace :
25072 alignment-specifier:
25073 alignas ( type-id ... [opt] )
25074 alignas ( alignment-expression ... [opt] ). */
25077 cp_parser_std_attribute_spec (cp_parser
*parser
)
25079 tree attributes
= NULL_TREE
;
25080 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
25082 if (token
->type
== CPP_OPEN_SQUARE
25083 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_OPEN_SQUARE
)
25085 tree attr_ns
= NULL_TREE
;
25087 cp_lexer_consume_token (parser
->lexer
);
25088 cp_lexer_consume_token (parser
->lexer
);
25090 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_USING
))
25092 token
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
25093 if (token
->type
== CPP_NAME
)
25094 attr_ns
= token
->u
.value
;
25095 else if (token
->type
== CPP_KEYWORD
)
25096 attr_ns
= ridpointers
[(int) token
->keyword
];
25097 else if (token
->flags
& NAMED_OP
)
25098 attr_ns
= get_identifier (cpp_type2name (token
->type
,
25101 && cp_lexer_nth_token_is (parser
->lexer
, 3, CPP_COLON
))
25103 if (cxx_dialect
< cxx1z
25104 && !in_system_header_at (input_location
))
25105 pedwarn (input_location
, 0,
25106 "attribute using prefix only available "
25107 "with -std=c++1z or -std=gnu++1z");
25109 cp_lexer_consume_token (parser
->lexer
);
25110 cp_lexer_consume_token (parser
->lexer
);
25111 cp_lexer_consume_token (parser
->lexer
);
25114 attr_ns
= NULL_TREE
;
25117 attributes
= cp_parser_std_attribute_list (parser
, attr_ns
);
25119 if (!cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
)
25120 || !cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
))
25121 cp_parser_skip_to_end_of_statement (parser
);
25123 /* Warn about parsing c++11 attribute in non-c++1 mode, only
25124 when we are sure that we have actually parsed them. */
25125 maybe_warn_cpp0x (CPP0X_ATTRIBUTES
);
25131 /* Look for an alignment-specifier. */
25133 token
= cp_lexer_peek_token (parser
->lexer
);
25135 if (token
->type
!= CPP_KEYWORD
25136 || token
->keyword
!= RID_ALIGNAS
)
25139 cp_lexer_consume_token (parser
->lexer
);
25140 maybe_warn_cpp0x (CPP0X_ATTRIBUTES
);
25142 if (cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
) == NULL
)
25144 cp_parser_error (parser
, "expected %<(%>");
25145 return error_mark_node
;
25148 cp_parser_parse_tentatively (parser
);
25149 alignas_expr
= cp_parser_type_id (parser
);
25151 if (!cp_parser_parse_definitely (parser
))
25153 alignas_expr
= cp_parser_assignment_expression (parser
);
25154 if (alignas_expr
== error_mark_node
)
25155 cp_parser_skip_to_end_of_statement (parser
);
25156 if (alignas_expr
== NULL_TREE
25157 || alignas_expr
== error_mark_node
)
25158 return alignas_expr
;
25161 alignas_expr
= cxx_alignas_expr (alignas_expr
);
25162 alignas_expr
= build_tree_list (NULL_TREE
, alignas_expr
);
25164 /* Handle alignas (pack...). */
25165 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
25167 cp_lexer_consume_token (parser
->lexer
);
25168 alignas_expr
= make_pack_expansion (alignas_expr
);
25171 /* Something went wrong, so don't build the attribute. */
25172 if (alignas_expr
== error_mark_node
)
25173 return error_mark_node
;
25175 if (cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
) == NULL
)
25177 cp_parser_error (parser
, "expected %<)%>");
25178 return error_mark_node
;
25181 /* Build the C++-11 representation of an 'aligned'
25184 build_tree_list (build_tree_list (get_identifier ("gnu"),
25185 get_identifier ("aligned")),
25192 /* Parse a standard C++-11 attribute-specifier-seq.
25194 attribute-specifier-seq:
25195 attribute-specifier-seq [opt] attribute-specifier
25199 cp_parser_std_attribute_spec_seq (cp_parser
*parser
)
25201 tree attr_specs
= NULL_TREE
;
25202 tree attr_last
= NULL_TREE
;
25206 tree attr_spec
= cp_parser_std_attribute_spec (parser
);
25207 if (attr_spec
== NULL_TREE
)
25209 if (attr_spec
== error_mark_node
)
25210 return error_mark_node
;
25213 TREE_CHAIN (attr_last
) = attr_spec
;
25215 attr_specs
= attr_last
= attr_spec
;
25216 attr_last
= tree_last (attr_last
);
25222 /* Parse an optional `__extension__' keyword. Returns TRUE if it is
25223 present, and FALSE otherwise. *SAVED_PEDANTIC is set to the
25224 current value of the PEDANTIC flag, regardless of whether or not
25225 the `__extension__' keyword is present. The caller is responsible
25226 for restoring the value of the PEDANTIC flag. */
25229 cp_parser_extension_opt (cp_parser
* parser
, int* saved_pedantic
)
25231 /* Save the old value of the PEDANTIC flag. */
25232 *saved_pedantic
= pedantic
;
25234 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_EXTENSION
))
25236 /* Consume the `__extension__' token. */
25237 cp_lexer_consume_token (parser
->lexer
);
25238 /* We're not being pedantic while the `__extension__' keyword is
25248 /* Parse a label declaration.
25251 __label__ label-declarator-seq ;
25253 label-declarator-seq:
25254 identifier , label-declarator-seq
25258 cp_parser_label_declaration (cp_parser
* parser
)
25260 /* Look for the `__label__' keyword. */
25261 cp_parser_require_keyword (parser
, RID_LABEL
, RT_LABEL
);
25267 /* Look for an identifier. */
25268 identifier
= cp_parser_identifier (parser
);
25269 /* If we failed, stop. */
25270 if (identifier
== error_mark_node
)
25272 /* Declare it as a label. */
25273 finish_label_decl (identifier
);
25274 /* If the next token is a `;', stop. */
25275 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
25277 /* Look for the `,' separating the label declarations. */
25278 cp_parser_require (parser
, CPP_COMMA
, RT_COMMA
);
25281 /* Look for the final `;'. */
25282 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
25285 // -------------------------------------------------------------------------- //
25288 // Parse a requires clause.
25290 // requires-clause:
25291 // 'requires' logical-or-expression
25293 // The required logical-or-expression must be a constant expression. Note
25294 // that we don't check that the expression is constepxr here. We defer until
25295 // we analyze constraints and then, we only check atomic constraints.
25297 cp_parser_requires_clause (cp_parser
*parser
)
25299 // Parse the requires clause so that it is not automatically folded.
25300 ++processing_template_decl
;
25301 tree expr
= cp_parser_binary_expression (parser
, false, false,
25302 PREC_NOT_OPERATOR
, NULL
);
25303 if (check_for_bare_parameter_packs (expr
))
25304 expr
= error_mark_node
;
25305 --processing_template_decl
;
25309 // Optionally parse a requires clause:
25311 cp_parser_requires_clause_opt (cp_parser
*parser
)
25313 cp_token
*tok
= cp_lexer_peek_token (parser
->lexer
);
25314 if (tok
->keyword
!= RID_REQUIRES
)
25316 if (!flag_concepts
&& tok
->type
== CPP_NAME
25317 && tok
->u
.value
== ridpointers
[RID_REQUIRES
])
25319 error_at (cp_lexer_peek_token (parser
->lexer
)->location
,
25320 "%<requires%> only available with -fconcepts");
25321 /* Parse and discard the requires-clause. */
25322 cp_lexer_consume_token (parser
->lexer
);
25323 cp_parser_requires_clause (parser
);
25327 cp_lexer_consume_token (parser
->lexer
);
25328 return cp_parser_requires_clause (parser
);
25332 /*---------------------------------------------------------------------------
25333 Requires expressions
25334 ---------------------------------------------------------------------------*/
25336 /* Parse a requires expression
25338 requirement-expression:
25339 'requires' requirement-parameter-list [opt] requirement-body */
25341 cp_parser_requires_expression (cp_parser
*parser
)
25343 gcc_assert (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_REQUIRES
));
25344 location_t loc
= cp_lexer_consume_token (parser
->lexer
)->location
;
25346 /* A requires-expression shall appear only within a concept
25347 definition or a requires-clause.
25349 TODO: Implement this diagnostic correctly. */
25350 if (!processing_template_decl
)
25352 error_at (loc
, "a requires expression cannot appear outside a template");
25353 cp_parser_skip_to_end_of_statement (parser
);
25354 return error_mark_node
;
25359 /* Local parameters are delared as variables within the scope
25360 of the expression. They are not visible past the end of
25361 the expression. Expressions within the requires-expression
25362 are unevaluated. */
25363 struct scope_sentinel
25367 ++cp_unevaluated_operand
;
25368 begin_scope (sk_block
, NULL_TREE
);
25373 pop_bindings_and_leave_scope ();
25374 --cp_unevaluated_operand
;
25378 /* Parse the optional parameter list. */
25379 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
25381 parms
= cp_parser_requirement_parameter_list (parser
);
25382 if (parms
== error_mark_node
)
25383 return error_mark_node
;
25388 /* Parse the requirement body. */
25389 reqs
= cp_parser_requirement_body (parser
);
25390 if (reqs
== error_mark_node
)
25391 return error_mark_node
;
25394 /* This needs to happen after pop_bindings_and_leave_scope, as it reverses
25396 grokparms (parms
, &parms
);
25397 return finish_requires_expr (parms
, reqs
);
25400 /* Parse a parameterized requirement.
25402 requirement-parameter-list:
25403 '(' parameter-declaration-clause ')' */
25405 cp_parser_requirement_parameter_list (cp_parser
*parser
)
25407 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
25408 return error_mark_node
;
25410 tree parms
= cp_parser_parameter_declaration_clause (parser
);
25412 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
25413 return error_mark_node
;
25418 /* Parse the body of a requirement.
25421 '{' requirement-list '}' */
25423 cp_parser_requirement_body (cp_parser
*parser
)
25425 if (!cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
))
25426 return error_mark_node
;
25428 tree reqs
= cp_parser_requirement_list (parser
);
25430 if (!cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
))
25431 return error_mark_node
;
25436 /* Parse a list of requirements.
25440 requirement-list ';' requirement[opt] */
25442 cp_parser_requirement_list (cp_parser
*parser
)
25444 tree result
= NULL_TREE
;
25447 tree req
= cp_parser_requirement (parser
);
25448 if (req
== error_mark_node
)
25449 return error_mark_node
;
25451 result
= tree_cons (NULL_TREE
, req
, result
);
25453 /* If we see a semi-colon, consume it. */
25454 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
25455 cp_lexer_consume_token (parser
->lexer
);
25457 /* Stop processing at the end of the list. */
25458 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_BRACE
))
25462 /* Reverse the order of requirements so they are analyzed in
25463 declaration order. */
25464 return nreverse (result
);
25467 /* Parse a syntactic requirement or type requirement.
25471 compound-requirement
25473 nested-requirement */
25475 cp_parser_requirement (cp_parser
*parser
)
25477 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
25478 return cp_parser_compound_requirement (parser
);
25479 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TYPENAME
))
25480 return cp_parser_type_requirement (parser
);
25481 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_REQUIRES
))
25482 return cp_parser_nested_requirement (parser
);
25484 return cp_parser_simple_requirement (parser
);
25487 /* Parse a simple requirement.
25489 simple-requirement:
25492 cp_parser_simple_requirement (cp_parser
*parser
)
25494 tree expr
= cp_parser_expression (parser
, NULL
, false, false);
25495 if (!expr
|| expr
== error_mark_node
)
25496 return error_mark_node
;
25498 if (!cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
))
25499 return error_mark_node
;
25501 return finish_simple_requirement (expr
);
25504 /* Parse a type requirement
25507 nested-name-specifier [opt] required-type-name ';'
25509 required-type-name:
25511 'template' [opt] simple-template-id */
25513 cp_parser_type_requirement (cp_parser
*parser
)
25515 cp_lexer_consume_token (parser
->lexer
);
25517 // Save the scope before parsing name specifiers.
25518 tree saved_scope
= parser
->scope
;
25519 tree saved_object_scope
= parser
->object_scope
;
25520 tree saved_qualifying_scope
= parser
->qualifying_scope
;
25521 cp_parser_global_scope_opt (parser
, /*current_scope_valid_p=*/true);
25522 cp_parser_nested_name_specifier_opt (parser
,
25523 /*typename_keyword_p=*/true,
25524 /*check_dependency_p=*/false,
25526 /*is_declaration=*/false);
25529 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TEMPLATE
))
25531 cp_lexer_consume_token (parser
->lexer
);
25532 type
= cp_parser_template_id (parser
,
25533 /*template_keyword_p=*/true,
25534 /*check_dependency=*/false,
25535 /*tag_type=*/none_type
,
25536 /*is_declaration=*/false);
25537 type
= make_typename_type (parser
->scope
, type
, typename_type
,
25538 /*complain=*/tf_error
);
25541 type
= cp_parser_type_name (parser
, /*typename_keyword_p=*/true);
25543 if (TREE_CODE (type
) == TYPE_DECL
)
25544 type
= TREE_TYPE (type
);
25546 parser
->scope
= saved_scope
;
25547 parser
->object_scope
= saved_object_scope
;
25548 parser
->qualifying_scope
= saved_qualifying_scope
;
25550 if (type
== error_mark_node
)
25551 cp_parser_skip_to_end_of_statement (parser
);
25553 if (!cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
))
25554 return error_mark_node
;
25555 if (type
== error_mark_node
)
25556 return error_mark_node
;
25558 return finish_type_requirement (type
);
25561 /* Parse a compound requirement
25563 compound-requirement:
25564 '{' expression '}' 'noexcept' [opt] trailing-return-type [opt] ';' */
25566 cp_parser_compound_requirement (cp_parser
*parser
)
25568 /* Parse an expression enclosed in '{ }'s. */
25569 if (!cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
))
25570 return error_mark_node
;
25572 tree expr
= cp_parser_expression (parser
, NULL
, false, false);
25573 if (!expr
|| expr
== error_mark_node
)
25574 return error_mark_node
;
25576 if (!cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
))
25577 return error_mark_node
;
25579 /* Parse the optional noexcept. */
25580 bool noexcept_p
= false;
25581 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_NOEXCEPT
))
25583 cp_lexer_consume_token (parser
->lexer
);
25587 /* Parse the optional trailing return type. */
25588 tree type
= NULL_TREE
;
25589 if (cp_lexer_next_token_is (parser
->lexer
, CPP_DEREF
))
25591 cp_lexer_consume_token (parser
->lexer
);
25592 bool saved_result_type_constraint_p
= parser
->in_result_type_constraint_p
;
25593 parser
->in_result_type_constraint_p
= true;
25594 type
= cp_parser_trailing_type_id (parser
);
25595 parser
->in_result_type_constraint_p
= saved_result_type_constraint_p
;
25596 if (type
== error_mark_node
)
25597 return error_mark_node
;
25600 return finish_compound_requirement (expr
, type
, noexcept_p
);
25603 /* Parse a nested requirement. This is the same as a requires clause.
25605 nested-requirement:
25608 cp_parser_nested_requirement (cp_parser
*parser
)
25610 cp_lexer_consume_token (parser
->lexer
);
25611 tree req
= cp_parser_requires_clause (parser
);
25612 if (req
== error_mark_node
)
25613 return error_mark_node
;
25614 return finish_nested_requirement (req
);
25617 /* Support Functions */
25619 /* Return the appropriate prefer_type argument for lookup_name_real based on
25620 tag_type and template_mem_access. */
25623 prefer_type_arg (tag_types tag_type
, bool template_mem_access
= false)
25625 /* DR 141: When looking in the current enclosing context for a template-name
25626 after -> or ., only consider class templates. */
25627 if (template_mem_access
)
25631 case none_type
: return 0; // No preference.
25632 case scope_type
: return 1; // Type or namespace.
25633 default: return 2; // Type only.
25637 /* Looks up NAME in the current scope, as given by PARSER->SCOPE.
25638 NAME should have one of the representations used for an
25639 id-expression. If NAME is the ERROR_MARK_NODE, the ERROR_MARK_NODE
25640 is returned. If PARSER->SCOPE is a dependent type, then a
25641 SCOPE_REF is returned.
25643 If NAME is a TEMPLATE_ID_EXPR, then it will be immediately
25644 returned; the name was already resolved when the TEMPLATE_ID_EXPR
25645 was formed. Abstractly, such entities should not be passed to this
25646 function, because they do not need to be looked up, but it is
25647 simpler to check for this special case here, rather than at the
25650 In cases not explicitly covered above, this function returns a
25651 DECL, OVERLOAD, or baselink representing the result of the lookup.
25652 If there was no entity with the indicated NAME, the ERROR_MARK_NODE
25655 If TAG_TYPE is not NONE_TYPE, it indicates an explicit type keyword
25656 (e.g., "struct") that was used. In that case bindings that do not
25657 refer to types are ignored.
25659 If IS_TEMPLATE is TRUE, bindings that do not refer to templates are
25662 If IS_NAMESPACE is TRUE, bindings that do not refer to namespaces
25665 If CHECK_DEPENDENCY is TRUE, names are not looked up in dependent
25668 If AMBIGUOUS_DECLS is non-NULL, *AMBIGUOUS_DECLS is set to a
25669 TREE_LIST of candidates if name-lookup results in an ambiguity, and
25670 NULL_TREE otherwise. */
25673 cp_parser_lookup_name (cp_parser
*parser
, tree name
,
25674 enum tag_types tag_type
,
25677 bool check_dependency
,
25678 tree
*ambiguous_decls
,
25679 location_t name_location
)
25682 tree object_type
= parser
->context
->object_type
;
25684 /* Assume that the lookup will be unambiguous. */
25685 if (ambiguous_decls
)
25686 *ambiguous_decls
= NULL_TREE
;
25688 /* Now that we have looked up the name, the OBJECT_TYPE (if any) is
25689 no longer valid. Note that if we are parsing tentatively, and
25690 the parse fails, OBJECT_TYPE will be automatically restored. */
25691 parser
->context
->object_type
= NULL_TREE
;
25693 if (name
== error_mark_node
)
25694 return error_mark_node
;
25696 /* A template-id has already been resolved; there is no lookup to
25698 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
25700 if (BASELINK_P (name
))
25702 gcc_assert (TREE_CODE (BASELINK_FUNCTIONS (name
))
25703 == TEMPLATE_ID_EXPR
);
25707 /* A BIT_NOT_EXPR is used to represent a destructor. By this point,
25708 it should already have been checked to make sure that the name
25709 used matches the type being destroyed. */
25710 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
25714 /* Figure out to which type this destructor applies. */
25716 type
= parser
->scope
;
25717 else if (object_type
)
25718 type
= object_type
;
25720 type
= current_class_type
;
25721 /* If that's not a class type, there is no destructor. */
25722 if (!type
|| !CLASS_TYPE_P (type
))
25723 return error_mark_node
;
25725 if (CLASSTYPE_LAZY_DESTRUCTOR (type
))
25726 lazily_declare_fn (sfk_destructor
, type
);
25728 if (tree dtor
= CLASSTYPE_DESTRUCTOR (type
))
25731 return error_mark_node
;
25734 /* By this point, the NAME should be an ordinary identifier. If
25735 the id-expression was a qualified name, the qualifying scope is
25736 stored in PARSER->SCOPE at this point. */
25737 gcc_assert (identifier_p (name
));
25739 /* Perform the lookup. */
25744 if (parser
->scope
== error_mark_node
)
25745 return error_mark_node
;
25747 /* If the SCOPE is dependent, the lookup must be deferred until
25748 the template is instantiated -- unless we are explicitly
25749 looking up names in uninstantiated templates. Even then, we
25750 cannot look up the name if the scope is not a class type; it
25751 might, for example, be a template type parameter. */
25752 dependent_p
= (TYPE_P (parser
->scope
)
25753 && dependent_scope_p (parser
->scope
));
25754 if ((check_dependency
|| !CLASS_TYPE_P (parser
->scope
))
25756 /* Defer lookup. */
25757 decl
= error_mark_node
;
25760 tree pushed_scope
= NULL_TREE
;
25762 /* If PARSER->SCOPE is a dependent type, then it must be a
25763 class type, and we must not be checking dependencies;
25764 otherwise, we would have processed this lookup above. So
25765 that PARSER->SCOPE is not considered a dependent base by
25766 lookup_member, we must enter the scope here. */
25768 pushed_scope
= push_scope (parser
->scope
);
25770 /* If the PARSER->SCOPE is a template specialization, it
25771 may be instantiated during name lookup. In that case,
25772 errors may be issued. Even if we rollback the current
25773 tentative parse, those errors are valid. */
25774 decl
= lookup_qualified_name (parser
->scope
, name
,
25775 prefer_type_arg (tag_type
),
25776 /*complain=*/true);
25778 /* 3.4.3.1: In a lookup in which the constructor is an acceptable
25779 lookup result and the nested-name-specifier nominates a class C:
25780 * if the name specified after the nested-name-specifier, when
25781 looked up in C, is the injected-class-name of C (Clause 9), or
25782 * if the name specified after the nested-name-specifier is the
25783 same as the identifier or the simple-template-id's template-
25784 name in the last component of the nested-name-specifier,
25785 the name is instead considered to name the constructor of
25786 class C. [ Note: for example, the constructor is not an
25787 acceptable lookup result in an elaborated-type-specifier so
25788 the constructor would not be used in place of the
25789 injected-class-name. --end note ] Such a constructor name
25790 shall be used only in the declarator-id of a declaration that
25791 names a constructor or in a using-declaration. */
25792 if (tag_type
== none_type
25793 && DECL_SELF_REFERENCE_P (decl
)
25794 && same_type_p (DECL_CONTEXT (decl
), parser
->scope
))
25795 decl
= lookup_qualified_name (parser
->scope
, ctor_identifier
,
25796 prefer_type_arg (tag_type
),
25797 /*complain=*/true);
25799 /* If we have a single function from a using decl, pull it out. */
25800 if (TREE_CODE (decl
) == OVERLOAD
25801 && !really_overloaded_fn (decl
))
25802 decl
= OVL_FUNCTION (decl
);
25805 pop_scope (pushed_scope
);
25808 /* If the scope is a dependent type and either we deferred lookup or
25809 we did lookup but didn't find the name, rememeber the name. */
25810 if (decl
== error_mark_node
&& TYPE_P (parser
->scope
)
25811 && dependent_type_p (parser
->scope
))
25817 /* The resolution to Core Issue 180 says that `struct
25818 A::B' should be considered a type-name, even if `A'
25820 type
= make_typename_type (parser
->scope
, name
, tag_type
,
25821 /*complain=*/tf_error
);
25822 if (type
!= error_mark_node
)
25823 decl
= TYPE_NAME (type
);
25825 else if (is_template
25826 && (cp_parser_next_token_ends_template_argument_p (parser
)
25827 || cp_lexer_next_token_is (parser
->lexer
,
25829 decl
= make_unbound_class_template (parser
->scope
,
25831 /*complain=*/tf_error
);
25833 decl
= build_qualified_name (/*type=*/NULL_TREE
,
25834 parser
->scope
, name
,
25837 parser
->qualifying_scope
= parser
->scope
;
25838 parser
->object_scope
= NULL_TREE
;
25840 else if (object_type
)
25842 /* Look up the name in the scope of the OBJECT_TYPE, unless the
25843 OBJECT_TYPE is not a class. */
25844 if (CLASS_TYPE_P (object_type
))
25845 /* If the OBJECT_TYPE is a template specialization, it may
25846 be instantiated during name lookup. In that case, errors
25847 may be issued. Even if we rollback the current tentative
25848 parse, those errors are valid. */
25849 decl
= lookup_member (object_type
,
25852 prefer_type_arg (tag_type
),
25853 tf_warning_or_error
);
25859 /* Look it up in the enclosing context. */
25860 decl
= lookup_name_real (name
, prefer_type_arg (tag_type
),
25862 /*block_p=*/true, is_namespace
, 0);
25863 /* DR 141 says when looking for a template-name after -> or ., only
25864 consider class templates. */
25865 if (decl
&& is_template
&& !DECL_TYPE_TEMPLATE_P (decl
))
25868 if (is_overloaded_fn (d
))
25869 d
= get_first_fn (d
);
25870 if (DECL_P (d
) && !DECL_CLASS_SCOPE_P (d
))
25874 if (object_type
== unknown_type_node
)
25875 /* The object is type-dependent, so we can't look anything up; we used
25876 this to get the DR 141 behavior. */
25877 object_type
= NULL_TREE
;
25878 parser
->object_scope
= object_type
;
25879 parser
->qualifying_scope
= NULL_TREE
;
25883 decl
= lookup_name_real (name
, prefer_type_arg (tag_type
),
25885 /*block_p=*/true, is_namespace
, 0);
25886 parser
->qualifying_scope
= NULL_TREE
;
25887 parser
->object_scope
= NULL_TREE
;
25890 /* If the lookup failed, let our caller know. */
25891 if (!decl
|| decl
== error_mark_node
)
25892 return error_mark_node
;
25894 /* Pull out the template from an injected-class-name (or multiple). */
25896 decl
= maybe_get_template_decl_from_type_decl (decl
);
25898 /* If it's a TREE_LIST, the result of the lookup was ambiguous. */
25899 if (TREE_CODE (decl
) == TREE_LIST
)
25901 if (ambiguous_decls
)
25902 *ambiguous_decls
= decl
;
25903 /* The error message we have to print is too complicated for
25904 cp_parser_error, so we incorporate its actions directly. */
25905 if (!cp_parser_simulate_error (parser
))
25907 error_at (name_location
, "reference to %qD is ambiguous",
25909 print_candidates (decl
);
25911 return error_mark_node
;
25914 gcc_assert (DECL_P (decl
)
25915 || TREE_CODE (decl
) == OVERLOAD
25916 || TREE_CODE (decl
) == SCOPE_REF
25917 || TREE_CODE (decl
) == UNBOUND_CLASS_TEMPLATE
25918 || BASELINK_P (decl
));
25920 /* If we have resolved the name of a member declaration, check to
25921 see if the declaration is accessible. When the name resolves to
25922 set of overloaded functions, accessibility is checked when
25923 overload resolution is done.
25925 During an explicit instantiation, access is not checked at all,
25926 as per [temp.explicit]. */
25928 check_accessibility_of_qualified_id (decl
, object_type
, parser
->scope
);
25930 maybe_record_typedef_use (decl
);
25932 return cp_expr (decl
, name_location
);
25935 /* Like cp_parser_lookup_name, but for use in the typical case where
25936 CHECK_ACCESS is TRUE, IS_TYPE is FALSE, IS_TEMPLATE is FALSE,
25937 IS_NAMESPACE is FALSE, and CHECK_DEPENDENCY is TRUE. */
25940 cp_parser_lookup_name_simple (cp_parser
* parser
, tree name
, location_t location
)
25942 return cp_parser_lookup_name (parser
, name
,
25944 /*is_template=*/false,
25945 /*is_namespace=*/false,
25946 /*check_dependency=*/true,
25947 /*ambiguous_decls=*/NULL
,
25951 /* If DECL is a TEMPLATE_DECL that can be treated like a TYPE_DECL in
25952 the current context, return the TYPE_DECL. If TAG_NAME_P is
25953 true, the DECL indicates the class being defined in a class-head,
25954 or declared in an elaborated-type-specifier.
25956 Otherwise, return DECL. */
25959 cp_parser_maybe_treat_template_as_class (tree decl
, bool tag_name_p
)
25961 /* If the TEMPLATE_DECL is being declared as part of a class-head,
25962 the translation from TEMPLATE_DECL to TYPE_DECL occurs:
25965 template <typename T> struct B;
25968 template <typename T> struct A::B {};
25970 Similarly, in an elaborated-type-specifier:
25972 namespace N { struct X{}; }
25975 template <typename T> friend struct N::X;
25978 However, if the DECL refers to a class type, and we are in
25979 the scope of the class, then the name lookup automatically
25980 finds the TYPE_DECL created by build_self_reference rather
25981 than a TEMPLATE_DECL. For example, in:
25983 template <class T> struct S {
25987 there is no need to handle such case. */
25989 if (DECL_CLASS_TEMPLATE_P (decl
) && tag_name_p
)
25990 return DECL_TEMPLATE_RESULT (decl
);
25995 /* If too many, or too few, template-parameter lists apply to the
25996 declarator, issue an error message. Returns TRUE if all went well,
25997 and FALSE otherwise. */
26000 cp_parser_check_declarator_template_parameters (cp_parser
* parser
,
26001 cp_declarator
*declarator
,
26002 location_t declarator_location
)
26004 switch (declarator
->kind
)
26008 unsigned num_templates
= 0;
26009 tree scope
= declarator
->u
.id
.qualifying_scope
;
26012 num_templates
= num_template_headers_for_class (scope
);
26013 else if (TREE_CODE (declarator
->u
.id
.unqualified_name
)
26014 == TEMPLATE_ID_EXPR
)
26015 /* If the DECLARATOR has the form `X<y>' then it uses one
26016 additional level of template parameters. */
26019 return cp_parser_check_template_parameters
26020 (parser
, num_templates
, declarator_location
, declarator
);
26026 case cdk_reference
:
26028 return (cp_parser_check_declarator_template_parameters
26029 (parser
, declarator
->declarator
, declarator_location
));
26036 gcc_unreachable ();
26041 /* NUM_TEMPLATES were used in the current declaration. If that is
26042 invalid, return FALSE and issue an error messages. Otherwise,
26043 return TRUE. If DECLARATOR is non-NULL, then we are checking a
26044 declarator and we can print more accurate diagnostics. */
26047 cp_parser_check_template_parameters (cp_parser
* parser
,
26048 unsigned num_templates
,
26049 location_t location
,
26050 cp_declarator
*declarator
)
26052 /* If there are the same number of template classes and parameter
26053 lists, that's OK. */
26054 if (parser
->num_template_parameter_lists
== num_templates
)
26056 /* If there are more, but only one more, then we are referring to a
26057 member template. That's OK too. */
26058 if (parser
->num_template_parameter_lists
== num_templates
+ 1)
26060 /* If there are more template classes than parameter lists, we have
26063 template <class T> void S<T>::R<T>::f (); */
26064 if (parser
->num_template_parameter_lists
< num_templates
)
26066 if (declarator
&& !current_function_decl
)
26067 error_at (location
, "specializing member %<%T::%E%> "
26068 "requires %<template<>%> syntax",
26069 declarator
->u
.id
.qualifying_scope
,
26070 declarator
->u
.id
.unqualified_name
);
26071 else if (declarator
)
26072 error_at (location
, "invalid declaration of %<%T::%E%>",
26073 declarator
->u
.id
.qualifying_scope
,
26074 declarator
->u
.id
.unqualified_name
);
26076 error_at (location
, "too few template-parameter-lists");
26079 /* Otherwise, there are too many template parameter lists. We have
26082 template <class T> template <class U> void S::f(); */
26083 error_at (location
, "too many template-parameter-lists");
26087 /* Parse an optional `::' token indicating that the following name is
26088 from the global namespace. If so, PARSER->SCOPE is set to the
26089 GLOBAL_NAMESPACE. Otherwise, PARSER->SCOPE is set to NULL_TREE,
26090 unless CURRENT_SCOPE_VALID_P is TRUE, in which case it is left alone.
26091 Returns the new value of PARSER->SCOPE, if the `::' token is
26092 present, and NULL_TREE otherwise. */
26095 cp_parser_global_scope_opt (cp_parser
* parser
, bool current_scope_valid_p
)
26099 /* Peek at the next token. */
26100 token
= cp_lexer_peek_token (parser
->lexer
);
26101 /* If we're looking at a `::' token then we're starting from the
26102 global namespace, not our current location. */
26103 if (token
->type
== CPP_SCOPE
)
26105 /* Consume the `::' token. */
26106 cp_lexer_consume_token (parser
->lexer
);
26107 /* Set the SCOPE so that we know where to start the lookup. */
26108 parser
->scope
= global_namespace
;
26109 parser
->qualifying_scope
= global_namespace
;
26110 parser
->object_scope
= NULL_TREE
;
26112 return parser
->scope
;
26114 else if (!current_scope_valid_p
)
26116 parser
->scope
= NULL_TREE
;
26117 parser
->qualifying_scope
= NULL_TREE
;
26118 parser
->object_scope
= NULL_TREE
;
26124 /* Returns TRUE if the upcoming token sequence is the start of a
26125 constructor declarator or C++17 deduction guide. If FRIEND_P is true, the
26126 declarator is preceded by the `friend' specifier. */
26129 cp_parser_constructor_declarator_p (cp_parser
*parser
, bool friend_p
)
26131 bool constructor_p
;
26132 bool outside_class_specifier_p
;
26133 tree nested_name_specifier
;
26134 cp_token
*next_token
;
26136 /* The common case is that this is not a constructor declarator, so
26137 try to avoid doing lots of work if at all possible. It's not
26138 valid declare a constructor at function scope. */
26139 if (parser
->in_function_body
)
26141 /* And only certain tokens can begin a constructor declarator. */
26142 next_token
= cp_lexer_peek_token (parser
->lexer
);
26143 if (next_token
->type
!= CPP_NAME
26144 && next_token
->type
!= CPP_SCOPE
26145 && next_token
->type
!= CPP_NESTED_NAME_SPECIFIER
26146 && next_token
->type
!= CPP_TEMPLATE_ID
)
26149 /* Parse tentatively; we are going to roll back all of the tokens
26151 cp_parser_parse_tentatively (parser
);
26152 /* Assume that we are looking at a constructor declarator. */
26153 constructor_p
= true;
26155 /* Look for the optional `::' operator. */
26156 cp_parser_global_scope_opt (parser
,
26157 /*current_scope_valid_p=*/false);
26158 /* Look for the nested-name-specifier. */
26159 nested_name_specifier
26160 = (cp_parser_nested_name_specifier_opt (parser
,
26161 /*typename_keyword_p=*/false,
26162 /*check_dependency_p=*/false,
26164 /*is_declaration=*/false));
26166 outside_class_specifier_p
= (!at_class_scope_p ()
26167 || !TYPE_BEING_DEFINED (current_class_type
)
26170 /* Outside of a class-specifier, there must be a
26171 nested-name-specifier. Except in C++17 mode, where we
26172 might be declaring a guiding declaration. */
26173 if (!nested_name_specifier
&& outside_class_specifier_p
26174 && cxx_dialect
< cxx1z
)
26175 constructor_p
= false;
26176 else if (nested_name_specifier
== error_mark_node
)
26177 constructor_p
= false;
26179 /* If we have a class scope, this is easy; DR 147 says that S::S always
26180 names the constructor, and no other qualified name could. */
26181 if (constructor_p
&& nested_name_specifier
26182 && CLASS_TYPE_P (nested_name_specifier
))
26184 tree id
= cp_parser_unqualified_id (parser
,
26185 /*template_keyword_p=*/false,
26186 /*check_dependency_p=*/false,
26187 /*declarator_p=*/true,
26188 /*optional_p=*/false);
26189 if (is_overloaded_fn (id
))
26190 id
= DECL_NAME (get_first_fn (id
));
26191 if (!constructor_name_p (id
, nested_name_specifier
))
26192 constructor_p
= false;
26194 /* If we still think that this might be a constructor-declarator,
26195 look for a class-name. */
26196 else if (constructor_p
)
26200 template <typename T> struct S {
26204 we must recognize that the nested `S' names a class. */
26205 if (cxx_dialect
>= cxx1z
)
26206 cp_parser_parse_tentatively (parser
);
26209 type_decl
= cp_parser_class_name (parser
,
26210 /*typename_keyword_p=*/false,
26211 /*template_keyword_p=*/false,
26213 /*check_dependency_p=*/false,
26214 /*class_head_p=*/false,
26215 /*is_declaration=*/false);
26217 if (cxx_dialect
>= cxx1z
26218 && !cp_parser_parse_definitely (parser
))
26220 type_decl
= NULL_TREE
;
26221 tree tmpl
= cp_parser_template_name (parser
,
26222 /*template_keyword*/false,
26223 /*check_dependency_p*/false,
26224 /*is_declaration*/false,
26226 /*is_identifier*/NULL
);
26227 if (DECL_CLASS_TEMPLATE_P (tmpl
)
26228 || DECL_TEMPLATE_TEMPLATE_PARM_P (tmpl
))
26229 /* It's a deduction guide, return true. */;
26231 cp_parser_simulate_error (parser
);
26234 /* If there was no class-name, then this is not a constructor.
26235 Otherwise, if we are in a class-specifier and we aren't
26236 handling a friend declaration, check that its type matches
26237 current_class_type (c++/38313). Note: error_mark_node
26238 is left alone for error recovery purposes. */
26239 constructor_p
= (!cp_parser_error_occurred (parser
)
26240 && (outside_class_specifier_p
26241 || type_decl
== NULL_TREE
26242 || type_decl
== error_mark_node
26243 || same_type_p (current_class_type
,
26244 TREE_TYPE (type_decl
))));
26246 /* If we're still considering a constructor, we have to see a `(',
26247 to begin the parameter-declaration-clause, followed by either a
26248 `)', an `...', or a decl-specifier. We need to check for a
26249 type-specifier to avoid being fooled into thinking that:
26253 is a constructor. (It is actually a function named `f' that
26254 takes one parameter (of type `int') and returns a value of type
26257 && !cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
26258 constructor_p
= false;
26261 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_PAREN
)
26262 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_ELLIPSIS
)
26263 /* A parameter declaration begins with a decl-specifier,
26264 which is either the "attribute" keyword, a storage class
26265 specifier, or (usually) a type-specifier. */
26266 && !cp_lexer_next_token_is_decl_specifier_keyword (parser
->lexer
))
26269 tree pushed_scope
= NULL_TREE
;
26270 unsigned saved_num_template_parameter_lists
;
26272 /* Names appearing in the type-specifier should be looked up
26273 in the scope of the class. */
26274 if (current_class_type
)
26276 else if (type_decl
)
26278 type
= TREE_TYPE (type_decl
);
26279 if (TREE_CODE (type
) == TYPENAME_TYPE
)
26281 type
= resolve_typename_type (type
,
26282 /*only_current_p=*/false);
26283 if (TREE_CODE (type
) == TYPENAME_TYPE
)
26285 cp_parser_abort_tentative_parse (parser
);
26289 pushed_scope
= push_scope (type
);
26292 /* Inside the constructor parameter list, surrounding
26293 template-parameter-lists do not apply. */
26294 saved_num_template_parameter_lists
26295 = parser
->num_template_parameter_lists
;
26296 parser
->num_template_parameter_lists
= 0;
26298 /* Look for the type-specifier. */
26299 cp_parser_type_specifier (parser
,
26300 CP_PARSER_FLAGS_NONE
,
26301 /*decl_specs=*/NULL
,
26302 /*is_declarator=*/true,
26303 /*declares_class_or_enum=*/NULL
,
26304 /*is_cv_qualifier=*/NULL
);
26306 parser
->num_template_parameter_lists
26307 = saved_num_template_parameter_lists
;
26309 /* Leave the scope of the class. */
26311 pop_scope (pushed_scope
);
26313 constructor_p
= !cp_parser_error_occurred (parser
);
26317 /* We did not really want to consume any tokens. */
26318 cp_parser_abort_tentative_parse (parser
);
26320 return constructor_p
;
26323 /* Parse the definition of the function given by the DECL_SPECIFIERS,
26324 ATTRIBUTES, and DECLARATOR. The access checks have been deferred;
26325 they must be performed once we are in the scope of the function.
26327 Returns the function defined. */
26330 cp_parser_function_definition_from_specifiers_and_declarator
26331 (cp_parser
* parser
,
26332 cp_decl_specifier_seq
*decl_specifiers
,
26334 const cp_declarator
*declarator
)
26339 /* Begin the function-definition. */
26340 success_p
= start_function (decl_specifiers
, declarator
, attributes
);
26342 /* The things we're about to see are not directly qualified by any
26343 template headers we've seen thus far. */
26344 reset_specialization ();
26346 /* If there were names looked up in the decl-specifier-seq that we
26347 did not check, check them now. We must wait until we are in the
26348 scope of the function to perform the checks, since the function
26349 might be a friend. */
26350 perform_deferred_access_checks (tf_warning_or_error
);
26354 cp_finalize_omp_declare_simd (parser
, current_function_decl
);
26355 parser
->omp_declare_simd
= NULL
;
26356 cp_finalize_oacc_routine (parser
, current_function_decl
, true);
26357 parser
->oacc_routine
= NULL
;
26362 /* Skip the entire function. */
26363 cp_parser_skip_to_end_of_block_or_statement (parser
);
26364 fn
= error_mark_node
;
26366 else if (DECL_INITIAL (current_function_decl
) != error_mark_node
)
26368 /* Seen already, skip it. An error message has already been output. */
26369 cp_parser_skip_to_end_of_block_or_statement (parser
);
26370 fn
= current_function_decl
;
26371 current_function_decl
= NULL_TREE
;
26372 /* If this is a function from a class, pop the nested class. */
26373 if (current_class_name
)
26374 pop_nested_class ();
26379 if (DECL_DECLARED_INLINE_P (current_function_decl
))
26380 tv
= TV_PARSE_INLINE
;
26382 tv
= TV_PARSE_FUNC
;
26384 fn
= cp_parser_function_definition_after_declarator (parser
,
26385 /*inline_p=*/false);
26392 /* Parse the part of a function-definition that follows the
26393 declarator. INLINE_P is TRUE iff this function is an inline
26394 function defined within a class-specifier.
26396 Returns the function defined. */
26399 cp_parser_function_definition_after_declarator (cp_parser
* parser
,
26403 bool ctor_initializer_p
= false;
26404 bool saved_in_unbraced_linkage_specification_p
;
26405 bool saved_in_function_body
;
26406 unsigned saved_num_template_parameter_lists
;
26408 bool fully_implicit_function_template_p
26409 = parser
->fully_implicit_function_template_p
;
26410 parser
->fully_implicit_function_template_p
= false;
26411 tree implicit_template_parms
26412 = parser
->implicit_template_parms
;
26413 parser
->implicit_template_parms
= 0;
26414 cp_binding_level
* implicit_template_scope
26415 = parser
->implicit_template_scope
;
26416 parser
->implicit_template_scope
= 0;
26418 saved_in_function_body
= parser
->in_function_body
;
26419 parser
->in_function_body
= true;
26420 /* If the next token is `return', then the code may be trying to
26421 make use of the "named return value" extension that G++ used to
26423 token
= cp_lexer_peek_token (parser
->lexer
);
26424 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_RETURN
))
26426 /* Consume the `return' keyword. */
26427 cp_lexer_consume_token (parser
->lexer
);
26428 /* Look for the identifier that indicates what value is to be
26430 cp_parser_identifier (parser
);
26431 /* Issue an error message. */
26432 error_at (token
->location
,
26433 "named return values are no longer supported");
26434 /* Skip tokens until we reach the start of the function body. */
26437 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
26438 if (token
->type
== CPP_OPEN_BRACE
26439 || token
->type
== CPP_EOF
26440 || token
->type
== CPP_PRAGMA_EOL
)
26442 cp_lexer_consume_token (parser
->lexer
);
26445 /* The `extern' in `extern "C" void f () { ... }' does not apply to
26446 anything declared inside `f'. */
26447 saved_in_unbraced_linkage_specification_p
26448 = parser
->in_unbraced_linkage_specification_p
;
26449 parser
->in_unbraced_linkage_specification_p
= false;
26450 /* Inside the function, surrounding template-parameter-lists do not
26452 saved_num_template_parameter_lists
26453 = parser
->num_template_parameter_lists
;
26454 parser
->num_template_parameter_lists
= 0;
26456 start_lambda_scope (current_function_decl
);
26458 /* If the next token is `try', `__transaction_atomic', or
26459 `__transaction_relaxed`, then we are looking at either function-try-block
26460 or function-transaction-block. Note that all of these include the
26462 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TRANSACTION_ATOMIC
))
26463 ctor_initializer_p
= cp_parser_function_transaction (parser
,
26464 RID_TRANSACTION_ATOMIC
);
26465 else if (cp_lexer_next_token_is_keyword (parser
->lexer
,
26466 RID_TRANSACTION_RELAXED
))
26467 ctor_initializer_p
= cp_parser_function_transaction (parser
,
26468 RID_TRANSACTION_RELAXED
);
26469 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TRY
))
26470 ctor_initializer_p
= cp_parser_function_try_block (parser
);
26472 ctor_initializer_p
= cp_parser_ctor_initializer_opt_and_function_body
26473 (parser
, /*in_function_try_block=*/false);
26475 finish_lambda_scope ();
26477 /* Finish the function. */
26478 fn
= finish_function ((ctor_initializer_p
? 1 : 0) |
26479 (inline_p
? 2 : 0));
26480 /* Generate code for it, if necessary. */
26481 expand_or_defer_fn (fn
);
26482 /* Restore the saved values. */
26483 parser
->in_unbraced_linkage_specification_p
26484 = saved_in_unbraced_linkage_specification_p
;
26485 parser
->num_template_parameter_lists
26486 = saved_num_template_parameter_lists
;
26487 parser
->in_function_body
= saved_in_function_body
;
26489 parser
->fully_implicit_function_template_p
26490 = fully_implicit_function_template_p
;
26491 parser
->implicit_template_parms
26492 = implicit_template_parms
;
26493 parser
->implicit_template_scope
26494 = implicit_template_scope
;
26496 if (parser
->fully_implicit_function_template_p
)
26497 finish_fully_implicit_template (parser
, /*member_decl_opt=*/0);
26502 /* Parse a template-declaration body (following argument list). */
26505 cp_parser_template_declaration_after_parameters (cp_parser
* parser
,
26506 tree parameter_list
,
26509 tree decl
= NULL_TREE
;
26510 bool friend_p
= false;
26512 /* We just processed one more parameter list. */
26513 ++parser
->num_template_parameter_lists
;
26515 /* Get the deferred access checks from the parameter list. These
26516 will be checked once we know what is being declared, as for a
26517 member template the checks must be performed in the scope of the
26518 class containing the member. */
26519 vec
<deferred_access_check
, va_gc
> *checks
= get_deferred_access_checks ();
26521 /* Tentatively parse for a new template parameter list, which can either be
26522 the template keyword or a template introduction. */
26523 if (cp_parser_template_declaration_after_export (parser
, member_p
))
26525 else if (cxx_dialect
>= cxx11
26526 && cp_lexer_next_token_is_keyword (parser
->lexer
, RID_USING
))
26527 decl
= cp_parser_alias_declaration (parser
);
26530 /* There are no access checks when parsing a template, as we do not
26531 know if a specialization will be a friend. */
26532 push_deferring_access_checks (dk_no_check
);
26533 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
26534 decl
= cp_parser_single_declaration (parser
,
26537 /*explicit_specialization_p=*/false,
26539 pop_deferring_access_checks ();
26541 /* If this is a member template declaration, let the front
26543 if (member_p
&& !friend_p
&& decl
)
26545 if (TREE_CODE (decl
) == TYPE_DECL
)
26546 cp_parser_check_access_in_redeclaration (decl
, token
->location
);
26548 decl
= finish_member_template_decl (decl
);
26550 else if (friend_p
&& decl
26551 && DECL_DECLARES_TYPE_P (decl
))
26552 make_friend_class (current_class_type
, TREE_TYPE (decl
),
26553 /*complain=*/true);
26555 /* We are done with the current parameter list. */
26556 --parser
->num_template_parameter_lists
;
26558 pop_deferring_access_checks ();
26561 finish_template_decl (parameter_list
);
26563 /* Check the template arguments for a literal operator template. */
26565 && DECL_DECLARES_FUNCTION_P (decl
)
26566 && UDLIT_OPER_P (DECL_NAME (decl
)))
26569 if (parameter_list
== NULL_TREE
)
26573 int num_parms
= TREE_VEC_LENGTH (parameter_list
);
26574 if (num_parms
== 1)
26576 tree parm_list
= TREE_VEC_ELT (parameter_list
, 0);
26577 tree parm
= INNERMOST_TEMPLATE_PARMS (parm_list
);
26578 if (TREE_TYPE (parm
) != char_type_node
26579 || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm
)))
26582 else if (num_parms
== 2 && cxx_dialect
>= cxx14
)
26584 tree parm_type
= TREE_VEC_ELT (parameter_list
, 0);
26585 tree type
= INNERMOST_TEMPLATE_PARMS (parm_type
);
26586 tree parm_list
= TREE_VEC_ELT (parameter_list
, 1);
26587 tree parm
= INNERMOST_TEMPLATE_PARMS (parm_list
);
26588 if (parm
== error_mark_node
26589 || TREE_TYPE (parm
) != TREE_TYPE (type
)
26590 || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm
)))
26598 if (cxx_dialect
>= cxx14
)
26599 error ("literal operator template %qD has invalid parameter list."
26600 " Expected non-type template argument pack <char...>"
26601 " or <typename CharT, CharT...>",
26604 error ("literal operator template %qD has invalid parameter list."
26605 " Expected non-type template argument pack <char...>",
26610 /* Register member declarations. */
26611 if (member_p
&& !friend_p
&& decl
&& !DECL_CLASS_TEMPLATE_P (decl
))
26612 finish_member_declaration (decl
);
26613 /* If DECL is a function template, we must return to parse it later.
26614 (Even though there is no definition, there might be default
26615 arguments that need handling.) */
26616 if (member_p
&& decl
26617 && DECL_DECLARES_FUNCTION_P (decl
))
26618 vec_safe_push (unparsed_funs_with_definitions
, decl
);
26621 /* Parse a template introduction header for a template-declaration. Returns
26622 false if tentative parse fails. */
26625 cp_parser_template_introduction (cp_parser
* parser
, bool member_p
)
26627 cp_parser_parse_tentatively (parser
);
26629 tree saved_scope
= parser
->scope
;
26630 tree saved_object_scope
= parser
->object_scope
;
26631 tree saved_qualifying_scope
= parser
->qualifying_scope
;
26633 /* Look for the optional `::' operator. */
26634 cp_parser_global_scope_opt (parser
,
26635 /*current_scope_valid_p=*/false);
26636 /* Look for the nested-name-specifier. */
26637 cp_parser_nested_name_specifier_opt (parser
,
26638 /*typename_keyword_p=*/false,
26639 /*check_dependency_p=*/true,
26641 /*is_declaration=*/false);
26643 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
26644 tree concept_name
= cp_parser_identifier (parser
);
26646 /* Look up the concept for which we will be matching
26647 template parameters. */
26648 tree tmpl_decl
= cp_parser_lookup_name_simple (parser
, concept_name
,
26650 parser
->scope
= saved_scope
;
26651 parser
->object_scope
= saved_object_scope
;
26652 parser
->qualifying_scope
= saved_qualifying_scope
;
26654 if (concept_name
== error_mark_node
)
26655 cp_parser_simulate_error (parser
);
26657 /* Look for opening brace for introduction. */
26658 cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
);
26660 if (!cp_parser_parse_definitely (parser
))
26663 push_deferring_access_checks (dk_deferred
);
26665 /* Build vector of placeholder parameters and grab
26666 matching identifiers. */
26667 tree introduction_list
= cp_parser_introduction_list (parser
);
26669 /* The introduction-list shall not be empty. */
26670 int nargs
= TREE_VEC_LENGTH (introduction_list
);
26673 error ("empty introduction-list");
26677 /* Look for closing brace for introduction. */
26678 if (!cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
))
26681 if (tmpl_decl
== error_mark_node
)
26683 cp_parser_name_lookup_error (parser
, concept_name
, tmpl_decl
, NLE_NULL
,
26688 /* Build and associate the constraint. */
26689 tree parms
= finish_template_introduction (tmpl_decl
, introduction_list
);
26690 if (parms
&& parms
!= error_mark_node
)
26692 cp_parser_template_declaration_after_parameters (parser
, parms
,
26697 error_at (token
->location
, "no matching concept for template-introduction");
26701 /* Parse a normal template-declaration following the template keyword. */
26704 cp_parser_explicit_template_declaration (cp_parser
* parser
, bool member_p
)
26706 tree parameter_list
;
26707 bool need_lang_pop
;
26708 location_t location
= input_location
;
26710 /* Look for the `<' token. */
26711 if (!cp_parser_require (parser
, CPP_LESS
, RT_LESS
))
26713 if (at_class_scope_p () && current_function_decl
)
26715 /* 14.5.2.2 [temp.mem]
26717 A local class shall not have member templates. */
26718 error_at (location
,
26719 "invalid declaration of member template in local class");
26720 cp_parser_skip_to_end_of_block_or_statement (parser
);
26725 A template ... shall not have C linkage. */
26726 if (current_lang_name
== lang_name_c
)
26728 error_at (location
, "template with C linkage");
26729 /* Give it C++ linkage to avoid confusing other parts of the
26731 push_lang_context (lang_name_cplusplus
);
26732 need_lang_pop
= true;
26735 need_lang_pop
= false;
26737 /* We cannot perform access checks on the template parameter
26738 declarations until we know what is being declared, just as we
26739 cannot check the decl-specifier list. */
26740 push_deferring_access_checks (dk_deferred
);
26742 /* If the next token is `>', then we have an invalid
26743 specialization. Rather than complain about an invalid template
26744 parameter, issue an error message here. */
26745 if (cp_lexer_next_token_is (parser
->lexer
, CPP_GREATER
))
26747 cp_parser_error (parser
, "invalid explicit specialization");
26748 begin_specialization ();
26749 parameter_list
= NULL_TREE
;
26753 /* Parse the template parameters. */
26754 parameter_list
= cp_parser_template_parameter_list (parser
);
26757 /* Look for the `>'. */
26758 cp_parser_skip_to_end_of_template_parameter_list (parser
);
26760 /* Manage template requirements */
26763 tree reqs
= get_shorthand_constraints (current_template_parms
);
26764 if (tree r
= cp_parser_requires_clause_opt (parser
))
26765 reqs
= conjoin_constraints (reqs
, normalize_expression (r
));
26766 TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
) = reqs
;
26769 cp_parser_template_declaration_after_parameters (parser
, parameter_list
,
26772 /* For the erroneous case of a template with C linkage, we pushed an
26773 implicit C++ linkage scope; exit that scope now. */
26775 pop_lang_context ();
26778 /* Parse a template-declaration, assuming that the `export' (and
26779 `extern') keywords, if present, has already been scanned. MEMBER_P
26780 is as for cp_parser_template_declaration. */
26783 cp_parser_template_declaration_after_export (cp_parser
* parser
, bool member_p
)
26785 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TEMPLATE
))
26787 cp_lexer_consume_token (parser
->lexer
);
26788 cp_parser_explicit_template_declaration (parser
, member_p
);
26791 else if (flag_concepts
)
26792 return cp_parser_template_introduction (parser
, member_p
);
26797 /* Perform the deferred access checks from a template-parameter-list.
26798 CHECKS is a TREE_LIST of access checks, as returned by
26799 get_deferred_access_checks. */
26802 cp_parser_perform_template_parameter_access_checks (vec
<deferred_access_check
, va_gc
> *checks
)
26804 ++processing_template_parmlist
;
26805 perform_access_checks (checks
, tf_warning_or_error
);
26806 --processing_template_parmlist
;
26809 /* Parse a `decl-specifier-seq [opt] init-declarator [opt] ;' or
26810 `function-definition' sequence that follows a template header.
26811 If MEMBER_P is true, this declaration appears in a class scope.
26813 Returns the DECL for the declared entity. If FRIEND_P is non-NULL,
26814 *FRIEND_P is set to TRUE iff the declaration is a friend. */
26817 cp_parser_single_declaration (cp_parser
* parser
,
26818 vec
<deferred_access_check
, va_gc
> *checks
,
26820 bool explicit_specialization_p
,
26823 int declares_class_or_enum
;
26824 tree decl
= NULL_TREE
;
26825 cp_decl_specifier_seq decl_specifiers
;
26826 bool function_definition_p
= false;
26827 cp_token
*decl_spec_token_start
;
26829 /* This function is only used when processing a template
26831 gcc_assert (innermost_scope_kind () == sk_template_parms
26832 || innermost_scope_kind () == sk_template_spec
);
26834 /* Defer access checks until we know what is being declared. */
26835 push_deferring_access_checks (dk_deferred
);
26837 /* Try the `decl-specifier-seq [opt] init-declarator [opt]'
26839 decl_spec_token_start
= cp_lexer_peek_token (parser
->lexer
);
26840 cp_parser_decl_specifier_seq (parser
,
26841 CP_PARSER_FLAGS_OPTIONAL
,
26843 &declares_class_or_enum
);
26845 *friend_p
= cp_parser_friend_p (&decl_specifiers
);
26847 /* There are no template typedefs. */
26848 if (decl_spec_seq_has_spec_p (&decl_specifiers
, ds_typedef
))
26850 error_at (decl_spec_token_start
->location
,
26851 "template declaration of %<typedef%>");
26852 decl
= error_mark_node
;
26855 /* Gather up the access checks that occurred the
26856 decl-specifier-seq. */
26857 stop_deferring_access_checks ();
26859 /* Check for the declaration of a template class. */
26860 if (declares_class_or_enum
)
26862 if (cp_parser_declares_only_class_p (parser
)
26863 || (declares_class_or_enum
& 2))
26865 // If this is a declaration, but not a definition, associate
26866 // any constraints with the type declaration. Constraints
26867 // are associated with definitions in cp_parser_class_specifier.
26868 if (declares_class_or_enum
== 1)
26869 associate_classtype_constraints (decl_specifiers
.type
);
26871 decl
= shadow_tag (&decl_specifiers
);
26876 friend template <typename T> struct A<T>::B;
26879 A<T>::B will be represented by a TYPENAME_TYPE, and
26880 therefore not recognized by shadow_tag. */
26881 if (friend_p
&& *friend_p
26883 && decl_specifiers
.type
26884 && TYPE_P (decl_specifiers
.type
))
26885 decl
= decl_specifiers
.type
;
26887 if (decl
&& decl
!= error_mark_node
)
26888 decl
= TYPE_NAME (decl
);
26890 decl
= error_mark_node
;
26892 /* Perform access checks for template parameters. */
26893 cp_parser_perform_template_parameter_access_checks (checks
);
26895 /* Give a helpful diagnostic for
26896 template <class T> struct A { } a;
26897 if we aren't already recovering from an error. */
26898 if (!cp_parser_declares_only_class_p (parser
)
26901 error_at (cp_lexer_peek_token (parser
->lexer
)->location
,
26902 "a class template declaration must not declare "
26904 cp_parser_skip_to_end_of_block_or_statement (parser
);
26910 /* Complain about missing 'typename' or other invalid type names. */
26911 if (!decl_specifiers
.any_type_specifiers_p
26912 && cp_parser_parse_and_diagnose_invalid_type_name (parser
))
26914 /* cp_parser_parse_and_diagnose_invalid_type_name calls
26915 cp_parser_skip_to_end_of_block_or_statement, so don't try to parse
26916 the rest of this declaration. */
26917 decl
= error_mark_node
;
26921 /* If it's not a template class, try for a template function. If
26922 the next token is a `;', then this declaration does not declare
26923 anything. But, if there were errors in the decl-specifiers, then
26924 the error might well have come from an attempted class-specifier.
26925 In that case, there's no need to warn about a missing declarator. */
26927 && (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
)
26928 || decl_specifiers
.type
!= error_mark_node
))
26930 decl
= cp_parser_init_declarator (parser
,
26933 /*function_definition_allowed_p=*/true,
26935 declares_class_or_enum
,
26936 &function_definition_p
,
26939 /* 7.1.1-1 [dcl.stc]
26941 A storage-class-specifier shall not be specified in an explicit
26942 specialization... */
26944 && explicit_specialization_p
26945 && decl_specifiers
.storage_class
!= sc_none
)
26947 error_at (decl_spec_token_start
->location
,
26948 "explicit template specialization cannot have a storage class");
26949 decl
= error_mark_node
;
26952 if (decl
&& VAR_P (decl
))
26953 check_template_variable (decl
);
26956 /* Look for a trailing `;' after the declaration. */
26957 if (!function_definition_p
26958 && (decl
== error_mark_node
26959 || !cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
)))
26960 cp_parser_skip_to_end_of_block_or_statement (parser
);
26963 pop_deferring_access_checks ();
26965 /* Clear any current qualification; whatever comes next is the start
26966 of something new. */
26967 parser
->scope
= NULL_TREE
;
26968 parser
->qualifying_scope
= NULL_TREE
;
26969 parser
->object_scope
= NULL_TREE
;
26974 /* Parse a cast-expression that is not the operand of a unary "&". */
26977 cp_parser_simple_cast_expression (cp_parser
*parser
)
26979 return cp_parser_cast_expression (parser
, /*address_p=*/false,
26980 /*cast_p=*/false, /*decltype*/false, NULL
);
26983 /* Parse a functional cast to TYPE. Returns an expression
26984 representing the cast. */
26987 cp_parser_functional_cast (cp_parser
* parser
, tree type
)
26989 vec
<tree
, va_gc
> *vec
;
26990 tree expression_list
;
26994 location_t start_loc
= input_location
;
26997 type
= error_mark_node
;
26999 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
27001 cp_lexer_set_source_position (parser
->lexer
);
27002 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
27003 expression_list
= cp_parser_braced_list (parser
, &nonconst_p
);
27004 CONSTRUCTOR_IS_DIRECT_INIT (expression_list
) = 1;
27005 if (TREE_CODE (type
) == TYPE_DECL
)
27006 type
= TREE_TYPE (type
);
27008 cast
= finish_compound_literal (type
, expression_list
,
27009 tf_warning_or_error
, fcl_functional
);
27010 /* Create a location of the form:
27013 with caret == start at the start of the type name,
27014 finishing at the closing brace. */
27015 location_t finish_loc
27016 = get_finish (cp_lexer_previous_token (parser
->lexer
)->location
);
27017 location_t combined_loc
= make_location (start_loc
, start_loc
,
27019 cast
.set_location (combined_loc
);
27024 vec
= cp_parser_parenthesized_expression_list (parser
, non_attr
,
27026 /*allow_expansion_p=*/true,
27027 /*non_constant_p=*/NULL
);
27029 expression_list
= error_mark_node
;
27032 expression_list
= build_tree_list_vec (vec
);
27033 release_tree_vector (vec
);
27036 cast
= build_functional_cast (type
, expression_list
,
27037 tf_warning_or_error
);
27038 /* [expr.const]/1: In an integral constant expression "only type
27039 conversions to integral or enumeration type can be used". */
27040 if (TREE_CODE (type
) == TYPE_DECL
)
27041 type
= TREE_TYPE (type
);
27042 if (cast
!= error_mark_node
27043 && !cast_valid_in_integral_constant_expression_p (type
)
27044 && cp_parser_non_integral_constant_expression (parser
,
27046 return error_mark_node
;
27048 /* Create a location of the form:
27051 with caret == start at the start of the type name,
27052 finishing at the closing paren. */
27053 location_t finish_loc
27054 = get_finish (cp_lexer_previous_token (parser
->lexer
)->location
);
27055 location_t combined_loc
= make_location (start_loc
, start_loc
, finish_loc
);
27056 cast
.set_location (combined_loc
);
27060 /* Save the tokens that make up the body of a member function defined
27061 in a class-specifier. The DECL_SPECIFIERS and DECLARATOR have
27062 already been parsed. The ATTRIBUTES are any GNU "__attribute__"
27063 specifiers applied to the declaration. Returns the FUNCTION_DECL
27064 for the member function. */
27067 cp_parser_save_member_function_body (cp_parser
* parser
,
27068 cp_decl_specifier_seq
*decl_specifiers
,
27069 cp_declarator
*declarator
,
27075 bool function_try_block
= false;
27077 /* Create the FUNCTION_DECL. */
27078 fn
= grokmethod (decl_specifiers
, declarator
, attributes
);
27079 cp_finalize_omp_declare_simd (parser
, fn
);
27080 cp_finalize_oacc_routine (parser
, fn
, true);
27081 /* If something went badly wrong, bail out now. */
27082 if (fn
== error_mark_node
)
27084 /* If there's a function-body, skip it. */
27085 if (cp_parser_token_starts_function_definition_p
27086 (cp_lexer_peek_token (parser
->lexer
)))
27087 cp_parser_skip_to_end_of_block_or_statement (parser
);
27088 return error_mark_node
;
27091 /* Remember it, if there default args to post process. */
27092 cp_parser_save_default_args (parser
, fn
);
27094 /* Save away the tokens that make up the body of the
27096 first
= parser
->lexer
->next_token
;
27098 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TRANSACTION_RELAXED
))
27099 cp_lexer_consume_token (parser
->lexer
);
27100 else if (cp_lexer_next_token_is_keyword (parser
->lexer
,
27101 RID_TRANSACTION_ATOMIC
))
27103 cp_lexer_consume_token (parser
->lexer
);
27104 /* Match cp_parser_txn_attribute_opt [[ identifier ]]. */
27105 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_SQUARE
)
27106 && cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_OPEN_SQUARE
)
27107 && (cp_lexer_nth_token_is (parser
->lexer
, 3, CPP_NAME
)
27108 || cp_lexer_nth_token_is (parser
->lexer
, 3, CPP_KEYWORD
))
27109 && cp_lexer_nth_token_is (parser
->lexer
, 4, CPP_CLOSE_SQUARE
)
27110 && cp_lexer_nth_token_is (parser
->lexer
, 5, CPP_CLOSE_SQUARE
))
27112 cp_lexer_consume_token (parser
->lexer
);
27113 cp_lexer_consume_token (parser
->lexer
);
27114 cp_lexer_consume_token (parser
->lexer
);
27115 cp_lexer_consume_token (parser
->lexer
);
27116 cp_lexer_consume_token (parser
->lexer
);
27119 while (cp_next_tokens_can_be_gnu_attribute_p (parser
)
27120 && cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_OPEN_PAREN
))
27122 cp_lexer_consume_token (parser
->lexer
);
27123 if (cp_parser_cache_group (parser
, CPP_CLOSE_PAREN
, /*depth=*/0))
27128 /* Handle function try blocks. */
27129 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TRY
))
27131 cp_lexer_consume_token (parser
->lexer
);
27132 function_try_block
= true;
27134 /* We can have braced-init-list mem-initializers before the fn body. */
27135 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
27137 cp_lexer_consume_token (parser
->lexer
);
27138 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_BRACE
))
27140 /* cache_group will stop after an un-nested { } pair, too. */
27141 if (cp_parser_cache_group (parser
, CPP_CLOSE_PAREN
, /*depth=*/0))
27144 /* variadic mem-inits have ... after the ')'. */
27145 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
27146 cp_lexer_consume_token (parser
->lexer
);
27149 cp_parser_cache_group (parser
, CPP_CLOSE_BRACE
, /*depth=*/0);
27150 /* Handle function try blocks. */
27151 if (function_try_block
)
27152 while (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_CATCH
))
27153 cp_parser_cache_group (parser
, CPP_CLOSE_BRACE
, /*depth=*/0);
27154 last
= parser
->lexer
->next_token
;
27156 /* Save away the inline definition; we will process it when the
27157 class is complete. */
27158 DECL_PENDING_INLINE_INFO (fn
) = cp_token_cache_new (first
, last
);
27159 DECL_PENDING_INLINE_P (fn
) = 1;
27161 /* We need to know that this was defined in the class, so that
27162 friend templates are handled correctly. */
27163 DECL_INITIALIZED_IN_CLASS_P (fn
) = 1;
27165 /* Add FN to the queue of functions to be parsed later. */
27166 vec_safe_push (unparsed_funs_with_definitions
, fn
);
27171 /* Save the tokens that make up the in-class initializer for a non-static
27172 data member. Returns a DEFAULT_ARG. */
27175 cp_parser_save_nsdmi (cp_parser
* parser
)
27177 return cp_parser_cache_defarg (parser
, /*nsdmi=*/true);
27180 /* Parse a template-argument-list, as well as the trailing ">" (but
27181 not the opening "<"). See cp_parser_template_argument_list for the
27185 cp_parser_enclosed_template_argument_list (cp_parser
* parser
)
27189 tree saved_qualifying_scope
;
27190 tree saved_object_scope
;
27191 bool saved_greater_than_is_operator_p
;
27192 int saved_unevaluated_operand
;
27193 int saved_inhibit_evaluation_warnings
;
27197 When parsing a template-id, the first non-nested `>' is taken as
27198 the end of the template-argument-list rather than a greater-than
27200 saved_greater_than_is_operator_p
27201 = parser
->greater_than_is_operator_p
;
27202 parser
->greater_than_is_operator_p
= false;
27203 /* Parsing the argument list may modify SCOPE, so we save it
27205 saved_scope
= parser
->scope
;
27206 saved_qualifying_scope
= parser
->qualifying_scope
;
27207 saved_object_scope
= parser
->object_scope
;
27208 /* We need to evaluate the template arguments, even though this
27209 template-id may be nested within a "sizeof". */
27210 saved_unevaluated_operand
= cp_unevaluated_operand
;
27211 cp_unevaluated_operand
= 0;
27212 saved_inhibit_evaluation_warnings
= c_inhibit_evaluation_warnings
;
27213 c_inhibit_evaluation_warnings
= 0;
27214 /* Parse the template-argument-list itself. */
27215 if (cp_lexer_next_token_is (parser
->lexer
, CPP_GREATER
)
27216 || cp_lexer_next_token_is (parser
->lexer
, CPP_RSHIFT
))
27217 arguments
= NULL_TREE
;
27219 arguments
= cp_parser_template_argument_list (parser
);
27220 /* Look for the `>' that ends the template-argument-list. If we find
27221 a '>>' instead, it's probably just a typo. */
27222 if (cp_lexer_next_token_is (parser
->lexer
, CPP_RSHIFT
))
27224 if (cxx_dialect
!= cxx98
)
27226 /* In C++0x, a `>>' in a template argument list or cast
27227 expression is considered to be two separate `>'
27228 tokens. So, change the current token to a `>', but don't
27229 consume it: it will be consumed later when the outer
27230 template argument list (or cast expression) is parsed.
27231 Note that this replacement of `>' for `>>' is necessary
27232 even if we are parsing tentatively: in the tentative
27233 case, after calling
27234 cp_parser_enclosed_template_argument_list we will always
27235 throw away all of the template arguments and the first
27236 closing `>', either because the template argument list
27237 was erroneous or because we are replacing those tokens
27238 with a CPP_TEMPLATE_ID token. The second `>' (which will
27239 not have been thrown away) is needed either to close an
27240 outer template argument list or to complete a new-style
27242 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
27243 token
->type
= CPP_GREATER
;
27245 else if (!saved_greater_than_is_operator_p
)
27247 /* If we're in a nested template argument list, the '>>' has
27248 to be a typo for '> >'. We emit the error message, but we
27249 continue parsing and we push a '>' as next token, so that
27250 the argument list will be parsed correctly. Note that the
27251 global source location is still on the token before the
27252 '>>', so we need to say explicitly where we want it. */
27253 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
27254 gcc_rich_location
richloc (token
->location
);
27255 richloc
.add_fixit_replace ("> >");
27256 error_at_rich_loc (&richloc
, "%<>>%> should be %<> >%> "
27257 "within a nested template argument list");
27259 token
->type
= CPP_GREATER
;
27263 /* If this is not a nested template argument list, the '>>'
27264 is a typo for '>'. Emit an error message and continue.
27265 Same deal about the token location, but here we can get it
27266 right by consuming the '>>' before issuing the diagnostic. */
27267 cp_token
*token
= cp_lexer_consume_token (parser
->lexer
);
27268 error_at (token
->location
,
27269 "spurious %<>>%>, use %<>%> to terminate "
27270 "a template argument list");
27274 cp_parser_skip_to_end_of_template_parameter_list (parser
);
27275 /* The `>' token might be a greater-than operator again now. */
27276 parser
->greater_than_is_operator_p
27277 = saved_greater_than_is_operator_p
;
27278 /* Restore the SAVED_SCOPE. */
27279 parser
->scope
= saved_scope
;
27280 parser
->qualifying_scope
= saved_qualifying_scope
;
27281 parser
->object_scope
= saved_object_scope
;
27282 cp_unevaluated_operand
= saved_unevaluated_operand
;
27283 c_inhibit_evaluation_warnings
= saved_inhibit_evaluation_warnings
;
27288 /* MEMBER_FUNCTION is a member function, or a friend. If default
27289 arguments, or the body of the function have not yet been parsed,
27293 cp_parser_late_parsing_for_member (cp_parser
* parser
, tree member_function
)
27295 timevar_push (TV_PARSE_INMETH
);
27296 /* If this member is a template, get the underlying
27298 if (DECL_FUNCTION_TEMPLATE_P (member_function
))
27299 member_function
= DECL_TEMPLATE_RESULT (member_function
);
27301 /* There should not be any class definitions in progress at this
27302 point; the bodies of members are only parsed outside of all class
27304 gcc_assert (parser
->num_classes_being_defined
== 0);
27305 /* While we're parsing the member functions we might encounter more
27306 classes. We want to handle them right away, but we don't want
27307 them getting mixed up with functions that are currently in the
27309 push_unparsed_function_queues (parser
);
27311 /* Make sure that any template parameters are in scope. */
27312 maybe_begin_member_template_processing (member_function
);
27314 /* If the body of the function has not yet been parsed, parse it
27316 if (DECL_PENDING_INLINE_P (member_function
))
27318 tree function_scope
;
27319 cp_token_cache
*tokens
;
27321 /* The function is no longer pending; we are processing it. */
27322 tokens
= DECL_PENDING_INLINE_INFO (member_function
);
27323 DECL_PENDING_INLINE_INFO (member_function
) = NULL
;
27324 DECL_PENDING_INLINE_P (member_function
) = 0;
27326 /* If this is a local class, enter the scope of the containing
27328 function_scope
= current_function_decl
;
27329 if (function_scope
)
27330 push_function_context ();
27332 /* Push the body of the function onto the lexer stack. */
27333 cp_parser_push_lexer_for_tokens (parser
, tokens
);
27335 /* Let the front end know that we going to be defining this
27337 start_preparsed_function (member_function
, NULL_TREE
,
27338 SF_PRE_PARSED
| SF_INCLASS_INLINE
);
27340 /* Don't do access checking if it is a templated function. */
27341 if (processing_template_decl
)
27342 push_deferring_access_checks (dk_no_check
);
27344 /* #pragma omp declare reduction needs special parsing. */
27345 if (DECL_OMP_DECLARE_REDUCTION_P (member_function
))
27347 parser
->lexer
->in_pragma
= true;
27348 cp_parser_omp_declare_reduction_exprs (member_function
, parser
);
27349 finish_function (/*inline*/2);
27350 cp_check_omp_declare_reduction (member_function
);
27353 /* Now, parse the body of the function. */
27354 cp_parser_function_definition_after_declarator (parser
,
27355 /*inline_p=*/true);
27357 if (processing_template_decl
)
27358 pop_deferring_access_checks ();
27360 /* Leave the scope of the containing function. */
27361 if (function_scope
)
27362 pop_function_context ();
27363 cp_parser_pop_lexer (parser
);
27366 /* Remove any template parameters from the symbol table. */
27367 maybe_end_member_template_processing ();
27369 /* Restore the queue. */
27370 pop_unparsed_function_queues (parser
);
27371 timevar_pop (TV_PARSE_INMETH
);
27374 /* If DECL contains any default args, remember it on the unparsed
27375 functions queue. */
27378 cp_parser_save_default_args (cp_parser
* parser
, tree decl
)
27382 for (probe
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
27384 probe
= TREE_CHAIN (probe
))
27385 if (TREE_PURPOSE (probe
))
27387 cp_default_arg_entry entry
= {current_class_type
, decl
};
27388 vec_safe_push (unparsed_funs_with_default_args
, entry
);
27393 /* DEFAULT_ARG contains the saved tokens for the initializer of DECL,
27394 which is either a FIELD_DECL or PARM_DECL. Parse it and return
27395 the result. For a PARM_DECL, PARMTYPE is the corresponding type
27396 from the parameter-type-list. */
27399 cp_parser_late_parse_one_default_arg (cp_parser
*parser
, tree decl
,
27400 tree default_arg
, tree parmtype
)
27402 cp_token_cache
*tokens
;
27406 if (default_arg
== error_mark_node
)
27407 return error_mark_node
;
27409 /* Push the saved tokens for the default argument onto the parser's
27411 tokens
= DEFARG_TOKENS (default_arg
);
27412 cp_parser_push_lexer_for_tokens (parser
, tokens
);
27414 start_lambda_scope (decl
);
27416 /* Parse the default argument. */
27417 parsed_arg
= cp_parser_initializer (parser
, &dummy
, &dummy
);
27418 if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg
))
27419 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS
);
27421 finish_lambda_scope ();
27423 if (parsed_arg
== error_mark_node
)
27424 cp_parser_skip_to_end_of_statement (parser
);
27426 if (!processing_template_decl
)
27428 /* In a non-template class, check conversions now. In a template,
27429 we'll wait and instantiate these as needed. */
27430 if (TREE_CODE (decl
) == PARM_DECL
)
27431 parsed_arg
= check_default_argument (parmtype
, parsed_arg
,
27432 tf_warning_or_error
);
27433 else if (maybe_reject_flexarray_init (decl
, parsed_arg
))
27434 parsed_arg
= error_mark_node
;
27436 parsed_arg
= digest_nsdmi_init (decl
, parsed_arg
);
27439 /* If the token stream has not been completely used up, then
27440 there was extra junk after the end of the default
27442 if (!cp_lexer_next_token_is (parser
->lexer
, CPP_EOF
))
27444 if (TREE_CODE (decl
) == PARM_DECL
)
27445 cp_parser_error (parser
, "expected %<,%>");
27447 cp_parser_error (parser
, "expected %<;%>");
27450 /* Revert to the main lexer. */
27451 cp_parser_pop_lexer (parser
);
27456 /* FIELD is a non-static data member with an initializer which we saved for
27457 later; parse it now. */
27460 cp_parser_late_parsing_nsdmi (cp_parser
*parser
, tree field
)
27464 maybe_begin_member_template_processing (field
);
27466 push_unparsed_function_queues (parser
);
27467 def
= cp_parser_late_parse_one_default_arg (parser
, field
,
27468 DECL_INITIAL (field
),
27470 pop_unparsed_function_queues (parser
);
27472 maybe_end_member_template_processing ();
27474 DECL_INITIAL (field
) = def
;
27477 /* FN is a FUNCTION_DECL which may contains a parameter with an
27478 unparsed DEFAULT_ARG. Parse the default args now. This function
27479 assumes that the current scope is the scope in which the default
27480 argument should be processed. */
27483 cp_parser_late_parsing_default_args (cp_parser
*parser
, tree fn
)
27485 bool saved_local_variables_forbidden_p
;
27486 tree parm
, parmdecl
;
27488 /* While we're parsing the default args, we might (due to the
27489 statement expression extension) encounter more classes. We want
27490 to handle them right away, but we don't want them getting mixed
27491 up with default args that are currently in the queue. */
27492 push_unparsed_function_queues (parser
);
27494 /* Local variable names (and the `this' keyword) may not appear
27495 in a default argument. */
27496 saved_local_variables_forbidden_p
= parser
->local_variables_forbidden_p
;
27497 parser
->local_variables_forbidden_p
= true;
27499 push_defarg_context (fn
);
27501 for (parm
= TYPE_ARG_TYPES (TREE_TYPE (fn
)),
27502 parmdecl
= DECL_ARGUMENTS (fn
);
27503 parm
&& parm
!= void_list_node
;
27504 parm
= TREE_CHAIN (parm
),
27505 parmdecl
= DECL_CHAIN (parmdecl
))
27507 tree default_arg
= TREE_PURPOSE (parm
);
27509 vec
<tree
, va_gc
> *insts
;
27516 if (TREE_CODE (default_arg
) != DEFAULT_ARG
)
27517 /* This can happen for a friend declaration for a function
27518 already declared with default arguments. */
27522 = cp_parser_late_parse_one_default_arg (parser
, parmdecl
,
27524 TREE_VALUE (parm
));
27525 if (parsed_arg
== error_mark_node
)
27530 TREE_PURPOSE (parm
) = parsed_arg
;
27532 /* Update any instantiations we've already created. */
27533 for (insts
= DEFARG_INSTANTIATIONS (default_arg
), ix
= 0;
27534 vec_safe_iterate (insts
, ix
, ©
); ix
++)
27535 TREE_PURPOSE (copy
) = parsed_arg
;
27538 pop_defarg_context ();
27540 /* Make sure no default arg is missing. */
27541 check_default_args (fn
);
27543 /* Restore the state of local_variables_forbidden_p. */
27544 parser
->local_variables_forbidden_p
= saved_local_variables_forbidden_p
;
27546 /* Restore the queue. */
27547 pop_unparsed_function_queues (parser
);
27550 /* Subroutine of cp_parser_sizeof_operand, for handling C++11
27552 sizeof ... ( identifier )
27554 where the 'sizeof' token has already been consumed. */
27557 cp_parser_sizeof_pack (cp_parser
*parser
)
27559 /* Consume the `...'. */
27560 cp_lexer_consume_token (parser
->lexer
);
27561 maybe_warn_variadic_templates ();
27563 bool paren
= cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
);
27565 cp_lexer_consume_token (parser
->lexer
);
27567 permerror (cp_lexer_peek_token (parser
->lexer
)->location
,
27568 "%<sizeof...%> argument must be surrounded by parentheses");
27570 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
27571 tree name
= cp_parser_identifier (parser
);
27572 if (name
== error_mark_node
)
27573 return error_mark_node
;
27574 /* The name is not qualified. */
27575 parser
->scope
= NULL_TREE
;
27576 parser
->qualifying_scope
= NULL_TREE
;
27577 parser
->object_scope
= NULL_TREE
;
27578 tree expr
= cp_parser_lookup_name_simple (parser
, name
, token
->location
);
27579 if (expr
== error_mark_node
)
27580 cp_parser_name_lookup_error (parser
, name
, expr
, NLE_NULL
,
27582 if (TREE_CODE (expr
) == TYPE_DECL
|| TREE_CODE (expr
) == TEMPLATE_DECL
)
27583 expr
= TREE_TYPE (expr
);
27584 else if (TREE_CODE (expr
) == CONST_DECL
)
27585 expr
= DECL_INITIAL (expr
);
27586 expr
= make_pack_expansion (expr
);
27587 PACK_EXPANSION_SIZEOF_P (expr
) = true;
27590 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
27595 /* Parse the operand of `sizeof' (or a similar operator). Returns
27596 either a TYPE or an expression, depending on the form of the
27597 input. The KEYWORD indicates which kind of expression we have
27601 cp_parser_sizeof_operand (cp_parser
* parser
, enum rid keyword
)
27603 tree expr
= NULL_TREE
;
27604 const char *saved_message
;
27606 bool saved_integral_constant_expression_p
;
27607 bool saved_non_integral_constant_expression_p
;
27609 /* If it's a `...', then we are computing the length of a parameter
27611 if (keyword
== RID_SIZEOF
27612 && cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
27613 return cp_parser_sizeof_pack (parser
);
27615 /* Types cannot be defined in a `sizeof' expression. Save away the
27617 saved_message
= parser
->type_definition_forbidden_message
;
27618 /* And create the new one. */
27619 tmp
= concat ("types may not be defined in %<",
27620 IDENTIFIER_POINTER (ridpointers
[keyword
]),
27621 "%> expressions", NULL
);
27622 parser
->type_definition_forbidden_message
= tmp
;
27624 /* The restrictions on constant-expressions do not apply inside
27625 sizeof expressions. */
27626 saved_integral_constant_expression_p
27627 = parser
->integral_constant_expression_p
;
27628 saved_non_integral_constant_expression_p
27629 = parser
->non_integral_constant_expression_p
;
27630 parser
->integral_constant_expression_p
= false;
27632 /* Do not actually evaluate the expression. */
27633 ++cp_unevaluated_operand
;
27634 ++c_inhibit_evaluation_warnings
;
27635 /* If it's a `(', then we might be looking at the type-id
27637 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
27639 tree type
= NULL_TREE
;
27641 /* We can't be sure yet whether we're looking at a type-id or an
27643 cp_parser_parse_tentatively (parser
);
27644 /* Note: as a GNU Extension, compound literals are considered
27645 postfix-expressions as they are in C99, so they are valid
27646 arguments to sizeof. See comment in cp_parser_cast_expression
27648 if (cp_parser_compound_literal_p (parser
))
27649 cp_parser_simulate_error (parser
);
27652 bool saved_in_type_id_in_expr_p
= parser
->in_type_id_in_expr_p
;
27653 parser
->in_type_id_in_expr_p
= true;
27654 /* Look for the type-id. */
27655 type
= cp_parser_type_id (parser
);
27656 /* Look for the closing `)'. */
27657 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
27658 parser
->in_type_id_in_expr_p
= saved_in_type_id_in_expr_p
;
27661 /* If all went well, then we're done. */
27662 if (cp_parser_parse_definitely (parser
))
27664 cp_decl_specifier_seq decl_specs
;
27666 /* Build a trivial decl-specifier-seq. */
27667 clear_decl_specs (&decl_specs
);
27668 decl_specs
.type
= type
;
27670 /* Call grokdeclarator to figure out what type this is. */
27671 expr
= grokdeclarator (NULL
,
27675 /*attrlist=*/NULL
);
27679 /* If the type-id production did not work out, then we must be
27680 looking at the unary-expression production. */
27682 expr
= cp_parser_unary_expression (parser
);
27684 /* Go back to evaluating expressions. */
27685 --cp_unevaluated_operand
;
27686 --c_inhibit_evaluation_warnings
;
27688 /* Free the message we created. */
27690 /* And restore the old one. */
27691 parser
->type_definition_forbidden_message
= saved_message
;
27692 parser
->integral_constant_expression_p
27693 = saved_integral_constant_expression_p
;
27694 parser
->non_integral_constant_expression_p
27695 = saved_non_integral_constant_expression_p
;
27700 /* If the current declaration has no declarator, return true. */
27703 cp_parser_declares_only_class_p (cp_parser
*parser
)
27705 /* If the next token is a `;' or a `,' then there is no
27707 return (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
)
27708 || cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
));
27711 /* Update the DECL_SPECS to reflect the storage class indicated by
27715 cp_parser_set_storage_class (cp_parser
*parser
,
27716 cp_decl_specifier_seq
*decl_specs
,
27720 cp_storage_class storage_class
;
27722 if (parser
->in_unbraced_linkage_specification_p
)
27724 error_at (token
->location
, "invalid use of %qD in linkage specification",
27725 ridpointers
[keyword
]);
27728 else if (decl_specs
->storage_class
!= sc_none
)
27730 decl_specs
->conflicting_specifiers_p
= true;
27734 if ((keyword
== RID_EXTERN
|| keyword
== RID_STATIC
)
27735 && decl_spec_seq_has_spec_p (decl_specs
, ds_thread
)
27736 && decl_specs
->gnu_thread_keyword_p
)
27738 pedwarn (decl_specs
->locations
[ds_thread
], 0,
27739 "%<__thread%> before %qD", ridpointers
[keyword
]);
27745 storage_class
= sc_auto
;
27748 storage_class
= sc_register
;
27751 storage_class
= sc_static
;
27754 storage_class
= sc_extern
;
27757 storage_class
= sc_mutable
;
27760 gcc_unreachable ();
27762 decl_specs
->storage_class
= storage_class
;
27763 set_and_check_decl_spec_loc (decl_specs
, ds_storage_class
, token
);
27765 /* A storage class specifier cannot be applied alongside a typedef
27766 specifier. If there is a typedef specifier present then set
27767 conflicting_specifiers_p which will trigger an error later
27768 on in grokdeclarator. */
27769 if (decl_spec_seq_has_spec_p (decl_specs
, ds_typedef
))
27770 decl_specs
->conflicting_specifiers_p
= true;
27773 /* Update the DECL_SPECS to reflect the TYPE_SPEC. If TYPE_DEFINITION_P
27774 is true, the type is a class or enum definition. */
27777 cp_parser_set_decl_spec_type (cp_decl_specifier_seq
*decl_specs
,
27780 bool type_definition_p
)
27782 decl_specs
->any_specifiers_p
= true;
27784 /* If the user tries to redeclare bool, char16_t, char32_t, or wchar_t
27785 (with, for example, in "typedef int wchar_t;") we remember that
27786 this is what happened. In system headers, we ignore these
27787 declarations so that G++ can work with system headers that are not
27789 if (decl_spec_seq_has_spec_p (decl_specs
, ds_typedef
)
27790 && !type_definition_p
27791 && (type_spec
== boolean_type_node
27792 || type_spec
== char16_type_node
27793 || type_spec
== char32_type_node
27794 || type_spec
== wchar_type_node
)
27795 && (decl_specs
->type
27796 || decl_spec_seq_has_spec_p (decl_specs
, ds_long
)
27797 || decl_spec_seq_has_spec_p (decl_specs
, ds_short
)
27798 || decl_spec_seq_has_spec_p (decl_specs
, ds_unsigned
)
27799 || decl_spec_seq_has_spec_p (decl_specs
, ds_signed
)))
27801 decl_specs
->redefined_builtin_type
= type_spec
;
27802 set_and_check_decl_spec_loc (decl_specs
,
27803 ds_redefined_builtin_type_spec
,
27805 if (!decl_specs
->type
)
27807 decl_specs
->type
= type_spec
;
27808 decl_specs
->type_definition_p
= false;
27809 set_and_check_decl_spec_loc (decl_specs
,ds_type_spec
, token
);
27812 else if (decl_specs
->type
)
27813 decl_specs
->multiple_types_p
= true;
27816 decl_specs
->type
= type_spec
;
27817 decl_specs
->type_definition_p
= type_definition_p
;
27818 decl_specs
->redefined_builtin_type
= NULL_TREE
;
27819 set_and_check_decl_spec_loc (decl_specs
, ds_type_spec
, token
);
27823 /* True iff TOKEN is the GNU keyword __thread. */
27826 token_is__thread (cp_token
*token
)
27828 gcc_assert (token
->keyword
== RID_THREAD
);
27829 return id_equal (token
->u
.value
, "__thread");
27832 /* Set the location for a declarator specifier and check if it is
27835 DECL_SPECS is the sequence of declarator specifiers onto which to
27838 DS is the single declarator specifier to set which location is to
27839 be set onto the existing sequence of declarators.
27841 LOCATION is the location for the declarator specifier to
27845 set_and_check_decl_spec_loc (cp_decl_specifier_seq
*decl_specs
,
27846 cp_decl_spec ds
, cp_token
*token
)
27848 gcc_assert (ds
< ds_last
);
27850 if (decl_specs
== NULL
)
27853 source_location location
= token
->location
;
27855 if (decl_specs
->locations
[ds
] == 0)
27857 decl_specs
->locations
[ds
] = location
;
27858 if (ds
== ds_thread
)
27859 decl_specs
->gnu_thread_keyword_p
= token_is__thread (token
);
27865 if (decl_specs
->locations
[ds_long_long
] != 0)
27866 error_at (location
,
27867 "%<long long long%> is too long for GCC");
27870 decl_specs
->locations
[ds_long_long
] = location
;
27871 pedwarn_cxx98 (location
,
27873 "ISO C++ 1998 does not support %<long long%>");
27876 else if (ds
== ds_thread
)
27878 bool gnu
= token_is__thread (token
);
27879 if (gnu
!= decl_specs
->gnu_thread_keyword_p
)
27880 error_at (location
,
27881 "both %<__thread%> and %<thread_local%> specified");
27884 gcc_rich_location
richloc (location
);
27885 richloc
.add_fixit_remove ();
27886 error_at_rich_loc (&richloc
, "duplicate %qD", token
->u
.value
);
27891 static const char *const decl_spec_names
[] = {
27908 gcc_rich_location
richloc (location
);
27909 richloc
.add_fixit_remove ();
27910 error_at_rich_loc (&richloc
, "duplicate %qs", decl_spec_names
[ds
]);
27915 /* Return true iff the declarator specifier DS is present in the
27916 sequence of declarator specifiers DECL_SPECS. */
27919 decl_spec_seq_has_spec_p (const cp_decl_specifier_seq
* decl_specs
,
27922 gcc_assert (ds
< ds_last
);
27924 if (decl_specs
== NULL
)
27927 return decl_specs
->locations
[ds
] != 0;
27930 /* DECL_SPECIFIERS is the representation of a decl-specifier-seq.
27931 Returns TRUE iff `friend' appears among the DECL_SPECIFIERS. */
27934 cp_parser_friend_p (const cp_decl_specifier_seq
*decl_specifiers
)
27936 return decl_spec_seq_has_spec_p (decl_specifiers
, ds_friend
);
27939 /* Issue an error message indicating that TOKEN_DESC was expected.
27940 If KEYWORD is true, it indicated this function is called by
27941 cp_parser_require_keword and the required token can only be
27942 a indicated keyword. */
27945 cp_parser_required_error (cp_parser
*parser
,
27946 required_token token_desc
,
27949 switch (token_desc
)
27952 cp_parser_error (parser
, "expected %<new%>");
27955 cp_parser_error (parser
, "expected %<delete%>");
27958 cp_parser_error (parser
, "expected %<return%>");
27961 cp_parser_error (parser
, "expected %<while%>");
27964 cp_parser_error (parser
, "expected %<extern%>");
27966 case RT_STATIC_ASSERT
:
27967 cp_parser_error (parser
, "expected %<static_assert%>");
27970 cp_parser_error (parser
, "expected %<decltype%>");
27973 cp_parser_error (parser
, "expected %<operator%>");
27976 cp_parser_error (parser
, "expected %<class%>");
27979 cp_parser_error (parser
, "expected %<template%>");
27982 cp_parser_error (parser
, "expected %<namespace%>");
27985 cp_parser_error (parser
, "expected %<using%>");
27988 cp_parser_error (parser
, "expected %<asm%>");
27991 cp_parser_error (parser
, "expected %<try%>");
27994 cp_parser_error (parser
, "expected %<catch%>");
27997 cp_parser_error (parser
, "expected %<throw%>");
28000 cp_parser_error (parser
, "expected %<__label__%>");
28003 cp_parser_error (parser
, "expected %<@try%>");
28005 case RT_AT_SYNCHRONIZED
:
28006 cp_parser_error (parser
, "expected %<@synchronized%>");
28009 cp_parser_error (parser
, "expected %<@throw%>");
28011 case RT_TRANSACTION_ATOMIC
:
28012 cp_parser_error (parser
, "expected %<__transaction_atomic%>");
28014 case RT_TRANSACTION_RELAXED
:
28015 cp_parser_error (parser
, "expected %<__transaction_relaxed%>");
28022 switch (token_desc
)
28025 cp_parser_error (parser
, "expected %<;%>");
28027 case RT_OPEN_PAREN
:
28028 cp_parser_error (parser
, "expected %<(%>");
28030 case RT_CLOSE_BRACE
:
28031 cp_parser_error (parser
, "expected %<}%>");
28033 case RT_OPEN_BRACE
:
28034 cp_parser_error (parser
, "expected %<{%>");
28036 case RT_CLOSE_SQUARE
:
28037 cp_parser_error (parser
, "expected %<]%>");
28039 case RT_OPEN_SQUARE
:
28040 cp_parser_error (parser
, "expected %<[%>");
28043 cp_parser_error (parser
, "expected %<,%>");
28046 cp_parser_error (parser
, "expected %<::%>");
28049 cp_parser_error (parser
, "expected %<<%>");
28052 cp_parser_error (parser
, "expected %<>%>");
28055 cp_parser_error (parser
, "expected %<=%>");
28058 cp_parser_error (parser
, "expected %<...%>");
28061 cp_parser_error (parser
, "expected %<*%>");
28064 cp_parser_error (parser
, "expected %<~%>");
28067 cp_parser_error (parser
, "expected %<:%>");
28069 case RT_COLON_SCOPE
:
28070 cp_parser_error (parser
, "expected %<:%> or %<::%>");
28072 case RT_CLOSE_PAREN
:
28073 cp_parser_error (parser
, "expected %<)%>");
28075 case RT_COMMA_CLOSE_PAREN
:
28076 cp_parser_error (parser
, "expected %<,%> or %<)%>");
28078 case RT_PRAGMA_EOL
:
28079 cp_parser_error (parser
, "expected end of line");
28082 cp_parser_error (parser
, "expected identifier");
28085 cp_parser_error (parser
, "expected selection-statement");
28088 cp_parser_error (parser
, "expected iteration-statement");
28091 cp_parser_error (parser
, "expected jump-statement");
28094 cp_parser_error (parser
, "expected class-key");
28096 case RT_CLASS_TYPENAME_TEMPLATE
:
28097 cp_parser_error (parser
,
28098 "expected %<class%>, %<typename%>, or %<template%>");
28101 gcc_unreachable ();
28105 gcc_unreachable ();
28110 /* If the next token is of the indicated TYPE, consume it. Otherwise,
28111 issue an error message indicating that TOKEN_DESC was expected.
28113 Returns the token consumed, if the token had the appropriate type.
28114 Otherwise, returns NULL. */
28117 cp_parser_require (cp_parser
* parser
,
28118 enum cpp_ttype type
,
28119 required_token token_desc
)
28121 if (cp_lexer_next_token_is (parser
->lexer
, type
))
28122 return cp_lexer_consume_token (parser
->lexer
);
28125 /* Output the MESSAGE -- unless we're parsing tentatively. */
28126 if (!cp_parser_simulate_error (parser
))
28127 cp_parser_required_error (parser
, token_desc
, /*keyword=*/false);
28132 /* An error message is produced if the next token is not '>'.
28133 All further tokens are skipped until the desired token is
28134 found or '{', '}', ';' or an unbalanced ')' or ']'. */
28137 cp_parser_skip_to_end_of_template_parameter_list (cp_parser
* parser
)
28139 /* Current level of '< ... >'. */
28140 unsigned level
= 0;
28141 /* Ignore '<' and '>' nested inside '( ... )' or '[ ... ]'. */
28142 unsigned nesting_depth
= 0;
28144 /* Are we ready, yet? If not, issue error message. */
28145 if (cp_parser_require (parser
, CPP_GREATER
, RT_GREATER
))
28148 /* Skip tokens until the desired token is found. */
28151 /* Peek at the next token. */
28152 switch (cp_lexer_peek_token (parser
->lexer
)->type
)
28155 if (!nesting_depth
)
28160 if (cxx_dialect
== cxx98
)
28161 /* C++0x views the `>>' operator as two `>' tokens, but
28164 else if (!nesting_depth
&& level
-- == 0)
28166 /* We've hit a `>>' where the first `>' closes the
28167 template argument list, and the second `>' is
28168 spurious. Just consume the `>>' and stop; we've
28169 already produced at least one error. */
28170 cp_lexer_consume_token (parser
->lexer
);
28173 /* Fall through for C++0x, so we handle the second `>' in
28175 gcc_fallthrough ();
28178 if (!nesting_depth
&& level
-- == 0)
28180 /* We've reached the token we want, consume it and stop. */
28181 cp_lexer_consume_token (parser
->lexer
);
28186 case CPP_OPEN_PAREN
:
28187 case CPP_OPEN_SQUARE
:
28191 case CPP_CLOSE_PAREN
:
28192 case CPP_CLOSE_SQUARE
:
28193 if (nesting_depth
-- == 0)
28198 case CPP_PRAGMA_EOL
:
28199 case CPP_SEMICOLON
:
28200 case CPP_OPEN_BRACE
:
28201 case CPP_CLOSE_BRACE
:
28202 /* The '>' was probably forgotten, don't look further. */
28209 /* Consume this token. */
28210 cp_lexer_consume_token (parser
->lexer
);
28214 /* If the next token is the indicated keyword, consume it. Otherwise,
28215 issue an error message indicating that TOKEN_DESC was expected.
28217 Returns the token consumed, if the token had the appropriate type.
28218 Otherwise, returns NULL. */
28221 cp_parser_require_keyword (cp_parser
* parser
,
28223 required_token token_desc
)
28225 cp_token
*token
= cp_parser_require (parser
, CPP_KEYWORD
, token_desc
);
28227 if (token
&& token
->keyword
!= keyword
)
28229 cp_parser_required_error (parser
, token_desc
, /*keyword=*/true);
28236 /* Returns TRUE iff TOKEN is a token that can begin the body of a
28237 function-definition. */
28240 cp_parser_token_starts_function_definition_p (cp_token
* token
)
28242 return (/* An ordinary function-body begins with an `{'. */
28243 token
->type
== CPP_OPEN_BRACE
28244 /* A ctor-initializer begins with a `:'. */
28245 || token
->type
== CPP_COLON
28246 /* A function-try-block begins with `try'. */
28247 || token
->keyword
== RID_TRY
28248 /* A function-transaction-block begins with `__transaction_atomic'
28249 or `__transaction_relaxed'. */
28250 || token
->keyword
== RID_TRANSACTION_ATOMIC
28251 || token
->keyword
== RID_TRANSACTION_RELAXED
28252 /* The named return value extension begins with `return'. */
28253 || token
->keyword
== RID_RETURN
);
28256 /* Returns TRUE iff the next token is the ":" or "{" beginning a class
28260 cp_parser_next_token_starts_class_definition_p (cp_parser
*parser
)
28264 token
= cp_lexer_peek_token (parser
->lexer
);
28265 return (token
->type
== CPP_OPEN_BRACE
28266 || (token
->type
== CPP_COLON
28267 && !parser
->colon_doesnt_start_class_def_p
));
28270 /* Returns TRUE iff the next token is the "," or ">" (or `>>', in
28271 C++0x) ending a template-argument. */
28274 cp_parser_next_token_ends_template_argument_p (cp_parser
*parser
)
28278 token
= cp_lexer_peek_token (parser
->lexer
);
28279 return (token
->type
== CPP_COMMA
28280 || token
->type
== CPP_GREATER
28281 || token
->type
== CPP_ELLIPSIS
28282 || ((cxx_dialect
!= cxx98
) && token
->type
== CPP_RSHIFT
));
28285 /* Returns TRUE iff the n-th token is a "<", or the n-th is a "[" and the
28286 (n+1)-th is a ":" (which is a possible digraph typo for "< ::"). */
28289 cp_parser_nth_token_starts_template_argument_list_p (cp_parser
* parser
,
28294 token
= cp_lexer_peek_nth_token (parser
->lexer
, n
);
28295 if (token
->type
== CPP_LESS
)
28297 /* Check for the sequence `<::' in the original code. It would be lexed as
28298 `[:', where `[' is a digraph, and there is no whitespace before
28300 if (token
->type
== CPP_OPEN_SQUARE
&& token
->flags
& DIGRAPH
)
28303 token2
= cp_lexer_peek_nth_token (parser
->lexer
, n
+1);
28304 if (token2
->type
== CPP_COLON
&& !(token2
->flags
& PREV_WHITE
))
28310 /* Returns the kind of tag indicated by TOKEN, if it is a class-key,
28311 or none_type otherwise. */
28313 static enum tag_types
28314 cp_parser_token_is_class_key (cp_token
* token
)
28316 switch (token
->keyword
)
28321 return record_type
;
28330 /* Returns the kind of tag indicated by TOKEN, if it is a type-parameter-key,
28331 or none_type otherwise or if the token is null. */
28333 static enum tag_types
28334 cp_parser_token_is_type_parameter_key (cp_token
* token
)
28339 switch (token
->keyword
)
28344 return typename_type
;
28351 /* Issue an error message if the CLASS_KEY does not match the TYPE. */
28354 cp_parser_check_class_key (enum tag_types class_key
, tree type
)
28356 if (type
== error_mark_node
)
28358 if ((TREE_CODE (type
) == UNION_TYPE
) != (class_key
== union_type
))
28360 if (permerror (input_location
, "%qs tag used in naming %q#T",
28361 class_key
== union_type
? "union"
28362 : class_key
== record_type
? "struct" : "class",
28364 inform (DECL_SOURCE_LOCATION (TYPE_NAME (type
)),
28365 "%q#T was previously declared here", type
);
28369 /* Issue an error message if DECL is redeclared with different
28370 access than its original declaration [class.access.spec/3].
28371 This applies to nested classes, nested class templates and
28372 enumerations [class.mem/1]. */
28375 cp_parser_check_access_in_redeclaration (tree decl
, location_t location
)
28378 || (!CLASS_TYPE_P (TREE_TYPE (decl
))
28379 && TREE_CODE (TREE_TYPE (decl
)) != ENUMERAL_TYPE
))
28382 if ((TREE_PRIVATE (decl
)
28383 != (current_access_specifier
== access_private_node
))
28384 || (TREE_PROTECTED (decl
)
28385 != (current_access_specifier
== access_protected_node
)))
28386 error_at (location
, "%qD redeclared with different access", decl
);
28389 /* Look for the `template' keyword, as a syntactic disambiguator.
28390 Return TRUE iff it is present, in which case it will be
28394 cp_parser_optional_template_keyword (cp_parser
*parser
)
28396 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TEMPLATE
))
28398 /* In C++98 the `template' keyword can only be used within templates;
28399 outside templates the parser can always figure out what is a
28400 template and what is not. In C++11, per the resolution of DR 468,
28401 `template' is allowed in cases where it is not strictly necessary. */
28402 if (!processing_template_decl
28403 && pedantic
&& cxx_dialect
== cxx98
)
28405 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
28406 pedwarn (token
->location
, OPT_Wpedantic
,
28407 "in C++98 %<template%> (as a disambiguator) is only "
28408 "allowed within templates");
28409 /* If this part of the token stream is rescanned, the same
28410 error message would be generated. So, we purge the token
28411 from the stream. */
28412 cp_lexer_purge_token (parser
->lexer
);
28417 /* Consume the `template' keyword. */
28418 cp_lexer_consume_token (parser
->lexer
);
28425 /* The next token is a CPP_NESTED_NAME_SPECIFIER. Consume the token,
28426 set PARSER->SCOPE, and perform other related actions. */
28429 cp_parser_pre_parsed_nested_name_specifier (cp_parser
*parser
)
28431 struct tree_check
*check_value
;
28433 /* Get the stored value. */
28434 check_value
= cp_lexer_consume_token (parser
->lexer
)->u
.tree_check_value
;
28435 /* Set the scope from the stored value. */
28436 parser
->scope
= saved_checks_value (check_value
);
28437 parser
->qualifying_scope
= check_value
->qualifying_scope
;
28438 parser
->object_scope
= NULL_TREE
;
28441 /* Consume tokens up through a non-nested END token. Returns TRUE if we
28442 encounter the end of a block before what we were looking for. */
28445 cp_parser_cache_group (cp_parser
*parser
,
28446 enum cpp_ttype end
,
28451 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
28453 /* Abort a parenthesized expression if we encounter a semicolon. */
28454 if ((end
== CPP_CLOSE_PAREN
|| depth
== 0)
28455 && token
->type
== CPP_SEMICOLON
)
28457 /* If we've reached the end of the file, stop. */
28458 if (token
->type
== CPP_EOF
28459 || (end
!= CPP_PRAGMA_EOL
28460 && token
->type
== CPP_PRAGMA_EOL
))
28462 if (token
->type
== CPP_CLOSE_BRACE
&& depth
== 0)
28463 /* We've hit the end of an enclosing block, so there's been some
28464 kind of syntax error. */
28467 /* Consume the token. */
28468 cp_lexer_consume_token (parser
->lexer
);
28469 /* See if it starts a new group. */
28470 if (token
->type
== CPP_OPEN_BRACE
)
28472 cp_parser_cache_group (parser
, CPP_CLOSE_BRACE
, depth
+ 1);
28473 /* In theory this should probably check end == '}', but
28474 cp_parser_save_member_function_body needs it to exit
28475 after either '}' or ')' when called with ')'. */
28479 else if (token
->type
== CPP_OPEN_PAREN
)
28481 cp_parser_cache_group (parser
, CPP_CLOSE_PAREN
, depth
+ 1);
28482 if (depth
== 0 && end
== CPP_CLOSE_PAREN
)
28485 else if (token
->type
== CPP_PRAGMA
)
28486 cp_parser_cache_group (parser
, CPP_PRAGMA_EOL
, depth
+ 1);
28487 else if (token
->type
== end
)
28492 /* Like above, for caching a default argument or NSDMI. Both of these are
28493 terminated by a non-nested comma, but it can be unclear whether or not a
28494 comma is nested in a template argument list unless we do more parsing.
28495 In order to handle this ambiguity, when we encounter a ',' after a '<'
28496 we try to parse what follows as a parameter-declaration-list (in the
28497 case of a default argument) or a member-declarator (in the case of an
28498 NSDMI). If that succeeds, then we stop caching. */
28501 cp_parser_cache_defarg (cp_parser
*parser
, bool nsdmi
)
28503 unsigned depth
= 0;
28504 int maybe_template_id
= 0;
28505 cp_token
*first_token
;
28507 tree default_argument
;
28509 /* Add tokens until we have processed the entire default
28510 argument. We add the range [first_token, token). */
28511 first_token
= cp_lexer_peek_token (parser
->lexer
);
28512 if (first_token
->type
== CPP_OPEN_BRACE
)
28514 /* For list-initialization, this is straightforward. */
28515 cp_parser_cache_group (parser
, CPP_CLOSE_BRACE
, /*depth=*/0);
28516 token
= cp_lexer_peek_token (parser
->lexer
);
28522 /* Peek at the next token. */
28523 token
= cp_lexer_peek_token (parser
->lexer
);
28524 /* What we do depends on what token we have. */
28525 switch (token
->type
)
28527 /* In valid code, a default argument must be
28528 immediately followed by a `,' `)', or `...'. */
28530 if (depth
== 0 && maybe_template_id
)
28532 /* If we've seen a '<', we might be in a
28533 template-argument-list. Until Core issue 325 is
28534 resolved, we don't know how this situation ought
28535 to be handled, so try to DTRT. We check whether
28536 what comes after the comma is a valid parameter
28537 declaration list. If it is, then the comma ends
28538 the default argument; otherwise the default
28539 argument continues. */
28540 bool error
= false;
28543 /* Set ITALP so cp_parser_parameter_declaration_list
28544 doesn't decide to commit to this parse. */
28545 bool saved_italp
= parser
->in_template_argument_list_p
;
28546 parser
->in_template_argument_list_p
= true;
28548 cp_parser_parse_tentatively (parser
);
28552 /* Parse declarators until we reach a non-comma or
28553 somthing that cannot be an initializer.
28554 Just checking whether we're looking at a single
28555 declarator is insufficient. Consider:
28556 int var = tuple<T,U>::x;
28557 The template parameter 'U' looks exactly like a
28561 int ctor_dtor_or_conv_p
;
28562 cp_lexer_consume_token (parser
->lexer
);
28563 cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_NAMED
,
28564 &ctor_dtor_or_conv_p
,
28565 /*parenthesized_p=*/NULL
,
28567 /*friend_p=*/false);
28568 peek
= cp_lexer_peek_token (parser
->lexer
);
28569 if (cp_parser_error_occurred (parser
))
28572 while (peek
->type
== CPP_COMMA
);
28573 /* If we met an '=' or ';' then the original comma
28574 was the end of the NSDMI. Otherwise assume
28575 we're still in the NSDMI. */
28576 error
= (peek
->type
!= CPP_EQ
28577 && peek
->type
!= CPP_SEMICOLON
);
28581 cp_lexer_consume_token (parser
->lexer
);
28582 begin_scope (sk_function_parms
, NULL_TREE
);
28583 cp_parser_parameter_declaration_list (parser
, &error
);
28584 pop_bindings_and_leave_scope ();
28586 if (!cp_parser_error_occurred (parser
) && !error
)
28588 cp_parser_abort_tentative_parse (parser
);
28590 parser
->in_template_argument_list_p
= saved_italp
;
28594 case CPP_CLOSE_PAREN
:
28596 /* If we run into a non-nested `;', `}', or `]',
28597 then the code is invalid -- but the default
28598 argument is certainly over. */
28599 case CPP_SEMICOLON
:
28600 case CPP_CLOSE_BRACE
:
28601 case CPP_CLOSE_SQUARE
:
28603 /* Handle correctly int n = sizeof ... ( p ); */
28604 && token
->type
!= CPP_ELLIPSIS
)
28606 /* Update DEPTH, if necessary. */
28607 else if (token
->type
== CPP_CLOSE_PAREN
28608 || token
->type
== CPP_CLOSE_BRACE
28609 || token
->type
== CPP_CLOSE_SQUARE
)
28613 case CPP_OPEN_PAREN
:
28614 case CPP_OPEN_SQUARE
:
28615 case CPP_OPEN_BRACE
:
28621 /* This might be the comparison operator, or it might
28622 start a template argument list. */
28623 ++maybe_template_id
;
28627 if (cxx_dialect
== cxx98
)
28629 /* Fall through for C++0x, which treats the `>>'
28630 operator like two `>' tokens in certain
28632 gcc_fallthrough ();
28637 /* This might be an operator, or it might close a
28638 template argument list. But if a previous '<'
28639 started a template argument list, this will have
28640 closed it, so we can't be in one anymore. */
28641 maybe_template_id
-= 1 + (token
->type
== CPP_RSHIFT
);
28642 if (maybe_template_id
< 0)
28643 maybe_template_id
= 0;
28647 /* If we run out of tokens, issue an error message. */
28649 case CPP_PRAGMA_EOL
:
28650 error_at (token
->location
, "file ends in default argument");
28651 return error_mark_node
;
28655 /* In these cases, we should look for template-ids.
28656 For example, if the default argument is
28657 `X<int, double>()', we need to do name lookup to
28658 figure out whether or not `X' is a template; if
28659 so, the `,' does not end the default argument.
28661 That is not yet done. */
28668 /* If we've reached the end, stop. */
28672 /* Add the token to the token block. */
28673 token
= cp_lexer_consume_token (parser
->lexer
);
28676 /* Create a DEFAULT_ARG to represent the unparsed default
28678 default_argument
= make_node (DEFAULT_ARG
);
28679 DEFARG_TOKENS (default_argument
)
28680 = cp_token_cache_new (first_token
, token
);
28681 DEFARG_INSTANTIATIONS (default_argument
) = NULL
;
28683 return default_argument
;
28686 /* Begin parsing tentatively. We always save tokens while parsing
28687 tentatively so that if the tentative parsing fails we can restore the
28691 cp_parser_parse_tentatively (cp_parser
* parser
)
28693 /* Enter a new parsing context. */
28694 parser
->context
= cp_parser_context_new (parser
->context
);
28695 /* Begin saving tokens. */
28696 cp_lexer_save_tokens (parser
->lexer
);
28697 /* In order to avoid repetitive access control error messages,
28698 access checks are queued up until we are no longer parsing
28700 push_deferring_access_checks (dk_deferred
);
28703 /* Commit to the currently active tentative parse. */
28706 cp_parser_commit_to_tentative_parse (cp_parser
* parser
)
28708 cp_parser_context
*context
;
28711 /* Mark all of the levels as committed. */
28712 lexer
= parser
->lexer
;
28713 for (context
= parser
->context
; context
->next
; context
= context
->next
)
28715 if (context
->status
== CP_PARSER_STATUS_KIND_COMMITTED
)
28717 context
->status
= CP_PARSER_STATUS_KIND_COMMITTED
;
28718 while (!cp_lexer_saving_tokens (lexer
))
28719 lexer
= lexer
->next
;
28720 cp_lexer_commit_tokens (lexer
);
28724 /* Commit to the topmost currently active tentative parse.
28726 Note that this function shouldn't be called when there are
28727 irreversible side-effects while in a tentative state. For
28728 example, we shouldn't create a permanent entry in the symbol
28729 table, or issue an error message that might not apply if the
28730 tentative parse is aborted. */
28733 cp_parser_commit_to_topmost_tentative_parse (cp_parser
* parser
)
28735 cp_parser_context
*context
= parser
->context
;
28736 cp_lexer
*lexer
= parser
->lexer
;
28740 if (context
->status
== CP_PARSER_STATUS_KIND_COMMITTED
)
28742 context
->status
= CP_PARSER_STATUS_KIND_COMMITTED
;
28744 while (!cp_lexer_saving_tokens (lexer
))
28745 lexer
= lexer
->next
;
28746 cp_lexer_commit_tokens (lexer
);
28750 /* Abort the currently active tentative parse. All consumed tokens
28751 will be rolled back, and no diagnostics will be issued. */
28754 cp_parser_abort_tentative_parse (cp_parser
* parser
)
28756 gcc_assert (parser
->context
->status
!= CP_PARSER_STATUS_KIND_COMMITTED
28757 || errorcount
> 0);
28758 cp_parser_simulate_error (parser
);
28759 /* Now, pretend that we want to see if the construct was
28760 successfully parsed. */
28761 cp_parser_parse_definitely (parser
);
28764 /* Stop parsing tentatively. If a parse error has occurred, restore the
28765 token stream. Otherwise, commit to the tokens we have consumed.
28766 Returns true if no error occurred; false otherwise. */
28769 cp_parser_parse_definitely (cp_parser
* parser
)
28771 bool error_occurred
;
28772 cp_parser_context
*context
;
28774 /* Remember whether or not an error occurred, since we are about to
28775 destroy that information. */
28776 error_occurred
= cp_parser_error_occurred (parser
);
28777 /* Remove the topmost context from the stack. */
28778 context
= parser
->context
;
28779 parser
->context
= context
->next
;
28780 /* If no parse errors occurred, commit to the tentative parse. */
28781 if (!error_occurred
)
28783 /* Commit to the tokens read tentatively, unless that was
28785 if (context
->status
!= CP_PARSER_STATUS_KIND_COMMITTED
)
28786 cp_lexer_commit_tokens (parser
->lexer
);
28788 pop_to_parent_deferring_access_checks ();
28790 /* Otherwise, if errors occurred, roll back our state so that things
28791 are just as they were before we began the tentative parse. */
28794 cp_lexer_rollback_tokens (parser
->lexer
);
28795 pop_deferring_access_checks ();
28797 /* Add the context to the front of the free list. */
28798 context
->next
= cp_parser_context_free_list
;
28799 cp_parser_context_free_list
= context
;
28801 return !error_occurred
;
28804 /* Returns true if we are parsing tentatively and are not committed to
28805 this tentative parse. */
28808 cp_parser_uncommitted_to_tentative_parse_p (cp_parser
* parser
)
28810 return (cp_parser_parsing_tentatively (parser
)
28811 && parser
->context
->status
!= CP_PARSER_STATUS_KIND_COMMITTED
);
28814 /* Returns nonzero iff an error has occurred during the most recent
28815 tentative parse. */
28818 cp_parser_error_occurred (cp_parser
* parser
)
28820 return (cp_parser_parsing_tentatively (parser
)
28821 && parser
->context
->status
== CP_PARSER_STATUS_KIND_ERROR
);
28824 /* Returns nonzero if GNU extensions are allowed. */
28827 cp_parser_allow_gnu_extensions_p (cp_parser
* parser
)
28829 return parser
->allow_gnu_extensions_p
;
28832 /* Objective-C++ Productions */
28835 /* Parse an Objective-C expression, which feeds into a primary-expression
28839 objc-message-expression
28840 objc-string-literal
28841 objc-encode-expression
28842 objc-protocol-expression
28843 objc-selector-expression
28845 Returns a tree representation of the expression. */
28848 cp_parser_objc_expression (cp_parser
* parser
)
28850 /* Try to figure out what kind of declaration is present. */
28851 cp_token
*kwd
= cp_lexer_peek_token (parser
->lexer
);
28855 case CPP_OPEN_SQUARE
:
28856 return cp_parser_objc_message_expression (parser
);
28858 case CPP_OBJC_STRING
:
28859 kwd
= cp_lexer_consume_token (parser
->lexer
);
28860 return objc_build_string_object (kwd
->u
.value
);
28863 switch (kwd
->keyword
)
28865 case RID_AT_ENCODE
:
28866 return cp_parser_objc_encode_expression (parser
);
28868 case RID_AT_PROTOCOL
:
28869 return cp_parser_objc_protocol_expression (parser
);
28871 case RID_AT_SELECTOR
:
28872 return cp_parser_objc_selector_expression (parser
);
28878 error_at (kwd
->location
,
28879 "misplaced %<@%D%> Objective-C++ construct",
28881 cp_parser_skip_to_end_of_block_or_statement (parser
);
28884 return error_mark_node
;
28887 /* Parse an Objective-C message expression.
28889 objc-message-expression:
28890 [ objc-message-receiver objc-message-args ]
28892 Returns a representation of an Objective-C message. */
28895 cp_parser_objc_message_expression (cp_parser
* parser
)
28897 tree receiver
, messageargs
;
28899 location_t start_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
28900 cp_lexer_consume_token (parser
->lexer
); /* Eat '['. */
28901 receiver
= cp_parser_objc_message_receiver (parser
);
28902 messageargs
= cp_parser_objc_message_args (parser
);
28903 location_t end_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
28904 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
28906 tree result
= objc_build_message_expr (receiver
, messageargs
);
28908 /* Construct a location e.g.
28911 ranging from the '[' to the ']', with the caret at the start. */
28912 location_t combined_loc
= make_location (start_loc
, start_loc
, end_loc
);
28913 protected_set_expr_location (result
, combined_loc
);
28918 /* Parse an objc-message-receiver.
28920 objc-message-receiver:
28922 simple-type-specifier
28924 Returns a representation of the type or expression. */
28927 cp_parser_objc_message_receiver (cp_parser
* parser
)
28931 /* An Objective-C message receiver may be either (1) a type
28932 or (2) an expression. */
28933 cp_parser_parse_tentatively (parser
);
28934 rcv
= cp_parser_expression (parser
);
28936 /* If that worked out, fine. */
28937 if (cp_parser_parse_definitely (parser
))
28940 cp_parser_parse_tentatively (parser
);
28941 rcv
= cp_parser_simple_type_specifier (parser
,
28942 /*decl_specs=*/NULL
,
28943 CP_PARSER_FLAGS_NONE
);
28945 if (cp_parser_parse_definitely (parser
))
28946 return objc_get_class_reference (rcv
);
28948 cp_parser_error (parser
, "objective-c++ message receiver expected");
28949 return error_mark_node
;
28952 /* Parse the arguments and selectors comprising an Objective-C message.
28957 objc-selector-args , objc-comma-args
28959 objc-selector-args:
28960 objc-selector [opt] : assignment-expression
28961 objc-selector-args objc-selector [opt] : assignment-expression
28964 assignment-expression
28965 objc-comma-args , assignment-expression
28967 Returns a TREE_LIST, with TREE_PURPOSE containing a list of
28968 selector arguments and TREE_VALUE containing a list of comma
28972 cp_parser_objc_message_args (cp_parser
* parser
)
28974 tree sel_args
= NULL_TREE
, addl_args
= NULL_TREE
;
28975 bool maybe_unary_selector_p
= true;
28976 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
28978 while (cp_parser_objc_selector_p (token
->type
) || token
->type
== CPP_COLON
)
28980 tree selector
= NULL_TREE
, arg
;
28982 if (token
->type
!= CPP_COLON
)
28983 selector
= cp_parser_objc_selector (parser
);
28985 /* Detect if we have a unary selector. */
28986 if (maybe_unary_selector_p
28987 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_COLON
))
28988 return build_tree_list (selector
, NULL_TREE
);
28990 maybe_unary_selector_p
= false;
28991 cp_parser_require (parser
, CPP_COLON
, RT_COLON
);
28992 arg
= cp_parser_assignment_expression (parser
);
28995 = chainon (sel_args
,
28996 build_tree_list (selector
, arg
));
28998 token
= cp_lexer_peek_token (parser
->lexer
);
29001 /* Handle non-selector arguments, if any. */
29002 while (token
->type
== CPP_COMMA
)
29006 cp_lexer_consume_token (parser
->lexer
);
29007 arg
= cp_parser_assignment_expression (parser
);
29010 = chainon (addl_args
,
29011 build_tree_list (NULL_TREE
, arg
));
29013 token
= cp_lexer_peek_token (parser
->lexer
);
29016 if (sel_args
== NULL_TREE
&& addl_args
== NULL_TREE
)
29018 cp_parser_error (parser
, "objective-c++ message argument(s) are expected");
29019 return build_tree_list (error_mark_node
, error_mark_node
);
29022 return build_tree_list (sel_args
, addl_args
);
29025 /* Parse an Objective-C encode expression.
29027 objc-encode-expression:
29028 @encode objc-typename
29030 Returns an encoded representation of the type argument. */
29033 cp_parser_objc_encode_expression (cp_parser
* parser
)
29037 location_t start_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
29039 cp_lexer_consume_token (parser
->lexer
); /* Eat '@encode'. */
29040 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
29041 token
= cp_lexer_peek_token (parser
->lexer
);
29042 type
= complete_type (cp_parser_type_id (parser
));
29043 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
29047 error_at (token
->location
,
29048 "%<@encode%> must specify a type as an argument");
29049 return error_mark_node
;
29052 /* This happens if we find @encode(T) (where T is a template
29053 typename or something dependent on a template typename) when
29054 parsing a template. In that case, we can't compile it
29055 immediately, but we rather create an AT_ENCODE_EXPR which will
29056 need to be instantiated when the template is used.
29058 if (dependent_type_p (type
))
29060 tree value
= build_min (AT_ENCODE_EXPR
, size_type_node
, type
);
29061 TREE_READONLY (value
) = 1;
29066 /* Build a location of the form:
29069 with caret==start at the @ token, finishing at the close paren. */
29070 location_t combined_loc
29071 = make_location (start_loc
, start_loc
,
29072 cp_lexer_previous_token (parser
->lexer
)->location
);
29074 return cp_expr (objc_build_encode_expr (type
), combined_loc
);
29077 /* Parse an Objective-C @defs expression. */
29080 cp_parser_objc_defs_expression (cp_parser
*parser
)
29084 cp_lexer_consume_token (parser
->lexer
); /* Eat '@defs'. */
29085 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
29086 name
= cp_parser_identifier (parser
);
29087 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
29089 return objc_get_class_ivars (name
);
29092 /* Parse an Objective-C protocol expression.
29094 objc-protocol-expression:
29095 @protocol ( identifier )
29097 Returns a representation of the protocol expression. */
29100 cp_parser_objc_protocol_expression (cp_parser
* parser
)
29103 location_t start_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
29105 cp_lexer_consume_token (parser
->lexer
); /* Eat '@protocol'. */
29106 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
29107 proto
= cp_parser_identifier (parser
);
29108 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
29110 /* Build a location of the form:
29113 with caret==start at the @ token, finishing at the close paren. */
29114 location_t combined_loc
29115 = make_location (start_loc
, start_loc
,
29116 cp_lexer_previous_token (parser
->lexer
)->location
);
29117 tree result
= objc_build_protocol_expr (proto
);
29118 protected_set_expr_location (result
, combined_loc
);
29122 /* Parse an Objective-C selector expression.
29124 objc-selector-expression:
29125 @selector ( objc-method-signature )
29127 objc-method-signature:
29133 objc-selector-seq objc-selector :
29135 Returns a representation of the method selector. */
29138 cp_parser_objc_selector_expression (cp_parser
* parser
)
29140 tree sel_seq
= NULL_TREE
;
29141 bool maybe_unary_selector_p
= true;
29143 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
29145 cp_lexer_consume_token (parser
->lexer
); /* Eat '@selector'. */
29146 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
29147 token
= cp_lexer_peek_token (parser
->lexer
);
29149 while (cp_parser_objc_selector_p (token
->type
) || token
->type
== CPP_COLON
29150 || token
->type
== CPP_SCOPE
)
29152 tree selector
= NULL_TREE
;
29154 if (token
->type
!= CPP_COLON
29155 || token
->type
== CPP_SCOPE
)
29156 selector
= cp_parser_objc_selector (parser
);
29158 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COLON
)
29159 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_SCOPE
))
29161 /* Detect if we have a unary selector. */
29162 if (maybe_unary_selector_p
)
29164 sel_seq
= selector
;
29165 goto finish_selector
;
29169 cp_parser_error (parser
, "expected %<:%>");
29172 maybe_unary_selector_p
= false;
29173 token
= cp_lexer_consume_token (parser
->lexer
);
29175 if (token
->type
== CPP_SCOPE
)
29178 = chainon (sel_seq
,
29179 build_tree_list (selector
, NULL_TREE
));
29181 = chainon (sel_seq
,
29182 build_tree_list (NULL_TREE
, NULL_TREE
));
29186 = chainon (sel_seq
,
29187 build_tree_list (selector
, NULL_TREE
));
29189 token
= cp_lexer_peek_token (parser
->lexer
);
29193 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
29196 /* Build a location of the form:
29199 with caret==start at the @ token, finishing at the close paren. */
29200 location_t combined_loc
29201 = make_location (loc
, loc
,
29202 cp_lexer_previous_token (parser
->lexer
)->location
);
29203 tree result
= objc_build_selector_expr (combined_loc
, sel_seq
);
29204 /* TODO: objc_build_selector_expr doesn't always honor the location. */
29205 protected_set_expr_location (result
, combined_loc
);
29209 /* Parse a list of identifiers.
29211 objc-identifier-list:
29213 objc-identifier-list , identifier
29215 Returns a TREE_LIST of identifier nodes. */
29218 cp_parser_objc_identifier_list (cp_parser
* parser
)
29224 identifier
= cp_parser_identifier (parser
);
29225 if (identifier
== error_mark_node
)
29226 return error_mark_node
;
29228 list
= build_tree_list (NULL_TREE
, identifier
);
29229 sep
= cp_lexer_peek_token (parser
->lexer
);
29231 while (sep
->type
== CPP_COMMA
)
29233 cp_lexer_consume_token (parser
->lexer
); /* Eat ','. */
29234 identifier
= cp_parser_identifier (parser
);
29235 if (identifier
== error_mark_node
)
29238 list
= chainon (list
, build_tree_list (NULL_TREE
,
29240 sep
= cp_lexer_peek_token (parser
->lexer
);
29246 /* Parse an Objective-C alias declaration.
29248 objc-alias-declaration:
29249 @compatibility_alias identifier identifier ;
29251 This function registers the alias mapping with the Objective-C front end.
29252 It returns nothing. */
29255 cp_parser_objc_alias_declaration (cp_parser
* parser
)
29259 cp_lexer_consume_token (parser
->lexer
); /* Eat '@compatibility_alias'. */
29260 alias
= cp_parser_identifier (parser
);
29261 orig
= cp_parser_identifier (parser
);
29262 objc_declare_alias (alias
, orig
);
29263 cp_parser_consume_semicolon_at_end_of_statement (parser
);
29266 /* Parse an Objective-C class forward-declaration.
29268 objc-class-declaration:
29269 @class objc-identifier-list ;
29271 The function registers the forward declarations with the Objective-C
29272 front end. It returns nothing. */
29275 cp_parser_objc_class_declaration (cp_parser
* parser
)
29277 cp_lexer_consume_token (parser
->lexer
); /* Eat '@class'. */
29282 id
= cp_parser_identifier (parser
);
29283 if (id
== error_mark_node
)
29286 objc_declare_class (id
);
29288 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
29289 cp_lexer_consume_token (parser
->lexer
);
29293 cp_parser_consume_semicolon_at_end_of_statement (parser
);
29296 /* Parse a list of Objective-C protocol references.
29298 objc-protocol-refs-opt:
29299 objc-protocol-refs [opt]
29301 objc-protocol-refs:
29302 < objc-identifier-list >
29304 Returns a TREE_LIST of identifiers, if any. */
29307 cp_parser_objc_protocol_refs_opt (cp_parser
* parser
)
29309 tree protorefs
= NULL_TREE
;
29311 if(cp_lexer_next_token_is (parser
->lexer
, CPP_LESS
))
29313 cp_lexer_consume_token (parser
->lexer
); /* Eat '<'. */
29314 protorefs
= cp_parser_objc_identifier_list (parser
);
29315 cp_parser_require (parser
, CPP_GREATER
, RT_GREATER
);
29321 /* Parse a Objective-C visibility specification. */
29324 cp_parser_objc_visibility_spec (cp_parser
* parser
)
29326 cp_token
*vis
= cp_lexer_peek_token (parser
->lexer
);
29328 switch (vis
->keyword
)
29330 case RID_AT_PRIVATE
:
29331 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
29333 case RID_AT_PROTECTED
:
29334 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
29336 case RID_AT_PUBLIC
:
29337 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
29339 case RID_AT_PACKAGE
:
29340 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
29346 /* Eat '@private'/'@protected'/'@public'. */
29347 cp_lexer_consume_token (parser
->lexer
);
29350 /* Parse an Objective-C method type. Return 'true' if it is a class
29351 (+) method, and 'false' if it is an instance (-) method. */
29354 cp_parser_objc_method_type (cp_parser
* parser
)
29356 if (cp_lexer_consume_token (parser
->lexer
)->type
== CPP_PLUS
)
29362 /* Parse an Objective-C protocol qualifier. */
29365 cp_parser_objc_protocol_qualifiers (cp_parser
* parser
)
29367 tree quals
= NULL_TREE
, node
;
29368 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
29370 node
= token
->u
.value
;
29372 while (node
&& identifier_p (node
)
29373 && (node
== ridpointers
[(int) RID_IN
]
29374 || node
== ridpointers
[(int) RID_OUT
]
29375 || node
== ridpointers
[(int) RID_INOUT
]
29376 || node
== ridpointers
[(int) RID_BYCOPY
]
29377 || node
== ridpointers
[(int) RID_BYREF
]
29378 || node
== ridpointers
[(int) RID_ONEWAY
]))
29380 quals
= tree_cons (NULL_TREE
, node
, quals
);
29381 cp_lexer_consume_token (parser
->lexer
);
29382 token
= cp_lexer_peek_token (parser
->lexer
);
29383 node
= token
->u
.value
;
29389 /* Parse an Objective-C typename. */
29392 cp_parser_objc_typename (cp_parser
* parser
)
29394 tree type_name
= NULL_TREE
;
29396 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
29398 tree proto_quals
, cp_type
= NULL_TREE
;
29400 cp_lexer_consume_token (parser
->lexer
); /* Eat '('. */
29401 proto_quals
= cp_parser_objc_protocol_qualifiers (parser
);
29403 /* An ObjC type name may consist of just protocol qualifiers, in which
29404 case the type shall default to 'id'. */
29405 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_PAREN
))
29407 cp_type
= cp_parser_type_id (parser
);
29409 /* If the type could not be parsed, an error has already
29410 been produced. For error recovery, behave as if it had
29411 not been specified, which will use the default type
29413 if (cp_type
== error_mark_node
)
29415 cp_type
= NULL_TREE
;
29416 /* We need to skip to the closing parenthesis as
29417 cp_parser_type_id() does not seem to do it for
29419 cp_parser_skip_to_closing_parenthesis (parser
,
29420 /*recovering=*/true,
29421 /*or_comma=*/false,
29422 /*consume_paren=*/false);
29426 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
29427 type_name
= build_tree_list (proto_quals
, cp_type
);
29433 /* Check to see if TYPE refers to an Objective-C selector name. */
29436 cp_parser_objc_selector_p (enum cpp_ttype type
)
29438 return (type
== CPP_NAME
|| type
== CPP_KEYWORD
29439 || type
== CPP_AND_AND
|| type
== CPP_AND_EQ
|| type
== CPP_AND
29440 || type
== CPP_OR
|| type
== CPP_COMPL
|| type
== CPP_NOT
29441 || type
== CPP_NOT_EQ
|| type
== CPP_OR_OR
|| type
== CPP_OR_EQ
29442 || type
== CPP_XOR
|| type
== CPP_XOR_EQ
);
29445 /* Parse an Objective-C selector. */
29448 cp_parser_objc_selector (cp_parser
* parser
)
29450 cp_token
*token
= cp_lexer_consume_token (parser
->lexer
);
29452 if (!cp_parser_objc_selector_p (token
->type
))
29454 error_at (token
->location
, "invalid Objective-C++ selector name");
29455 return error_mark_node
;
29458 /* C++ operator names are allowed to appear in ObjC selectors. */
29459 switch (token
->type
)
29461 case CPP_AND_AND
: return get_identifier ("and");
29462 case CPP_AND_EQ
: return get_identifier ("and_eq");
29463 case CPP_AND
: return get_identifier ("bitand");
29464 case CPP_OR
: return get_identifier ("bitor");
29465 case CPP_COMPL
: return get_identifier ("compl");
29466 case CPP_NOT
: return get_identifier ("not");
29467 case CPP_NOT_EQ
: return get_identifier ("not_eq");
29468 case CPP_OR_OR
: return get_identifier ("or");
29469 case CPP_OR_EQ
: return get_identifier ("or_eq");
29470 case CPP_XOR
: return get_identifier ("xor");
29471 case CPP_XOR_EQ
: return get_identifier ("xor_eq");
29472 default: return token
->u
.value
;
29476 /* Parse an Objective-C params list. */
29479 cp_parser_objc_method_keyword_params (cp_parser
* parser
, tree
* attributes
)
29481 tree params
= NULL_TREE
;
29482 bool maybe_unary_selector_p
= true;
29483 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
29485 while (cp_parser_objc_selector_p (token
->type
) || token
->type
== CPP_COLON
)
29487 tree selector
= NULL_TREE
, type_name
, identifier
;
29488 tree parm_attr
= NULL_TREE
;
29490 if (token
->keyword
== RID_ATTRIBUTE
)
29493 if (token
->type
!= CPP_COLON
)
29494 selector
= cp_parser_objc_selector (parser
);
29496 /* Detect if we have a unary selector. */
29497 if (maybe_unary_selector_p
29498 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_COLON
))
29500 params
= selector
; /* Might be followed by attributes. */
29504 maybe_unary_selector_p
= false;
29505 if (!cp_parser_require (parser
, CPP_COLON
, RT_COLON
))
29507 /* Something went quite wrong. There should be a colon
29508 here, but there is not. Stop parsing parameters. */
29511 type_name
= cp_parser_objc_typename (parser
);
29512 /* New ObjC allows attributes on parameters too. */
29513 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_ATTRIBUTE
))
29514 parm_attr
= cp_parser_attributes_opt (parser
);
29515 identifier
= cp_parser_identifier (parser
);
29519 objc_build_keyword_decl (selector
,
29524 token
= cp_lexer_peek_token (parser
->lexer
);
29527 if (params
== NULL_TREE
)
29529 cp_parser_error (parser
, "objective-c++ method declaration is expected");
29530 return error_mark_node
;
29533 /* We allow tail attributes for the method. */
29534 if (token
->keyword
== RID_ATTRIBUTE
)
29536 *attributes
= cp_parser_attributes_opt (parser
);
29537 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
)
29538 || cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
29540 cp_parser_error (parser
,
29541 "method attributes must be specified at the end");
29542 return error_mark_node
;
29545 if (params
== NULL_TREE
)
29547 cp_parser_error (parser
, "objective-c++ method declaration is expected");
29548 return error_mark_node
;
29553 /* Parse the non-keyword Objective-C params. */
29556 cp_parser_objc_method_tail_params_opt (cp_parser
* parser
, bool *ellipsisp
,
29559 tree params
= make_node (TREE_LIST
);
29560 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
29561 *ellipsisp
= false; /* Initially, assume no ellipsis. */
29563 while (token
->type
== CPP_COMMA
)
29565 cp_parameter_declarator
*parmdecl
;
29568 cp_lexer_consume_token (parser
->lexer
); /* Eat ','. */
29569 token
= cp_lexer_peek_token (parser
->lexer
);
29571 if (token
->type
== CPP_ELLIPSIS
)
29573 cp_lexer_consume_token (parser
->lexer
); /* Eat '...'. */
29575 token
= cp_lexer_peek_token (parser
->lexer
);
29579 /* TODO: parse attributes for tail parameters. */
29580 parmdecl
= cp_parser_parameter_declaration (parser
, false, NULL
);
29581 parm
= grokdeclarator (parmdecl
->declarator
,
29582 &parmdecl
->decl_specifiers
,
29583 PARM
, /*initialized=*/0,
29584 /*attrlist=*/NULL
);
29586 chainon (params
, build_tree_list (NULL_TREE
, parm
));
29587 token
= cp_lexer_peek_token (parser
->lexer
);
29590 /* We allow tail attributes for the method. */
29591 if (token
->keyword
== RID_ATTRIBUTE
)
29593 if (*attributes
== NULL_TREE
)
29595 *attributes
= cp_parser_attributes_opt (parser
);
29596 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
)
29597 || cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
29601 /* We have an error, but parse the attributes, so that we can
29603 *attributes
= cp_parser_attributes_opt (parser
);
29605 cp_parser_error (parser
,
29606 "method attributes must be specified at the end");
29607 return error_mark_node
;
29613 /* Parse a linkage specification, a pragma, an extra semicolon or a block. */
29616 cp_parser_objc_interstitial_code (cp_parser
* parser
)
29618 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
29620 /* If the next token is `extern' and the following token is a string
29621 literal, then we have a linkage specification. */
29622 if (token
->keyword
== RID_EXTERN
29623 && cp_parser_is_pure_string_literal
29624 (cp_lexer_peek_nth_token (parser
->lexer
, 2)))
29625 cp_parser_linkage_specification (parser
);
29626 /* Handle #pragma, if any. */
29627 else if (token
->type
== CPP_PRAGMA
)
29628 cp_parser_pragma (parser
, pragma_objc_icode
, NULL
);
29629 /* Allow stray semicolons. */
29630 else if (token
->type
== CPP_SEMICOLON
)
29631 cp_lexer_consume_token (parser
->lexer
);
29632 /* Mark methods as optional or required, when building protocols. */
29633 else if (token
->keyword
== RID_AT_OPTIONAL
)
29635 cp_lexer_consume_token (parser
->lexer
);
29636 objc_set_method_opt (true);
29638 else if (token
->keyword
== RID_AT_REQUIRED
)
29640 cp_lexer_consume_token (parser
->lexer
);
29641 objc_set_method_opt (false);
29643 else if (token
->keyword
== RID_NAMESPACE
)
29644 cp_parser_namespace_definition (parser
);
29645 /* Other stray characters must generate errors. */
29646 else if (token
->type
== CPP_OPEN_BRACE
|| token
->type
== CPP_CLOSE_BRACE
)
29648 cp_lexer_consume_token (parser
->lexer
);
29649 error ("stray %qs between Objective-C++ methods",
29650 token
->type
== CPP_OPEN_BRACE
? "{" : "}");
29652 /* Finally, try to parse a block-declaration, or a function-definition. */
29654 cp_parser_block_declaration (parser
, /*statement_p=*/false);
29657 /* Parse a method signature. */
29660 cp_parser_objc_method_signature (cp_parser
* parser
, tree
* attributes
)
29662 tree rettype
, kwdparms
, optparms
;
29663 bool ellipsis
= false;
29664 bool is_class_method
;
29666 is_class_method
= cp_parser_objc_method_type (parser
);
29667 rettype
= cp_parser_objc_typename (parser
);
29668 *attributes
= NULL_TREE
;
29669 kwdparms
= cp_parser_objc_method_keyword_params (parser
, attributes
);
29670 if (kwdparms
== error_mark_node
)
29671 return error_mark_node
;
29672 optparms
= cp_parser_objc_method_tail_params_opt (parser
, &ellipsis
, attributes
);
29673 if (optparms
== error_mark_node
)
29674 return error_mark_node
;
29676 return objc_build_method_signature (is_class_method
, rettype
, kwdparms
, optparms
, ellipsis
);
29680 cp_parser_objc_method_maybe_bad_prefix_attributes (cp_parser
* parser
)
29683 cp_lexer_save_tokens (parser
->lexer
);
29684 tattr
= cp_parser_attributes_opt (parser
);
29685 gcc_assert (tattr
) ;
29687 /* If the attributes are followed by a method introducer, this is not allowed.
29688 Dump the attributes and flag the situation. */
29689 if (cp_lexer_next_token_is (parser
->lexer
, CPP_PLUS
)
29690 || cp_lexer_next_token_is (parser
->lexer
, CPP_MINUS
))
29693 /* Otherwise, the attributes introduce some interstitial code, possibly so
29694 rewind to allow that check. */
29695 cp_lexer_rollback_tokens (parser
->lexer
);
29699 /* Parse an Objective-C method prototype list. */
29702 cp_parser_objc_method_prototype_list (cp_parser
* parser
)
29704 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
29706 while (token
->keyword
!= RID_AT_END
&& token
->type
!= CPP_EOF
)
29708 if (token
->type
== CPP_PLUS
|| token
->type
== CPP_MINUS
)
29710 tree attributes
, sig
;
29711 bool is_class_method
;
29712 if (token
->type
== CPP_PLUS
)
29713 is_class_method
= true;
29715 is_class_method
= false;
29716 sig
= cp_parser_objc_method_signature (parser
, &attributes
);
29717 if (sig
== error_mark_node
)
29719 cp_parser_skip_to_end_of_block_or_statement (parser
);
29720 token
= cp_lexer_peek_token (parser
->lexer
);
29723 objc_add_method_declaration (is_class_method
, sig
, attributes
);
29724 cp_parser_consume_semicolon_at_end_of_statement (parser
);
29726 else if (token
->keyword
== RID_AT_PROPERTY
)
29727 cp_parser_objc_at_property_declaration (parser
);
29728 else if (token
->keyword
== RID_ATTRIBUTE
29729 && cp_parser_objc_method_maybe_bad_prefix_attributes(parser
))
29730 warning_at (cp_lexer_peek_token (parser
->lexer
)->location
,
29732 "prefix attributes are ignored for methods");
29734 /* Allow for interspersed non-ObjC++ code. */
29735 cp_parser_objc_interstitial_code (parser
);
29737 token
= cp_lexer_peek_token (parser
->lexer
);
29740 if (token
->type
!= CPP_EOF
)
29741 cp_lexer_consume_token (parser
->lexer
); /* Eat '@end'. */
29743 cp_parser_error (parser
, "expected %<@end%>");
29745 objc_finish_interface ();
29748 /* Parse an Objective-C method definition list. */
29751 cp_parser_objc_method_definition_list (cp_parser
* parser
)
29753 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
29755 while (token
->keyword
!= RID_AT_END
&& token
->type
!= CPP_EOF
)
29759 if (token
->type
== CPP_PLUS
|| token
->type
== CPP_MINUS
)
29762 tree sig
, attribute
;
29763 bool is_class_method
;
29764 if (token
->type
== CPP_PLUS
)
29765 is_class_method
= true;
29767 is_class_method
= false;
29768 push_deferring_access_checks (dk_deferred
);
29769 sig
= cp_parser_objc_method_signature (parser
, &attribute
);
29770 if (sig
== error_mark_node
)
29772 cp_parser_skip_to_end_of_block_or_statement (parser
);
29773 token
= cp_lexer_peek_token (parser
->lexer
);
29776 objc_start_method_definition (is_class_method
, sig
, attribute
,
29779 /* For historical reasons, we accept an optional semicolon. */
29780 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
29781 cp_lexer_consume_token (parser
->lexer
);
29783 ptk
= cp_lexer_peek_token (parser
->lexer
);
29784 if (!(ptk
->type
== CPP_PLUS
|| ptk
->type
== CPP_MINUS
29785 || ptk
->type
== CPP_EOF
|| ptk
->keyword
== RID_AT_END
))
29787 perform_deferred_access_checks (tf_warning_or_error
);
29788 stop_deferring_access_checks ();
29789 meth
= cp_parser_function_definition_after_declarator (parser
,
29791 pop_deferring_access_checks ();
29792 objc_finish_method_definition (meth
);
29795 /* The following case will be removed once @synthesize is
29796 completely implemented. */
29797 else if (token
->keyword
== RID_AT_PROPERTY
)
29798 cp_parser_objc_at_property_declaration (parser
);
29799 else if (token
->keyword
== RID_AT_SYNTHESIZE
)
29800 cp_parser_objc_at_synthesize_declaration (parser
);
29801 else if (token
->keyword
== RID_AT_DYNAMIC
)
29802 cp_parser_objc_at_dynamic_declaration (parser
);
29803 else if (token
->keyword
== RID_ATTRIBUTE
29804 && cp_parser_objc_method_maybe_bad_prefix_attributes(parser
))
29805 warning_at (token
->location
, OPT_Wattributes
,
29806 "prefix attributes are ignored for methods");
29808 /* Allow for interspersed non-ObjC++ code. */
29809 cp_parser_objc_interstitial_code (parser
);
29811 token
= cp_lexer_peek_token (parser
->lexer
);
29814 if (token
->type
!= CPP_EOF
)
29815 cp_lexer_consume_token (parser
->lexer
); /* Eat '@end'. */
29817 cp_parser_error (parser
, "expected %<@end%>");
29819 objc_finish_implementation ();
29822 /* Parse Objective-C ivars. */
29825 cp_parser_objc_class_ivars (cp_parser
* parser
)
29827 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
29829 if (token
->type
!= CPP_OPEN_BRACE
)
29830 return; /* No ivars specified. */
29832 cp_lexer_consume_token (parser
->lexer
); /* Eat '{'. */
29833 token
= cp_lexer_peek_token (parser
->lexer
);
29835 while (token
->type
!= CPP_CLOSE_BRACE
29836 && token
->keyword
!= RID_AT_END
&& token
->type
!= CPP_EOF
)
29838 cp_decl_specifier_seq declspecs
;
29839 int decl_class_or_enum_p
;
29840 tree prefix_attributes
;
29842 cp_parser_objc_visibility_spec (parser
);
29844 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_BRACE
))
29847 cp_parser_decl_specifier_seq (parser
,
29848 CP_PARSER_FLAGS_OPTIONAL
,
29850 &decl_class_or_enum_p
);
29852 /* auto, register, static, extern, mutable. */
29853 if (declspecs
.storage_class
!= sc_none
)
29855 cp_parser_error (parser
, "invalid type for instance variable");
29856 declspecs
.storage_class
= sc_none
;
29859 /* thread_local. */
29860 if (decl_spec_seq_has_spec_p (&declspecs
, ds_thread
))
29862 cp_parser_error (parser
, "invalid type for instance variable");
29863 declspecs
.locations
[ds_thread
] = 0;
29867 if (decl_spec_seq_has_spec_p (&declspecs
, ds_typedef
))
29869 cp_parser_error (parser
, "invalid type for instance variable");
29870 declspecs
.locations
[ds_typedef
] = 0;
29873 prefix_attributes
= declspecs
.attributes
;
29874 declspecs
.attributes
= NULL_TREE
;
29876 /* Keep going until we hit the `;' at the end of the
29878 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
29880 tree width
= NULL_TREE
, attributes
, first_attribute
, decl
;
29881 cp_declarator
*declarator
= NULL
;
29882 int ctor_dtor_or_conv_p
;
29884 /* Check for a (possibly unnamed) bitfield declaration. */
29885 token
= cp_lexer_peek_token (parser
->lexer
);
29886 if (token
->type
== CPP_COLON
)
29889 if (token
->type
== CPP_NAME
29890 && (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
29893 /* Get the name of the bitfield. */
29894 declarator
= make_id_declarator (NULL_TREE
,
29895 cp_parser_identifier (parser
),
29899 cp_lexer_consume_token (parser
->lexer
); /* Eat ':'. */
29900 /* Get the width of the bitfield. */
29902 = cp_parser_constant_expression (parser
);
29906 /* Parse the declarator. */
29908 = cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_NAMED
,
29909 &ctor_dtor_or_conv_p
,
29910 /*parenthesized_p=*/NULL
,
29911 /*member_p=*/false,
29912 /*friend_p=*/false);
29915 /* Look for attributes that apply to the ivar. */
29916 attributes
= cp_parser_attributes_opt (parser
);
29917 /* Remember which attributes are prefix attributes and
29919 first_attribute
= attributes
;
29920 /* Combine the attributes. */
29921 attributes
= chainon (prefix_attributes
, attributes
);
29924 /* Create the bitfield declaration. */
29925 decl
= grokbitfield (declarator
, &declspecs
,
29929 decl
= grokfield (declarator
, &declspecs
,
29930 NULL_TREE
, /*init_const_expr_p=*/false,
29931 NULL_TREE
, attributes
);
29933 /* Add the instance variable. */
29934 if (decl
!= error_mark_node
&& decl
!= NULL_TREE
)
29935 objc_add_instance_variable (decl
);
29937 /* Reset PREFIX_ATTRIBUTES. */
29938 while (attributes
&& TREE_CHAIN (attributes
) != first_attribute
)
29939 attributes
= TREE_CHAIN (attributes
);
29941 TREE_CHAIN (attributes
) = NULL_TREE
;
29943 token
= cp_lexer_peek_token (parser
->lexer
);
29945 if (token
->type
== CPP_COMMA
)
29947 cp_lexer_consume_token (parser
->lexer
); /* Eat ','. */
29953 cp_parser_consume_semicolon_at_end_of_statement (parser
);
29954 token
= cp_lexer_peek_token (parser
->lexer
);
29957 if (token
->keyword
== RID_AT_END
)
29958 cp_parser_error (parser
, "expected %<}%>");
29960 /* Do not consume the RID_AT_END, so it will be read again as terminating
29961 the @interface of @implementation. */
29962 if (token
->keyword
!= RID_AT_END
&& token
->type
!= CPP_EOF
)
29963 cp_lexer_consume_token (parser
->lexer
); /* Eat '}'. */
29965 /* For historical reasons, we accept an optional semicolon. */
29966 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
29967 cp_lexer_consume_token (parser
->lexer
);
29970 /* Parse an Objective-C protocol declaration. */
29973 cp_parser_objc_protocol_declaration (cp_parser
* parser
, tree attributes
)
29975 tree proto
, protorefs
;
29978 cp_lexer_consume_token (parser
->lexer
); /* Eat '@protocol'. */
29979 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_NAME
))
29981 tok
= cp_lexer_peek_token (parser
->lexer
);
29982 error_at (tok
->location
, "identifier expected after %<@protocol%>");
29983 cp_parser_consume_semicolon_at_end_of_statement (parser
);
29987 /* See if we have a forward declaration or a definition. */
29988 tok
= cp_lexer_peek_nth_token (parser
->lexer
, 2);
29990 /* Try a forward declaration first. */
29991 if (tok
->type
== CPP_COMMA
|| tok
->type
== CPP_SEMICOLON
)
29997 id
= cp_parser_identifier (parser
);
29998 if (id
== error_mark_node
)
30001 objc_declare_protocol (id
, attributes
);
30003 if(cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
30004 cp_lexer_consume_token (parser
->lexer
);
30008 cp_parser_consume_semicolon_at_end_of_statement (parser
);
30011 /* Ok, we got a full-fledged definition (or at least should). */
30014 proto
= cp_parser_identifier (parser
);
30015 protorefs
= cp_parser_objc_protocol_refs_opt (parser
);
30016 objc_start_protocol (proto
, protorefs
, attributes
);
30017 cp_parser_objc_method_prototype_list (parser
);
30021 /* Parse an Objective-C superclass or category. */
30024 cp_parser_objc_superclass_or_category (cp_parser
*parser
,
30027 tree
*categ
, bool *is_class_extension
)
30029 cp_token
*next
= cp_lexer_peek_token (parser
->lexer
);
30031 *super
= *categ
= NULL_TREE
;
30032 *is_class_extension
= false;
30033 if (next
->type
== CPP_COLON
)
30035 cp_lexer_consume_token (parser
->lexer
); /* Eat ':'. */
30036 *super
= cp_parser_identifier (parser
);
30038 else if (next
->type
== CPP_OPEN_PAREN
)
30040 cp_lexer_consume_token (parser
->lexer
); /* Eat '('. */
30042 /* If there is no category name, and this is an @interface, we
30043 have a class extension. */
30044 if (iface_p
&& cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_PAREN
))
30046 *categ
= NULL_TREE
;
30047 *is_class_extension
= true;
30050 *categ
= cp_parser_identifier (parser
);
30052 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
30056 /* Parse an Objective-C class interface. */
30059 cp_parser_objc_class_interface (cp_parser
* parser
, tree attributes
)
30061 tree name
, super
, categ
, protos
;
30062 bool is_class_extension
;
30064 cp_lexer_consume_token (parser
->lexer
); /* Eat '@interface'. */
30065 name
= cp_parser_identifier (parser
);
30066 if (name
== error_mark_node
)
30068 /* It's hard to recover because even if valid @interface stuff
30069 is to follow, we can't compile it (or validate it) if we
30070 don't even know which class it refers to. Let's assume this
30071 was a stray '@interface' token in the stream and skip it.
30075 cp_parser_objc_superclass_or_category (parser
, true, &super
, &categ
,
30076 &is_class_extension
);
30077 protos
= cp_parser_objc_protocol_refs_opt (parser
);
30079 /* We have either a class or a category on our hands. */
30080 if (categ
|| is_class_extension
)
30081 objc_start_category_interface (name
, categ
, protos
, attributes
);
30084 objc_start_class_interface (name
, super
, protos
, attributes
);
30085 /* Handle instance variable declarations, if any. */
30086 cp_parser_objc_class_ivars (parser
);
30087 objc_continue_interface ();
30090 cp_parser_objc_method_prototype_list (parser
);
30093 /* Parse an Objective-C class implementation. */
30096 cp_parser_objc_class_implementation (cp_parser
* parser
)
30098 tree name
, super
, categ
;
30099 bool is_class_extension
;
30101 cp_lexer_consume_token (parser
->lexer
); /* Eat '@implementation'. */
30102 name
= cp_parser_identifier (parser
);
30103 if (name
== error_mark_node
)
30105 /* It's hard to recover because even if valid @implementation
30106 stuff is to follow, we can't compile it (or validate it) if
30107 we don't even know which class it refers to. Let's assume
30108 this was a stray '@implementation' token in the stream and
30113 cp_parser_objc_superclass_or_category (parser
, false, &super
, &categ
,
30114 &is_class_extension
);
30116 /* We have either a class or a category on our hands. */
30118 objc_start_category_implementation (name
, categ
);
30121 objc_start_class_implementation (name
, super
);
30122 /* Handle instance variable declarations, if any. */
30123 cp_parser_objc_class_ivars (parser
);
30124 objc_continue_implementation ();
30127 cp_parser_objc_method_definition_list (parser
);
30130 /* Consume the @end token and finish off the implementation. */
30133 cp_parser_objc_end_implementation (cp_parser
* parser
)
30135 cp_lexer_consume_token (parser
->lexer
); /* Eat '@end'. */
30136 objc_finish_implementation ();
30139 /* Parse an Objective-C declaration. */
30142 cp_parser_objc_declaration (cp_parser
* parser
, tree attributes
)
30144 /* Try to figure out what kind of declaration is present. */
30145 cp_token
*kwd
= cp_lexer_peek_token (parser
->lexer
);
30148 switch (kwd
->keyword
)
30153 error_at (kwd
->location
, "attributes may not be specified before"
30154 " the %<@%D%> Objective-C++ keyword",
30158 case RID_AT_IMPLEMENTATION
:
30159 warning_at (kwd
->location
, OPT_Wattributes
,
30160 "prefix attributes are ignored before %<@%D%>",
30167 switch (kwd
->keyword
)
30170 cp_parser_objc_alias_declaration (parser
);
30173 cp_parser_objc_class_declaration (parser
);
30175 case RID_AT_PROTOCOL
:
30176 cp_parser_objc_protocol_declaration (parser
, attributes
);
30178 case RID_AT_INTERFACE
:
30179 cp_parser_objc_class_interface (parser
, attributes
);
30181 case RID_AT_IMPLEMENTATION
:
30182 cp_parser_objc_class_implementation (parser
);
30185 cp_parser_objc_end_implementation (parser
);
30188 error_at (kwd
->location
, "misplaced %<@%D%> Objective-C++ construct",
30190 cp_parser_skip_to_end_of_block_or_statement (parser
);
30194 /* Parse an Objective-C try-catch-finally statement.
30196 objc-try-catch-finally-stmt:
30197 @try compound-statement objc-catch-clause-seq [opt]
30198 objc-finally-clause [opt]
30200 objc-catch-clause-seq:
30201 objc-catch-clause objc-catch-clause-seq [opt]
30204 @catch ( objc-exception-declaration ) compound-statement
30206 objc-finally-clause:
30207 @finally compound-statement
30209 objc-exception-declaration:
30210 parameter-declaration
30213 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
30217 PS: This function is identical to c_parser_objc_try_catch_finally_statement
30218 for C. Keep them in sync. */
30221 cp_parser_objc_try_catch_finally_statement (cp_parser
*parser
)
30223 location_t location
;
30226 cp_parser_require_keyword (parser
, RID_AT_TRY
, RT_AT_TRY
);
30227 location
= cp_lexer_peek_token (parser
->lexer
)->location
;
30228 objc_maybe_warn_exceptions (location
);
30229 /* NB: The @try block needs to be wrapped in its own STATEMENT_LIST
30230 node, lest it get absorbed into the surrounding block. */
30231 stmt
= push_stmt_list ();
30232 cp_parser_compound_statement (parser
, NULL
, BCS_NORMAL
, false);
30233 objc_begin_try_stmt (location
, pop_stmt_list (stmt
));
30235 while (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_AT_CATCH
))
30237 cp_parameter_declarator
*parm
;
30238 tree parameter_declaration
= error_mark_node
;
30239 bool seen_open_paren
= false;
30241 cp_lexer_consume_token (parser
->lexer
);
30242 if (cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
30243 seen_open_paren
= true;
30244 if (cp_lexer_next_token_is (parser
->lexer
, CPP_ELLIPSIS
))
30246 /* We have "@catch (...)" (where the '...' are literally
30247 what is in the code). Skip the '...'.
30248 parameter_declaration is set to NULL_TREE, and
30249 objc_being_catch_clauses() knows that that means
30251 cp_lexer_consume_token (parser
->lexer
);
30252 parameter_declaration
= NULL_TREE
;
30256 /* We have "@catch (NSException *exception)" or something
30257 like that. Parse the parameter declaration. */
30258 parm
= cp_parser_parameter_declaration (parser
, false, NULL
);
30260 parameter_declaration
= error_mark_node
;
30262 parameter_declaration
= grokdeclarator (parm
->declarator
,
30263 &parm
->decl_specifiers
,
30264 PARM
, /*initialized=*/0,
30265 /*attrlist=*/NULL
);
30267 if (seen_open_paren
)
30268 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
30271 /* If there was no open parenthesis, we are recovering from
30272 an error, and we are trying to figure out what mistake
30273 the user has made. */
30275 /* If there is an immediate closing parenthesis, the user
30276 probably forgot the opening one (ie, they typed "@catch
30277 NSException *e)". Parse the closing parenthesis and keep
30279 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_PAREN
))
30280 cp_lexer_consume_token (parser
->lexer
);
30282 /* If these is no immediate closing parenthesis, the user
30283 probably doesn't know that parenthesis are required at
30284 all (ie, they typed "@catch NSException *e"). So, just
30285 forget about the closing parenthesis and keep going. */
30287 objc_begin_catch_clause (parameter_declaration
);
30288 cp_parser_compound_statement (parser
, NULL
, BCS_NORMAL
, false);
30289 objc_finish_catch_clause ();
30291 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_AT_FINALLY
))
30293 cp_lexer_consume_token (parser
->lexer
);
30294 location
= cp_lexer_peek_token (parser
->lexer
)->location
;
30295 /* NB: The @finally block needs to be wrapped in its own STATEMENT_LIST
30296 node, lest it get absorbed into the surrounding block. */
30297 stmt
= push_stmt_list ();
30298 cp_parser_compound_statement (parser
, NULL
, BCS_NORMAL
, false);
30299 objc_build_finally_clause (location
, pop_stmt_list (stmt
));
30302 return objc_finish_try_stmt ();
30305 /* Parse an Objective-C synchronized statement.
30307 objc-synchronized-stmt:
30308 @synchronized ( expression ) compound-statement
30310 Returns NULL_TREE. */
30313 cp_parser_objc_synchronized_statement (cp_parser
*parser
)
30315 location_t location
;
30318 cp_parser_require_keyword (parser
, RID_AT_SYNCHRONIZED
, RT_AT_SYNCHRONIZED
);
30320 location
= cp_lexer_peek_token (parser
->lexer
)->location
;
30321 objc_maybe_warn_exceptions (location
);
30322 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
30323 lock
= cp_parser_expression (parser
);
30324 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
30326 /* NB: The @synchronized block needs to be wrapped in its own STATEMENT_LIST
30327 node, lest it get absorbed into the surrounding block. */
30328 stmt
= push_stmt_list ();
30329 cp_parser_compound_statement (parser
, NULL
, BCS_NORMAL
, false);
30331 return objc_build_synchronized (location
, lock
, pop_stmt_list (stmt
));
30334 /* Parse an Objective-C throw statement.
30337 @throw assignment-expression [opt] ;
30339 Returns a constructed '@throw' statement. */
30342 cp_parser_objc_throw_statement (cp_parser
*parser
)
30344 tree expr
= NULL_TREE
;
30345 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
30347 cp_parser_require_keyword (parser
, RID_AT_THROW
, RT_AT_THROW
);
30349 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
30350 expr
= cp_parser_expression (parser
);
30352 cp_parser_consume_semicolon_at_end_of_statement (parser
);
30354 return objc_build_throw_stmt (loc
, expr
);
30357 /* Parse an Objective-C statement. */
30360 cp_parser_objc_statement (cp_parser
* parser
)
30362 /* Try to figure out what kind of declaration is present. */
30363 cp_token
*kwd
= cp_lexer_peek_token (parser
->lexer
);
30365 switch (kwd
->keyword
)
30368 return cp_parser_objc_try_catch_finally_statement (parser
);
30369 case RID_AT_SYNCHRONIZED
:
30370 return cp_parser_objc_synchronized_statement (parser
);
30372 return cp_parser_objc_throw_statement (parser
);
30374 error_at (kwd
->location
, "misplaced %<@%D%> Objective-C++ construct",
30376 cp_parser_skip_to_end_of_block_or_statement (parser
);
30379 return error_mark_node
;
30382 /* If we are compiling ObjC++ and we see an __attribute__ we neeed to
30383 look ahead to see if an objc keyword follows the attributes. This
30384 is to detect the use of prefix attributes on ObjC @interface and
30388 cp_parser_objc_valid_prefix_attributes (cp_parser
* parser
, tree
*attrib
)
30390 cp_lexer_save_tokens (parser
->lexer
);
30391 *attrib
= cp_parser_attributes_opt (parser
);
30392 gcc_assert (*attrib
);
30393 if (OBJC_IS_AT_KEYWORD (cp_lexer_peek_token (parser
->lexer
)->keyword
))
30395 cp_lexer_commit_tokens (parser
->lexer
);
30398 cp_lexer_rollback_tokens (parser
->lexer
);
30402 /* This routine is a minimal replacement for
30403 c_parser_struct_declaration () used when parsing the list of
30404 types/names or ObjC++ properties. For example, when parsing the
30407 @property (readonly) int a, b, c;
30409 this function is responsible for parsing "int a, int b, int c" and
30410 returning the declarations as CHAIN of DECLs.
30412 TODO: Share this code with cp_parser_objc_class_ivars. It's very
30413 similar parsing. */
30415 cp_parser_objc_struct_declaration (cp_parser
*parser
)
30417 tree decls
= NULL_TREE
;
30418 cp_decl_specifier_seq declspecs
;
30419 int decl_class_or_enum_p
;
30420 tree prefix_attributes
;
30422 cp_parser_decl_specifier_seq (parser
,
30423 CP_PARSER_FLAGS_NONE
,
30425 &decl_class_or_enum_p
);
30427 if (declspecs
.type
== error_mark_node
)
30428 return error_mark_node
;
30430 /* auto, register, static, extern, mutable. */
30431 if (declspecs
.storage_class
!= sc_none
)
30433 cp_parser_error (parser
, "invalid type for property");
30434 declspecs
.storage_class
= sc_none
;
30437 /* thread_local. */
30438 if (decl_spec_seq_has_spec_p (&declspecs
, ds_thread
))
30440 cp_parser_error (parser
, "invalid type for property");
30441 declspecs
.locations
[ds_thread
] = 0;
30445 if (decl_spec_seq_has_spec_p (&declspecs
, ds_typedef
))
30447 cp_parser_error (parser
, "invalid type for property");
30448 declspecs
.locations
[ds_typedef
] = 0;
30451 prefix_attributes
= declspecs
.attributes
;
30452 declspecs
.attributes
= NULL_TREE
;
30454 /* Keep going until we hit the `;' at the end of the declaration. */
30455 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
30457 tree attributes
, first_attribute
, decl
;
30458 cp_declarator
*declarator
;
30461 /* Parse the declarator. */
30462 declarator
= cp_parser_declarator (parser
, CP_PARSER_DECLARATOR_NAMED
,
30463 NULL
, NULL
, false, false);
30465 /* Look for attributes that apply to the ivar. */
30466 attributes
= cp_parser_attributes_opt (parser
);
30467 /* Remember which attributes are prefix attributes and
30469 first_attribute
= attributes
;
30470 /* Combine the attributes. */
30471 attributes
= chainon (prefix_attributes
, attributes
);
30473 decl
= grokfield (declarator
, &declspecs
,
30474 NULL_TREE
, /*init_const_expr_p=*/false,
30475 NULL_TREE
, attributes
);
30477 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
30478 return error_mark_node
;
30480 /* Reset PREFIX_ATTRIBUTES. */
30481 while (attributes
&& TREE_CHAIN (attributes
) != first_attribute
)
30482 attributes
= TREE_CHAIN (attributes
);
30484 TREE_CHAIN (attributes
) = NULL_TREE
;
30486 DECL_CHAIN (decl
) = decls
;
30489 token
= cp_lexer_peek_token (parser
->lexer
);
30490 if (token
->type
== CPP_COMMA
)
30492 cp_lexer_consume_token (parser
->lexer
); /* Eat ','. */
30501 /* Parse an Objective-C @property declaration. The syntax is:
30503 objc-property-declaration:
30504 '@property' objc-property-attributes[opt] struct-declaration ;
30506 objc-property-attributes:
30507 '(' objc-property-attribute-list ')'
30509 objc-property-attribute-list:
30510 objc-property-attribute
30511 objc-property-attribute-list, objc-property-attribute
30513 objc-property-attribute
30514 'getter' = identifier
30515 'setter' = identifier
30524 @property NSString *name;
30525 @property (readonly) id object;
30526 @property (retain, nonatomic, getter=getTheName) id name;
30527 @property int a, b, c;
30529 PS: This function is identical to
30530 c_parser_objc_at_property_declaration for C. Keep them in sync. */
30532 cp_parser_objc_at_property_declaration (cp_parser
*parser
)
30534 /* The following variables hold the attributes of the properties as
30535 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
30536 seen. When we see an attribute, we set them to 'true' (if they
30537 are boolean properties) or to the identifier (if they have an
30538 argument, ie, for getter and setter). Note that here we only
30539 parse the list of attributes, check the syntax and accumulate the
30540 attributes that we find. objc_add_property_declaration() will
30541 then process the information. */
30542 bool property_assign
= false;
30543 bool property_copy
= false;
30544 tree property_getter_ident
= NULL_TREE
;
30545 bool property_nonatomic
= false;
30546 bool property_readonly
= false;
30547 bool property_readwrite
= false;
30548 bool property_retain
= false;
30549 tree property_setter_ident
= NULL_TREE
;
30551 /* 'properties' is the list of properties that we read. Usually a
30552 single one, but maybe more (eg, in "@property int a, b, c;" there
30557 loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
30559 cp_lexer_consume_token (parser
->lexer
); /* Eat '@property'. */
30561 /* Parse the optional attribute list... */
30562 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
30565 cp_lexer_consume_token (parser
->lexer
);
30569 bool syntax_error
= false;
30570 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
30573 if (token
->type
!= CPP_NAME
)
30575 cp_parser_error (parser
, "expected identifier");
30578 keyword
= C_RID_CODE (token
->u
.value
);
30579 cp_lexer_consume_token (parser
->lexer
);
30582 case RID_ASSIGN
: property_assign
= true; break;
30583 case RID_COPY
: property_copy
= true; break;
30584 case RID_NONATOMIC
: property_nonatomic
= true; break;
30585 case RID_READONLY
: property_readonly
= true; break;
30586 case RID_READWRITE
: property_readwrite
= true; break;
30587 case RID_RETAIN
: property_retain
= true; break;
30591 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_EQ
))
30593 if (keyword
== RID_GETTER
)
30594 cp_parser_error (parser
,
30595 "missing %<=%> (after %<getter%> attribute)");
30597 cp_parser_error (parser
,
30598 "missing %<=%> (after %<setter%> attribute)");
30599 syntax_error
= true;
30602 cp_lexer_consume_token (parser
->lexer
); /* eat the = */
30603 if (!cp_parser_objc_selector_p (cp_lexer_peek_token (parser
->lexer
)->type
))
30605 cp_parser_error (parser
, "expected identifier");
30606 syntax_error
= true;
30609 if (keyword
== RID_SETTER
)
30611 if (property_setter_ident
!= NULL_TREE
)
30613 cp_parser_error (parser
, "the %<setter%> attribute may only be specified once");
30614 cp_lexer_consume_token (parser
->lexer
);
30617 property_setter_ident
= cp_parser_objc_selector (parser
);
30618 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COLON
))
30619 cp_parser_error (parser
, "setter name must terminate with %<:%>");
30621 cp_lexer_consume_token (parser
->lexer
);
30625 if (property_getter_ident
!= NULL_TREE
)
30627 cp_parser_error (parser
, "the %<getter%> attribute may only be specified once");
30628 cp_lexer_consume_token (parser
->lexer
);
30631 property_getter_ident
= cp_parser_objc_selector (parser
);
30635 cp_parser_error (parser
, "unknown property attribute");
30636 syntax_error
= true;
30643 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
30644 cp_lexer_consume_token (parser
->lexer
);
30649 /* FIXME: "@property (setter, assign);" will generate a spurious
30650 "error: expected ‘)’ before ‘,’ token". This is because
30651 cp_parser_require, unlike the C counterpart, will produce an
30652 error even if we are in error recovery. */
30653 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
30655 cp_parser_skip_to_closing_parenthesis (parser
,
30656 /*recovering=*/true,
30657 /*or_comma=*/false,
30658 /*consume_paren=*/true);
30662 /* ... and the property declaration(s). */
30663 properties
= cp_parser_objc_struct_declaration (parser
);
30665 if (properties
== error_mark_node
)
30667 cp_parser_skip_to_end_of_statement (parser
);
30668 /* If the next token is now a `;', consume it. */
30669 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
30670 cp_lexer_consume_token (parser
->lexer
);
30674 if (properties
== NULL_TREE
)
30675 cp_parser_error (parser
, "expected identifier");
30678 /* Comma-separated properties are chained together in
30679 reverse order; add them one by one. */
30680 properties
= nreverse (properties
);
30682 for (; properties
; properties
= TREE_CHAIN (properties
))
30683 objc_add_property_declaration (loc
, copy_node (properties
),
30684 property_readonly
, property_readwrite
,
30685 property_assign
, property_retain
,
30686 property_copy
, property_nonatomic
,
30687 property_getter_ident
, property_setter_ident
);
30690 cp_parser_consume_semicolon_at_end_of_statement (parser
);
30693 /* Parse an Objective-C++ @synthesize declaration. The syntax is:
30695 objc-synthesize-declaration:
30696 @synthesize objc-synthesize-identifier-list ;
30698 objc-synthesize-identifier-list:
30699 objc-synthesize-identifier
30700 objc-synthesize-identifier-list, objc-synthesize-identifier
30702 objc-synthesize-identifier
30704 identifier = identifier
30707 @synthesize MyProperty;
30708 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
30710 PS: This function is identical to c_parser_objc_at_synthesize_declaration
30711 for C. Keep them in sync.
30714 cp_parser_objc_at_synthesize_declaration (cp_parser
*parser
)
30716 tree list
= NULL_TREE
;
30718 loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
30720 cp_lexer_consume_token (parser
->lexer
); /* Eat '@synthesize'. */
30723 tree property
, ivar
;
30724 property
= cp_parser_identifier (parser
);
30725 if (property
== error_mark_node
)
30727 cp_parser_consume_semicolon_at_end_of_statement (parser
);
30730 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EQ
))
30732 cp_lexer_consume_token (parser
->lexer
);
30733 ivar
= cp_parser_identifier (parser
);
30734 if (ivar
== error_mark_node
)
30736 cp_parser_consume_semicolon_at_end_of_statement (parser
);
30742 list
= chainon (list
, build_tree_list (ivar
, property
));
30743 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
30744 cp_lexer_consume_token (parser
->lexer
);
30748 cp_parser_consume_semicolon_at_end_of_statement (parser
);
30749 objc_add_synthesize_declaration (loc
, list
);
30752 /* Parse an Objective-C++ @dynamic declaration. The syntax is:
30754 objc-dynamic-declaration:
30755 @dynamic identifier-list ;
30758 @dynamic MyProperty;
30759 @dynamic MyProperty, AnotherProperty;
30761 PS: This function is identical to c_parser_objc_at_dynamic_declaration
30762 for C. Keep them in sync.
30765 cp_parser_objc_at_dynamic_declaration (cp_parser
*parser
)
30767 tree list
= NULL_TREE
;
30769 loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
30771 cp_lexer_consume_token (parser
->lexer
); /* Eat '@dynamic'. */
30775 property
= cp_parser_identifier (parser
);
30776 if (property
== error_mark_node
)
30778 cp_parser_consume_semicolon_at_end_of_statement (parser
);
30781 list
= chainon (list
, build_tree_list (NULL
, property
));
30782 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
30783 cp_lexer_consume_token (parser
->lexer
);
30787 cp_parser_consume_semicolon_at_end_of_statement (parser
);
30788 objc_add_dynamic_declaration (loc
, list
);
30792 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
30794 /* Returns name of the next clause.
30795 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
30796 the token is not consumed. Otherwise appropriate pragma_omp_clause is
30797 returned and the token is consumed. */
30799 static pragma_omp_clause
30800 cp_parser_omp_clause_name (cp_parser
*parser
)
30802 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
30804 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_AUTO
))
30805 result
= PRAGMA_OACC_CLAUSE_AUTO
;
30806 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_IF
))
30807 result
= PRAGMA_OMP_CLAUSE_IF
;
30808 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_DEFAULT
))
30809 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
30810 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_DELETE
))
30811 result
= PRAGMA_OACC_CLAUSE_DELETE
;
30812 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_PRIVATE
))
30813 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
30814 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_FOR
))
30815 result
= PRAGMA_OMP_CLAUSE_FOR
;
30816 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
30818 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
30819 const char *p
= IDENTIFIER_POINTER (id
);
30824 if (!strcmp ("aligned", p
))
30825 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
30826 else if (!strcmp ("async", p
))
30827 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
30830 if (!strcmp ("collapse", p
))
30831 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
30832 else if (!strcmp ("copy", p
))
30833 result
= PRAGMA_OACC_CLAUSE_COPY
;
30834 else if (!strcmp ("copyin", p
))
30835 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
30836 else if (!strcmp ("copyout", p
))
30837 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
30838 else if (!strcmp ("copyprivate", p
))
30839 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
30840 else if (!strcmp ("create", p
))
30841 result
= PRAGMA_OACC_CLAUSE_CREATE
;
30844 if (!strcmp ("defaultmap", p
))
30845 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
30846 else if (!strcmp ("depend", p
))
30847 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
30848 else if (!strcmp ("device", p
))
30849 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
30850 else if (!strcmp ("deviceptr", p
))
30851 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
30852 else if (!strcmp ("device_resident", p
))
30853 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
30854 else if (!strcmp ("dist_schedule", p
))
30855 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
30858 if (!strcmp ("final", p
))
30859 result
= PRAGMA_OMP_CLAUSE_FINAL
;
30860 else if (!strcmp ("firstprivate", p
))
30861 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
30862 else if (!strcmp ("from", p
))
30863 result
= PRAGMA_OMP_CLAUSE_FROM
;
30866 if (!strcmp ("gang", p
))
30867 result
= PRAGMA_OACC_CLAUSE_GANG
;
30868 else if (!strcmp ("grainsize", p
))
30869 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
30872 if (!strcmp ("hint", p
))
30873 result
= PRAGMA_OMP_CLAUSE_HINT
;
30874 else if (!strcmp ("host", p
))
30875 result
= PRAGMA_OACC_CLAUSE_HOST
;
30878 if (!strcmp ("inbranch", p
))
30879 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
30880 else if (!strcmp ("independent", p
))
30881 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
30882 else if (!strcmp ("is_device_ptr", p
))
30883 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
30886 if (!strcmp ("lastprivate", p
))
30887 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
30888 else if (!strcmp ("linear", p
))
30889 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
30890 else if (!strcmp ("link", p
))
30891 result
= PRAGMA_OMP_CLAUSE_LINK
;
30894 if (!strcmp ("map", p
))
30895 result
= PRAGMA_OMP_CLAUSE_MAP
;
30896 else if (!strcmp ("mergeable", p
))
30897 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
30898 else if (flag_cilkplus
&& !strcmp ("mask", p
))
30899 result
= PRAGMA_CILK_CLAUSE_MASK
;
30902 if (!strcmp ("nogroup", p
))
30903 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
30904 else if (!strcmp ("notinbranch", p
))
30905 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
30906 else if (!strcmp ("nowait", p
))
30907 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
30908 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
30909 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
30910 else if (!strcmp ("num_gangs", p
))
30911 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
30912 else if (!strcmp ("num_tasks", p
))
30913 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
30914 else if (!strcmp ("num_teams", p
))
30915 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
30916 else if (!strcmp ("num_threads", p
))
30917 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
30918 else if (!strcmp ("num_workers", p
))
30919 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
30922 if (!strcmp ("ordered", p
))
30923 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
30926 if (!strcmp ("parallel", p
))
30927 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
30928 else if (!strcmp ("present", p
))
30929 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
30930 else if (!strcmp ("present_or_copy", p
)
30931 || !strcmp ("pcopy", p
))
30932 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
30933 else if (!strcmp ("present_or_copyin", p
)
30934 || !strcmp ("pcopyin", p
))
30935 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
30936 else if (!strcmp ("present_or_copyout", p
)
30937 || !strcmp ("pcopyout", p
))
30938 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
30939 else if (!strcmp ("present_or_create", p
)
30940 || !strcmp ("pcreate", p
))
30941 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
30942 else if (!strcmp ("priority", p
))
30943 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
30944 else if (!strcmp ("proc_bind", p
))
30945 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
30948 if (!strcmp ("reduction", p
))
30949 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
30952 if (!strcmp ("safelen", p
))
30953 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
30954 else if (!strcmp ("schedule", p
))
30955 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
30956 else if (!strcmp ("sections", p
))
30957 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
30958 else if (!strcmp ("self", p
))
30959 result
= PRAGMA_OACC_CLAUSE_SELF
;
30960 else if (!strcmp ("seq", p
))
30961 result
= PRAGMA_OACC_CLAUSE_SEQ
;
30962 else if (!strcmp ("shared", p
))
30963 result
= PRAGMA_OMP_CLAUSE_SHARED
;
30964 else if (!strcmp ("simd", p
))
30965 result
= PRAGMA_OMP_CLAUSE_SIMD
;
30966 else if (!strcmp ("simdlen", p
))
30967 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
30970 if (!strcmp ("taskgroup", p
))
30971 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
30972 else if (!strcmp ("thread_limit", p
))
30973 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
30974 else if (!strcmp ("threads", p
))
30975 result
= PRAGMA_OMP_CLAUSE_THREADS
;
30976 else if (!strcmp ("tile", p
))
30977 result
= PRAGMA_OACC_CLAUSE_TILE
;
30978 else if (!strcmp ("to", p
))
30979 result
= PRAGMA_OMP_CLAUSE_TO
;
30982 if (!strcmp ("uniform", p
))
30983 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
30984 else if (!strcmp ("untied", p
))
30985 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
30986 else if (!strcmp ("use_device", p
))
30987 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
30988 else if (!strcmp ("use_device_ptr", p
))
30989 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
30992 if (!strcmp ("vector", p
))
30993 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
30994 else if (!strcmp ("vector_length", p
))
30995 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
30996 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
30997 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
31000 if (!strcmp ("wait", p
))
31001 result
= PRAGMA_OACC_CLAUSE_WAIT
;
31002 else if (!strcmp ("worker", p
))
31003 result
= PRAGMA_OACC_CLAUSE_WORKER
;
31008 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
31009 cp_lexer_consume_token (parser
->lexer
);
31014 /* Validate that a clause of the given type does not already exist. */
31017 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
31018 const char *name
, location_t location
)
31022 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
31023 if (OMP_CLAUSE_CODE (c
) == code
)
31025 error_at (location
, "too many %qs clauses", name
);
31033 variable-list , identifier
31035 In addition, we match a closing parenthesis (or, if COLON is non-NULL,
31036 colon). An opening parenthesis will have been consumed by the caller.
31038 If KIND is nonzero, create the appropriate node and install the decl
31039 in OMP_CLAUSE_DECL and add the node to the head of the list.
31041 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
31042 return the list created.
31044 COLON can be NULL if only closing parenthesis should end the list,
31045 or pointer to bool which will receive false if the list is terminated
31046 by closing parenthesis or true if the list is terminated by colon. */
31049 cp_parser_omp_var_list_no_open (cp_parser
*parser
, enum omp_clause_code kind
,
31050 tree list
, bool *colon
)
31053 bool saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
31056 parser
->colon_corrects_to_scope_p
= false;
31063 token
= cp_lexer_peek_token (parser
->lexer
);
31065 && current_class_ptr
31066 && cp_parser_is_keyword (token
, RID_THIS
))
31068 decl
= finish_this_expr ();
31069 if (TREE_CODE (decl
) == NON_LVALUE_EXPR
31070 || CONVERT_EXPR_P (decl
))
31071 decl
= TREE_OPERAND (decl
, 0);
31072 cp_lexer_consume_token (parser
->lexer
);
31076 name
= cp_parser_id_expression (parser
, /*template_p=*/false,
31077 /*check_dependency_p=*/true,
31078 /*template_p=*/NULL
,
31079 /*declarator_p=*/false,
31080 /*optional_p=*/false);
31081 if (name
== error_mark_node
)
31084 decl
= cp_parser_lookup_name_simple (parser
, name
, token
->location
);
31085 if (decl
== error_mark_node
)
31086 cp_parser_name_lookup_error (parser
, name
, decl
, NLE_NULL
,
31089 if (decl
== error_mark_node
)
31091 else if (kind
!= 0)
31095 case OMP_CLAUSE__CACHE_
:
31096 /* The OpenACC cache directive explicitly only allows "array
31097 elements or subarrays". */
31098 if (cp_lexer_peek_token (parser
->lexer
)->type
!= CPP_OPEN_SQUARE
)
31100 error_at (token
->location
, "expected %<[%>");
31101 decl
= error_mark_node
;
31105 case OMP_CLAUSE_MAP
:
31106 case OMP_CLAUSE_FROM
:
31107 case OMP_CLAUSE_TO
:
31108 while (cp_lexer_next_token_is (parser
->lexer
, CPP_DOT
))
31111 = cp_lexer_peek_token (parser
->lexer
)->location
;
31112 cp_id_kind idk
= CP_ID_KIND_NONE
;
31113 cp_lexer_consume_token (parser
->lexer
);
31114 decl
= convert_from_reference (decl
);
31116 = cp_parser_postfix_dot_deref_expression (parser
, CPP_DOT
,
31121 case OMP_CLAUSE_DEPEND
:
31122 case OMP_CLAUSE_REDUCTION
:
31123 while (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_SQUARE
))
31125 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
31127 parser
->colon_corrects_to_scope_p
= false;
31128 cp_lexer_consume_token (parser
->lexer
);
31129 if (!cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
31130 low_bound
= cp_parser_expression (parser
);
31132 parser
->colon_corrects_to_scope_p
31133 = saved_colon_corrects_to_scope_p
;
31134 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_SQUARE
))
31135 length
= integer_one_node
;
31138 /* Look for `:'. */
31139 if (!cp_parser_require (parser
, CPP_COLON
, RT_COLON
))
31141 if (!cp_lexer_next_token_is (parser
->lexer
,
31143 length
= cp_parser_expression (parser
);
31145 /* Look for the closing `]'. */
31146 if (!cp_parser_require (parser
, CPP_CLOSE_SQUARE
,
31150 decl
= tree_cons (low_bound
, length
, decl
);
31157 tree u
= build_omp_clause (token
->location
, kind
);
31158 OMP_CLAUSE_DECL (u
) = decl
;
31159 OMP_CLAUSE_CHAIN (u
) = list
;
31163 list
= tree_cons (decl
, NULL_TREE
, list
);
31166 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
31168 cp_lexer_consume_token (parser
->lexer
);
31172 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
31174 if (colon
!= NULL
&& cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
))
31177 cp_parser_require (parser
, CPP_COLON
, RT_COLON
);
31181 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31185 /* Try to resync to an unnested comma. Copied from
31186 cp_parser_parenthesized_expression_list. */
31189 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
31190 ending
= cp_parser_skip_to_closing_parenthesis (parser
,
31191 /*recovering=*/true,
31193 /*consume_paren=*/true);
31201 /* Similarly, but expect leading and trailing parenthesis. This is a very
31202 common case for omp clauses. */
31205 cp_parser_omp_var_list (cp_parser
*parser
, enum omp_clause_code kind
, tree list
)
31207 if (cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31208 return cp_parser_omp_var_list_no_open (parser
, kind
, list
, NULL
);
31213 copy ( variable-list )
31214 copyin ( variable-list )
31215 copyout ( variable-list )
31216 create ( variable-list )
31217 delete ( variable-list )
31218 present ( variable-list )
31219 present_or_copy ( variable-list )
31220 pcopy ( variable-list )
31221 present_or_copyin ( variable-list )
31222 pcopyin ( variable-list )
31223 present_or_copyout ( variable-list )
31224 pcopyout ( variable-list )
31225 present_or_create ( variable-list )
31226 pcreate ( variable-list ) */
31229 cp_parser_oacc_data_clause (cp_parser
*parser
, pragma_omp_clause c_kind
,
31232 enum gomp_map_kind kind
;
31235 case PRAGMA_OACC_CLAUSE_COPY
:
31236 kind
= GOMP_MAP_FORCE_TOFROM
;
31238 case PRAGMA_OACC_CLAUSE_COPYIN
:
31239 kind
= GOMP_MAP_FORCE_TO
;
31241 case PRAGMA_OACC_CLAUSE_COPYOUT
:
31242 kind
= GOMP_MAP_FORCE_FROM
;
31244 case PRAGMA_OACC_CLAUSE_CREATE
:
31245 kind
= GOMP_MAP_FORCE_ALLOC
;
31247 case PRAGMA_OACC_CLAUSE_DELETE
:
31248 kind
= GOMP_MAP_DELETE
;
31250 case PRAGMA_OACC_CLAUSE_DEVICE
:
31251 kind
= GOMP_MAP_FORCE_TO
;
31253 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
31254 kind
= GOMP_MAP_DEVICE_RESIDENT
;
31256 case PRAGMA_OACC_CLAUSE_HOST
:
31257 case PRAGMA_OACC_CLAUSE_SELF
:
31258 kind
= GOMP_MAP_FORCE_FROM
;
31260 case PRAGMA_OACC_CLAUSE_LINK
:
31261 kind
= GOMP_MAP_LINK
;
31263 case PRAGMA_OACC_CLAUSE_PRESENT
:
31264 kind
= GOMP_MAP_FORCE_PRESENT
;
31266 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
31267 kind
= GOMP_MAP_TOFROM
;
31269 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
31270 kind
= GOMP_MAP_TO
;
31272 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
31273 kind
= GOMP_MAP_FROM
;
31275 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
31276 kind
= GOMP_MAP_ALLOC
;
31279 gcc_unreachable ();
31282 nl
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_MAP
, list
);
31284 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
31285 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
31291 deviceptr ( variable-list ) */
31294 cp_parser_oacc_data_clause_deviceptr (cp_parser
*parser
, tree list
)
31296 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
31299 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
31300 cp_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
31301 variable-list must only allow for pointer variables. */
31302 vars
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_ERROR
, NULL
);
31303 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
31305 tree v
= TREE_PURPOSE (t
);
31306 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
31307 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
31308 OMP_CLAUSE_DECL (u
) = v
;
31309 OMP_CLAUSE_CHAIN (u
) = list
;
31323 cp_parser_oacc_simple_clause (cp_parser
* /* parser */,
31324 enum omp_clause_code code
,
31325 tree list
, location_t location
)
31327 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
], location
);
31328 tree c
= build_omp_clause (location
, code
);
31329 OMP_CLAUSE_CHAIN (c
) = list
;
31334 num_gangs ( expression )
31335 num_workers ( expression )
31336 vector_length ( expression ) */
31339 cp_parser_oacc_single_int_clause (cp_parser
*parser
, omp_clause_code code
,
31340 const char *str
, tree list
)
31342 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
31344 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31347 tree t
= cp_parser_assignment_expression (parser
, NULL
, false, false);
31349 if (t
== error_mark_node
31350 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31352 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
31353 /*or_comma=*/false,
31354 /*consume_paren=*/true);
31358 check_no_duplicate_clause (list
, code
, str
, loc
);
31360 tree c
= build_omp_clause (loc
, code
);
31361 OMP_CLAUSE_OPERAND (c
, 0) = t
;
31362 OMP_CLAUSE_CHAIN (c
) = list
;
31368 gang [( gang-arg-list )]
31369 worker [( [num:] int-expr )]
31370 vector [( [length:] int-expr )]
31372 where gang-arg is one of:
31377 and size-expr may be:
31384 cp_parser_oacc_shape_clause (cp_parser
*parser
, omp_clause_code kind
,
31385 const char *str
, tree list
)
31387 const char *id
= "num";
31388 cp_lexer
*lexer
= parser
->lexer
;
31389 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
31390 location_t loc
= cp_lexer_peek_token (lexer
)->location
;
31392 if (kind
== OMP_CLAUSE_VECTOR
)
31395 if (cp_lexer_next_token_is (lexer
, CPP_OPEN_PAREN
))
31397 cp_lexer_consume_token (lexer
);
31401 cp_token
*next
= cp_lexer_peek_token (lexer
);
31404 /* Gang static argument. */
31405 if (kind
== OMP_CLAUSE_GANG
31406 && cp_lexer_next_token_is_keyword (lexer
, RID_STATIC
))
31408 cp_lexer_consume_token (lexer
);
31410 if (!cp_parser_require (parser
, CPP_COLON
, RT_COLON
))
31411 goto cleanup_error
;
31414 if (ops
[idx
] != NULL
)
31416 cp_parser_error (parser
, "too many %<static%> arguments");
31417 goto cleanup_error
;
31420 /* Check for the '*' argument. */
31421 if (cp_lexer_next_token_is (lexer
, CPP_MULT
)
31422 && (cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_COMMA
)
31423 || cp_lexer_nth_token_is (parser
->lexer
, 2,
31426 cp_lexer_consume_token (lexer
);
31427 ops
[idx
] = integer_minus_one_node
;
31429 if (cp_lexer_next_token_is (lexer
, CPP_COMMA
))
31431 cp_lexer_consume_token (lexer
);
31437 /* Worker num: argument and vector length: arguments. */
31438 else if (cp_lexer_next_token_is (lexer
, CPP_NAME
)
31439 && id_equal (next
->u
.value
, id
)
31440 && cp_lexer_nth_token_is (lexer
, 2, CPP_COLON
))
31442 cp_lexer_consume_token (lexer
); /* id */
31443 cp_lexer_consume_token (lexer
); /* ':' */
31446 /* Now collect the actual argument. */
31447 if (ops
[idx
] != NULL_TREE
)
31449 cp_parser_error (parser
, "unexpected argument");
31450 goto cleanup_error
;
31453 tree expr
= cp_parser_assignment_expression (parser
, NULL
, false,
31455 if (expr
== error_mark_node
)
31456 goto cleanup_error
;
31458 mark_exp_read (expr
);
31461 if (kind
== OMP_CLAUSE_GANG
31462 && cp_lexer_next_token_is (lexer
, CPP_COMMA
))
31464 cp_lexer_consume_token (lexer
);
31471 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31472 goto cleanup_error
;
31475 check_no_duplicate_clause (list
, kind
, str
, loc
);
31477 c
= build_omp_clause (loc
, kind
);
31480 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
31482 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
31483 OMP_CLAUSE_CHAIN (c
) = list
;
31488 cp_parser_skip_to_closing_parenthesis (parser
, false, false, true);
31493 tile ( size-expr-list ) */
31496 cp_parser_oacc_clause_tile (cp_parser
*parser
, location_t clause_loc
, tree list
)
31498 tree c
, expr
= error_mark_node
;
31499 tree tile
= NULL_TREE
;
31501 /* Collapse and tile are mutually exclusive. (The spec doesn't say
31502 so, but the spec authors never considered such a case and have
31503 differing opinions on what it might mean, including 'not
31505 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile", clause_loc
);
31506 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse",
31509 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31514 if (tile
&& !cp_parser_require (parser
, CPP_COMMA
, RT_COMMA
))
31517 if (cp_lexer_next_token_is (parser
->lexer
, CPP_MULT
)
31518 && (cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_COMMA
)
31519 || cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_CLOSE_PAREN
)))
31521 cp_lexer_consume_token (parser
->lexer
);
31522 expr
= integer_zero_node
;
31525 expr
= cp_parser_constant_expression (parser
);
31527 tile
= tree_cons (NULL_TREE
, expr
, tile
);
31529 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_PAREN
));
31531 /* Consume the trailing ')'. */
31532 cp_lexer_consume_token (parser
->lexer
);
31534 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_TILE
);
31535 tile
= nreverse (tile
);
31536 OMP_CLAUSE_TILE_LIST (c
) = tile
;
31537 OMP_CLAUSE_CHAIN (c
) = list
;
31542 Parse wait clause or directive parameters. */
31545 cp_parser_oacc_wait_list (cp_parser
*parser
, location_t clause_loc
, tree list
)
31547 vec
<tree
, va_gc
> *args
;
31550 args
= cp_parser_parenthesized_expression_list (parser
, non_attr
,
31552 /*allow_expansion_p=*/true,
31553 /*non_constant_p=*/NULL
);
31555 if (args
== NULL
|| args
->length () == 0)
31557 cp_parser_error (parser
, "expected integer expression before ')'");
31559 release_tree_vector (args
);
31563 args_tree
= build_tree_list_vec (args
);
31565 release_tree_vector (args
);
31567 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
31569 tree targ
= TREE_VALUE (t
);
31571 if (targ
!= error_mark_node
)
31573 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
31574 error ("%<wait%> expression must be integral");
31577 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
31579 mark_rvalue_use (targ
);
31580 OMP_CLAUSE_DECL (c
) = targ
;
31581 OMP_CLAUSE_CHAIN (c
) = list
;
31591 wait ( int-expr-list ) */
31594 cp_parser_oacc_clause_wait (cp_parser
*parser
, tree list
)
31596 location_t location
= cp_lexer_peek_token (parser
->lexer
)->location
;
31598 if (cp_lexer_peek_token (parser
->lexer
)->type
!= CPP_OPEN_PAREN
)
31601 list
= cp_parser_oacc_wait_list (parser
, location
, list
);
31607 collapse ( constant-expression ) */
31610 cp_parser_omp_clause_collapse (cp_parser
*parser
, tree list
, location_t location
)
31616 loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
31617 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31620 num
= cp_parser_constant_expression (parser
);
31622 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31623 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
31624 /*or_comma=*/false,
31625 /*consume_paren=*/true);
31627 if (num
== error_mark_node
)
31629 num
= fold_non_dependent_expr (num
);
31630 if (!tree_fits_shwi_p (num
)
31631 || !INTEGRAL_TYPE_P (TREE_TYPE (num
))
31632 || (n
= tree_to_shwi (num
)) <= 0
31635 error_at (loc
, "collapse argument needs positive constant integer expression");
31639 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse", location
);
31640 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile", location
);
31641 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
31642 OMP_CLAUSE_CHAIN (c
) = list
;
31643 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
31649 default ( none | shared )
31652 default ( none | present ) */
31655 cp_parser_omp_clause_default (cp_parser
*parser
, tree list
,
31656 location_t location
, bool is_oacc
)
31658 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
31661 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31663 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
31665 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
31666 const char *p
= IDENTIFIER_POINTER (id
);
31671 if (strcmp ("none", p
) != 0)
31673 kind
= OMP_CLAUSE_DEFAULT_NONE
;
31677 if (strcmp ("present", p
) != 0 || !is_oacc
)
31679 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
31683 if (strcmp ("shared", p
) != 0 || is_oacc
)
31685 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
31692 cp_lexer_consume_token (parser
->lexer
);
31698 cp_parser_error (parser
, "expected %<none%> or %<present%>");
31700 cp_parser_error (parser
, "expected %<none%> or %<shared%>");
31703 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
31704 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31705 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
31706 /*or_comma=*/false,
31707 /*consume_paren=*/true);
31709 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
31712 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default", location
);
31713 c
= build_omp_clause (location
, OMP_CLAUSE_DEFAULT
);
31714 OMP_CLAUSE_CHAIN (c
) = list
;
31715 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
31721 final ( expression ) */
31724 cp_parser_omp_clause_final (cp_parser
*parser
, tree list
, location_t location
)
31728 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31731 t
= cp_parser_condition (parser
);
31733 if (t
== error_mark_node
31734 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31735 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
31736 /*or_comma=*/false,
31737 /*consume_paren=*/true);
31739 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final", location
);
31741 c
= build_omp_clause (location
, OMP_CLAUSE_FINAL
);
31742 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
31743 OMP_CLAUSE_CHAIN (c
) = list
;
31752 if ( directive-name-modifier : expression )
31754 directive-name-modifier:
31755 parallel | task | taskloop | target data | target | target update
31756 | target enter data | target exit data */
31759 cp_parser_omp_clause_if (cp_parser
*parser
, tree list
, location_t location
,
31763 enum tree_code if_modifier
= ERROR_MARK
;
31765 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31768 if (is_omp
&& cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
31770 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
31771 const char *p
= IDENTIFIER_POINTER (id
);
31774 if (strcmp ("parallel", p
) == 0)
31775 if_modifier
= OMP_PARALLEL
;
31776 else if (strcmp ("task", p
) == 0)
31777 if_modifier
= OMP_TASK
;
31778 else if (strcmp ("taskloop", p
) == 0)
31779 if_modifier
= OMP_TASKLOOP
;
31780 else if (strcmp ("target", p
) == 0)
31782 if_modifier
= OMP_TARGET
;
31783 if (cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_NAME
))
31785 id
= cp_lexer_peek_nth_token (parser
->lexer
, 2)->u
.value
;
31786 p
= IDENTIFIER_POINTER (id
);
31787 if (strcmp ("data", p
) == 0)
31788 if_modifier
= OMP_TARGET_DATA
;
31789 else if (strcmp ("update", p
) == 0)
31790 if_modifier
= OMP_TARGET_UPDATE
;
31791 else if (strcmp ("enter", p
) == 0)
31792 if_modifier
= OMP_TARGET_ENTER_DATA
;
31793 else if (strcmp ("exit", p
) == 0)
31794 if_modifier
= OMP_TARGET_EXIT_DATA
;
31795 if (if_modifier
!= OMP_TARGET
)
31800 = cp_lexer_peek_nth_token (parser
->lexer
, 2)->location
;
31801 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
31803 if_modifier
= ERROR_MARK
;
31805 if (if_modifier
== OMP_TARGET_ENTER_DATA
31806 || if_modifier
== OMP_TARGET_EXIT_DATA
)
31808 if (cp_lexer_nth_token_is (parser
->lexer
, 3, CPP_NAME
))
31810 id
= cp_lexer_peek_nth_token (parser
->lexer
, 3)->u
.value
;
31811 p
= IDENTIFIER_POINTER (id
);
31812 if (strcmp ("data", p
) == 0)
31818 = cp_lexer_peek_nth_token (parser
->lexer
, 3)->location
;
31819 error_at (loc
, "expected %<data%>");
31820 if_modifier
= ERROR_MARK
;
31825 if (if_modifier
!= ERROR_MARK
)
31827 if (cp_lexer_nth_token_is (parser
->lexer
, n
, CPP_COLON
))
31830 cp_lexer_consume_token (parser
->lexer
);
31837 = cp_lexer_peek_nth_token (parser
->lexer
, n
)->location
;
31838 error_at (loc
, "expected %<:%>");
31840 if_modifier
= ERROR_MARK
;
31845 t
= cp_parser_condition (parser
);
31847 if (t
== error_mark_node
31848 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31849 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
31850 /*or_comma=*/false,
31851 /*consume_paren=*/true);
31853 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
31854 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
31856 if (if_modifier
!= ERROR_MARK
31857 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
31859 const char *p
= NULL
;
31860 switch (if_modifier
)
31862 case OMP_PARALLEL
: p
= "parallel"; break;
31863 case OMP_TASK
: p
= "task"; break;
31864 case OMP_TASKLOOP
: p
= "taskloop"; break;
31865 case OMP_TARGET_DATA
: p
= "target data"; break;
31866 case OMP_TARGET
: p
= "target"; break;
31867 case OMP_TARGET_UPDATE
: p
= "target update"; break;
31868 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
31869 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
31870 default: gcc_unreachable ();
31872 error_at (location
, "too many %<if%> clauses with %qs modifier",
31876 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
31879 error_at (location
, "too many %<if%> clauses");
31881 error_at (location
, "too many %<if%> clauses without modifier");
31884 else if (if_modifier
== ERROR_MARK
31885 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
31887 error_at (location
, "if any %<if%> clause has modifier, then all "
31888 "%<if%> clauses have to use modifier");
31893 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
31894 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
31895 OMP_CLAUSE_IF_EXPR (c
) = t
;
31896 OMP_CLAUSE_CHAIN (c
) = list
;
31905 cp_parser_omp_clause_mergeable (cp_parser
* /*parser*/,
31906 tree list
, location_t location
)
31910 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable",
31913 c
= build_omp_clause (location
, OMP_CLAUSE_MERGEABLE
);
31914 OMP_CLAUSE_CHAIN (c
) = list
;
31922 cp_parser_omp_clause_nowait (cp_parser
* /*parser*/,
31923 tree list
, location_t location
)
31927 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait", location
);
31929 c
= build_omp_clause (location
, OMP_CLAUSE_NOWAIT
);
31930 OMP_CLAUSE_CHAIN (c
) = list
;
31935 num_threads ( expression ) */
31938 cp_parser_omp_clause_num_threads (cp_parser
*parser
, tree list
,
31939 location_t location
)
31943 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31946 t
= cp_parser_expression (parser
);
31948 if (t
== error_mark_node
31949 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31950 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
31951 /*or_comma=*/false,
31952 /*consume_paren=*/true);
31954 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
,
31955 "num_threads", location
);
31957 c
= build_omp_clause (location
, OMP_CLAUSE_NUM_THREADS
);
31958 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
31959 OMP_CLAUSE_CHAIN (c
) = list
;
31965 num_tasks ( expression ) */
31968 cp_parser_omp_clause_num_tasks (cp_parser
*parser
, tree list
,
31969 location_t location
)
31973 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
31976 t
= cp_parser_expression (parser
);
31978 if (t
== error_mark_node
31979 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
31980 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
31981 /*or_comma=*/false,
31982 /*consume_paren=*/true);
31984 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
,
31985 "num_tasks", location
);
31987 c
= build_omp_clause (location
, OMP_CLAUSE_NUM_TASKS
);
31988 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
31989 OMP_CLAUSE_CHAIN (c
) = list
;
31995 grainsize ( expression ) */
31998 cp_parser_omp_clause_grainsize (cp_parser
*parser
, tree list
,
31999 location_t location
)
32003 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32006 t
= cp_parser_expression (parser
);
32008 if (t
== error_mark_node
32009 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32010 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32011 /*or_comma=*/false,
32012 /*consume_paren=*/true);
32014 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
,
32015 "grainsize", location
);
32017 c
= build_omp_clause (location
, OMP_CLAUSE_GRAINSIZE
);
32018 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
32019 OMP_CLAUSE_CHAIN (c
) = list
;
32025 priority ( expression ) */
32028 cp_parser_omp_clause_priority (cp_parser
*parser
, tree list
,
32029 location_t location
)
32033 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32036 t
= cp_parser_expression (parser
);
32038 if (t
== error_mark_node
32039 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32040 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32041 /*or_comma=*/false,
32042 /*consume_paren=*/true);
32044 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
,
32045 "priority", location
);
32047 c
= build_omp_clause (location
, OMP_CLAUSE_PRIORITY
);
32048 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
32049 OMP_CLAUSE_CHAIN (c
) = list
;
32055 hint ( expression ) */
32058 cp_parser_omp_clause_hint (cp_parser
*parser
, tree list
,
32059 location_t location
)
32063 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32066 t
= cp_parser_expression (parser
);
32068 if (t
== error_mark_node
32069 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32070 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32071 /*or_comma=*/false,
32072 /*consume_paren=*/true);
32074 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint", location
);
32076 c
= build_omp_clause (location
, OMP_CLAUSE_HINT
);
32077 OMP_CLAUSE_HINT_EXPR (c
) = t
;
32078 OMP_CLAUSE_CHAIN (c
) = list
;
32084 defaultmap ( tofrom : scalar ) */
32087 cp_parser_omp_clause_defaultmap (cp_parser
*parser
, tree list
,
32088 location_t location
)
32093 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32096 if (!cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
32098 cp_parser_error (parser
, "expected %<tofrom%>");
32101 id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32102 p
= IDENTIFIER_POINTER (id
);
32103 if (strcmp (p
, "tofrom") != 0)
32105 cp_parser_error (parser
, "expected %<tofrom%>");
32108 cp_lexer_consume_token (parser
->lexer
);
32109 if (!cp_parser_require (parser
, CPP_COLON
, RT_COLON
))
32112 if (!cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
32114 cp_parser_error (parser
, "expected %<scalar%>");
32117 id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32118 p
= IDENTIFIER_POINTER (id
);
32119 if (strcmp (p
, "scalar") != 0)
32121 cp_parser_error (parser
, "expected %<scalar%>");
32124 cp_lexer_consume_token (parser
->lexer
);
32125 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32128 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap",
32131 c
= build_omp_clause (location
, OMP_CLAUSE_DEFAULTMAP
);
32132 OMP_CLAUSE_CHAIN (c
) = list
;
32136 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32137 /*or_comma=*/false,
32138 /*consume_paren=*/true);
32146 ordered ( constant-expression ) */
32149 cp_parser_omp_clause_ordered (cp_parser
*parser
,
32150 tree list
, location_t location
)
32152 tree c
, num
= NULL_TREE
;
32155 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
,
32156 "ordered", location
);
32158 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
32160 cp_lexer_consume_token (parser
->lexer
);
32162 num
= cp_parser_constant_expression (parser
);
32164 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32165 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32166 /*or_comma=*/false,
32167 /*consume_paren=*/true);
32169 if (num
== error_mark_node
)
32171 num
= fold_non_dependent_expr (num
);
32172 if (!tree_fits_shwi_p (num
)
32173 || !INTEGRAL_TYPE_P (TREE_TYPE (num
))
32174 || (n
= tree_to_shwi (num
)) <= 0
32177 error_at (location
,
32178 "ordered argument needs positive constant integer "
32184 c
= build_omp_clause (location
, OMP_CLAUSE_ORDERED
);
32185 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
32186 OMP_CLAUSE_CHAIN (c
) = list
;
32191 reduction ( reduction-operator : variable-list )
32193 reduction-operator:
32194 One of: + * - & ^ | && ||
32198 reduction-operator:
32199 One of: + * - & ^ | && || min max
32203 reduction-operator:
32204 One of: + * - & ^ | && ||
32208 cp_parser_omp_clause_reduction (cp_parser
*parser
, tree list
)
32210 enum tree_code code
= ERROR_MARK
;
32211 tree nlist
, c
, id
= NULL_TREE
;
32213 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32216 switch (cp_lexer_peek_token (parser
->lexer
)->type
)
32218 case CPP_PLUS
: code
= PLUS_EXPR
; break;
32219 case CPP_MULT
: code
= MULT_EXPR
; break;
32220 case CPP_MINUS
: code
= MINUS_EXPR
; break;
32221 case CPP_AND
: code
= BIT_AND_EXPR
; break;
32222 case CPP_XOR
: code
= BIT_XOR_EXPR
; break;
32223 case CPP_OR
: code
= BIT_IOR_EXPR
; break;
32224 case CPP_AND_AND
: code
= TRUTH_ANDIF_EXPR
; break;
32225 case CPP_OR_OR
: code
= TRUTH_ORIF_EXPR
; break;
32229 if (code
!= ERROR_MARK
)
32230 cp_lexer_consume_token (parser
->lexer
);
32233 bool saved_colon_corrects_to_scope_p
;
32234 saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
32235 parser
->colon_corrects_to_scope_p
= false;
32236 id
= cp_parser_id_expression (parser
, /*template_p=*/false,
32237 /*check_dependency_p=*/true,
32238 /*template_p=*/NULL
,
32239 /*declarator_p=*/false,
32240 /*optional_p=*/false);
32241 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
32242 if (identifier_p (id
))
32244 const char *p
= IDENTIFIER_POINTER (id
);
32246 if (strcmp (p
, "min") == 0)
32248 else if (strcmp (p
, "max") == 0)
32250 else if (id
== cp_operator_id (PLUS_EXPR
))
32252 else if (id
== cp_operator_id (MULT_EXPR
))
32254 else if (id
== cp_operator_id (MINUS_EXPR
))
32256 else if (id
== cp_operator_id (BIT_AND_EXPR
))
32257 code
= BIT_AND_EXPR
;
32258 else if (id
== cp_operator_id (BIT_IOR_EXPR
))
32259 code
= BIT_IOR_EXPR
;
32260 else if (id
== cp_operator_id (BIT_XOR_EXPR
))
32261 code
= BIT_XOR_EXPR
;
32262 else if (id
== cp_operator_id (TRUTH_ANDIF_EXPR
))
32263 code
= TRUTH_ANDIF_EXPR
;
32264 else if (id
== cp_operator_id (TRUTH_ORIF_EXPR
))
32265 code
= TRUTH_ORIF_EXPR
;
32266 id
= omp_reduction_id (code
, id
, NULL_TREE
);
32267 tree scope
= parser
->scope
;
32269 id
= build_qualified_name (NULL_TREE
, scope
, id
, false);
32270 parser
->scope
= NULL_TREE
;
32271 parser
->qualifying_scope
= NULL_TREE
;
32272 parser
->object_scope
= NULL_TREE
;
32276 error ("invalid reduction-identifier");
32278 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32279 /*or_comma=*/false,
32280 /*consume_paren=*/true);
32285 if (!cp_parser_require (parser
, CPP_COLON
, RT_COLON
))
32288 nlist
= cp_parser_omp_var_list_no_open (parser
, OMP_CLAUSE_REDUCTION
, list
,
32290 for (c
= nlist
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
32292 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
32293 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = id
;
32300 schedule ( schedule-kind )
32301 schedule ( schedule-kind , expression )
32304 static | dynamic | guided | runtime | auto
32307 schedule ( schedule-modifier : schedule-kind )
32308 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
32316 cp_parser_omp_clause_schedule (cp_parser
*parser
, tree list
, location_t location
)
32319 int modifiers
= 0, nmodifiers
= 0;
32321 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32324 c
= build_omp_clause (location
, OMP_CLAUSE_SCHEDULE
);
32326 while (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
32328 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32329 const char *p
= IDENTIFIER_POINTER (id
);
32330 if (strcmp ("simd", p
) == 0)
32331 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
32332 else if (strcmp ("monotonic", p
) == 0)
32333 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
32334 else if (strcmp ("nonmonotonic", p
) == 0)
32335 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
32338 cp_lexer_consume_token (parser
->lexer
);
32339 if (nmodifiers
++ == 0
32340 && cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
32341 cp_lexer_consume_token (parser
->lexer
);
32344 cp_parser_require (parser
, CPP_COLON
, RT_COLON
);
32349 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
32351 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32352 const char *p
= IDENTIFIER_POINTER (id
);
32357 if (strcmp ("dynamic", p
) != 0)
32359 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
32363 if (strcmp ("guided", p
) != 0)
32365 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
32369 if (strcmp ("runtime", p
) != 0)
32371 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
32378 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_STATIC
))
32379 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
32380 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_AUTO
))
32381 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
32384 cp_lexer_consume_token (parser
->lexer
);
32386 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
32387 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
32388 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
32389 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
32391 error_at (location
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
32396 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
32399 cp_lexer_consume_token (parser
->lexer
);
32401 token
= cp_lexer_peek_token (parser
->lexer
);
32402 t
= cp_parser_assignment_expression (parser
);
32404 if (t
== error_mark_node
)
32406 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
32407 error_at (token
->location
, "schedule %<runtime%> does not take "
32408 "a %<chunk_size%> parameter");
32409 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
32410 error_at (token
->location
, "schedule %<auto%> does not take "
32411 "a %<chunk_size%> parameter");
32413 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
32415 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32418 else if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_COMMA_CLOSE_PAREN
))
32421 OMP_CLAUSE_SCHEDULE_KIND (c
)
32422 = (enum omp_clause_schedule_kind
)
32423 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
32425 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule", location
);
32426 OMP_CLAUSE_CHAIN (c
) = list
;
32430 cp_parser_error (parser
, "invalid schedule kind");
32432 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32433 /*or_comma=*/false,
32434 /*consume_paren=*/true);
32442 cp_parser_omp_clause_untied (cp_parser
* /*parser*/,
32443 tree list
, location_t location
)
32447 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied", location
);
32449 c
= build_omp_clause (location
, OMP_CLAUSE_UNTIED
);
32450 OMP_CLAUSE_CHAIN (c
) = list
;
32459 cp_parser_omp_clause_branch (cp_parser
* /*parser*/, enum omp_clause_code code
,
32460 tree list
, location_t location
)
32462 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
], location
);
32463 tree c
= build_omp_clause (location
, code
);
32464 OMP_CLAUSE_CHAIN (c
) = list
;
32475 cp_parser_omp_clause_cancelkind (cp_parser
* /*parser*/,
32476 enum omp_clause_code code
,
32477 tree list
, location_t location
)
32479 tree c
= build_omp_clause (location
, code
);
32480 OMP_CLAUSE_CHAIN (c
) = list
;
32488 cp_parser_omp_clause_nogroup (cp_parser
* /*parser*/,
32489 tree list
, location_t location
)
32491 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup", location
);
32492 tree c
= build_omp_clause (location
, OMP_CLAUSE_NOGROUP
);
32493 OMP_CLAUSE_CHAIN (c
) = list
;
32502 cp_parser_omp_clause_orderedkind (cp_parser
* /*parser*/,
32503 enum omp_clause_code code
,
32504 tree list
, location_t location
)
32506 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
], location
);
32507 tree c
= build_omp_clause (location
, code
);
32508 OMP_CLAUSE_CHAIN (c
) = list
;
32513 num_teams ( expression ) */
32516 cp_parser_omp_clause_num_teams (cp_parser
*parser
, tree list
,
32517 location_t location
)
32521 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32524 t
= cp_parser_expression (parser
);
32526 if (t
== error_mark_node
32527 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32528 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32529 /*or_comma=*/false,
32530 /*consume_paren=*/true);
32532 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
,
32533 "num_teams", location
);
32535 c
= build_omp_clause (location
, OMP_CLAUSE_NUM_TEAMS
);
32536 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
32537 OMP_CLAUSE_CHAIN (c
) = list
;
32543 thread_limit ( expression ) */
32546 cp_parser_omp_clause_thread_limit (cp_parser
*parser
, tree list
,
32547 location_t location
)
32551 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32554 t
= cp_parser_expression (parser
);
32556 if (t
== error_mark_node
32557 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32558 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32559 /*or_comma=*/false,
32560 /*consume_paren=*/true);
32562 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
32563 "thread_limit", location
);
32565 c
= build_omp_clause (location
, OMP_CLAUSE_THREAD_LIMIT
);
32566 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
32567 OMP_CLAUSE_CHAIN (c
) = list
;
32573 aligned ( variable-list )
32574 aligned ( variable-list : constant-expression ) */
32577 cp_parser_omp_clause_aligned (cp_parser
*parser
, tree list
)
32579 tree nlist
, c
, alignment
= NULL_TREE
;
32582 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32585 nlist
= cp_parser_omp_var_list_no_open (parser
, OMP_CLAUSE_ALIGNED
, list
,
32590 alignment
= cp_parser_constant_expression (parser
);
32592 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32593 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32594 /*or_comma=*/false,
32595 /*consume_paren=*/true);
32597 if (alignment
== error_mark_node
)
32598 alignment
= NULL_TREE
;
32601 for (c
= nlist
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
32602 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
32608 linear ( variable-list )
32609 linear ( variable-list : expression )
32612 linear ( modifier ( variable-list ) )
32613 linear ( modifier ( variable-list ) : expression ) */
32616 cp_parser_omp_clause_linear (cp_parser
*parser
, tree list
,
32617 bool is_cilk_simd_fn
, bool declare_simd
)
32619 tree nlist
, c
, step
= integer_one_node
;
32621 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
32623 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32626 if (!is_cilk_simd_fn
32627 && cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
32629 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32630 const char *p
= IDENTIFIER_POINTER (id
);
32632 if (strcmp ("ref", p
) == 0)
32633 kind
= OMP_CLAUSE_LINEAR_REF
;
32634 else if (strcmp ("val", p
) == 0)
32635 kind
= OMP_CLAUSE_LINEAR_VAL
;
32636 else if (strcmp ("uval", p
) == 0)
32637 kind
= OMP_CLAUSE_LINEAR_UVAL
;
32638 if (cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_OPEN_PAREN
))
32639 cp_lexer_consume_token (parser
->lexer
);
32641 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
32644 if (kind
== OMP_CLAUSE_LINEAR_DEFAULT
)
32645 nlist
= cp_parser_omp_var_list_no_open (parser
, OMP_CLAUSE_LINEAR
, list
,
32649 nlist
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_LINEAR
, list
);
32650 colon
= cp_lexer_next_token_is (parser
->lexer
, CPP_COLON
);
32652 cp_parser_require (parser
, CPP_COLON
, RT_COLON
);
32653 else if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32654 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32655 /*or_comma=*/false,
32656 /*consume_paren=*/true);
32663 && cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
)
32664 && cp_lexer_nth_token_is (parser
->lexer
, 2, CPP_CLOSE_PAREN
))
32666 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
32667 cp_parser_parse_tentatively (parser
);
32668 step
= cp_parser_id_expression (parser
, /*template_p=*/false,
32669 /*check_dependency_p=*/true,
32670 /*template_p=*/NULL
,
32671 /*declarator_p=*/false,
32672 /*optional_p=*/false);
32673 if (step
!= error_mark_node
)
32674 step
= cp_parser_lookup_name_simple (parser
, step
, token
->location
);
32675 if (step
== error_mark_node
)
32678 cp_parser_abort_tentative_parse (parser
);
32680 else if (!cp_parser_parse_definitely (parser
))
32684 step
= cp_parser_expression (parser
);
32686 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
32688 sorry ("using parameters for %<linear%> step is not supported yet");
32689 step
= integer_one_node
;
32691 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32692 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32693 /*or_comma=*/false,
32694 /*consume_paren=*/true);
32696 if (step
== error_mark_node
)
32700 for (c
= nlist
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
32702 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
32703 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
32710 safelen ( constant-expression ) */
32713 cp_parser_omp_clause_safelen (cp_parser
*parser
, tree list
,
32714 location_t location
)
32718 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32721 t
= cp_parser_constant_expression (parser
);
32723 if (t
== error_mark_node
32724 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32725 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32726 /*or_comma=*/false,
32727 /*consume_paren=*/true);
32729 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen", location
);
32731 c
= build_omp_clause (location
, OMP_CLAUSE_SAFELEN
);
32732 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
32733 OMP_CLAUSE_CHAIN (c
) = list
;
32739 simdlen ( constant-expression ) */
32742 cp_parser_omp_clause_simdlen (cp_parser
*parser
, tree list
,
32743 location_t location
)
32747 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32750 t
= cp_parser_constant_expression (parser
);
32752 if (t
== error_mark_node
32753 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32754 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32755 /*or_comma=*/false,
32756 /*consume_paren=*/true);
32758 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen", location
);
32760 c
= build_omp_clause (location
, OMP_CLAUSE_SIMDLEN
);
32761 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
32762 OMP_CLAUSE_CHAIN (c
) = list
;
32769 identifier [+/- integer]
32770 vec , identifier [+/- integer]
32774 cp_parser_omp_clause_depend_sink (cp_parser
*parser
, location_t clause_loc
,
32779 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_NAME
))
32781 cp_parser_error (parser
, "expected identifier");
32785 while (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
32787 location_t id_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
32788 tree t
, identifier
= cp_parser_identifier (parser
);
32789 tree addend
= NULL
;
32791 if (identifier
== error_mark_node
)
32792 t
= error_mark_node
;
32795 t
= cp_parser_lookup_name_simple
32796 (parser
, identifier
,
32797 cp_lexer_peek_token (parser
->lexer
)->location
);
32798 if (t
== error_mark_node
)
32799 cp_parser_name_lookup_error (parser
, identifier
, t
, NLE_NULL
,
32804 if (cp_lexer_next_token_is (parser
->lexer
, CPP_MINUS
))
32806 else if (!cp_lexer_next_token_is (parser
->lexer
, CPP_PLUS
))
32808 addend
= integer_zero_node
;
32809 goto add_to_vector
;
32811 cp_lexer_consume_token (parser
->lexer
);
32813 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_NUMBER
))
32815 cp_parser_error (parser
, "expected integer");
32819 addend
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32820 if (TREE_CODE (addend
) != INTEGER_CST
)
32822 cp_parser_error (parser
, "expected integer");
32825 cp_lexer_consume_token (parser
->lexer
);
32828 if (t
!= error_mark_node
)
32830 vec
= tree_cons (addend
, t
, vec
);
32832 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
32835 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_COMMA
))
32838 cp_lexer_consume_token (parser
->lexer
);
32841 if (cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
) && vec
)
32843 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
32844 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
32845 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
32846 OMP_CLAUSE_CHAIN (u
) = list
;
32853 depend ( depend-kind : variable-list )
32861 depend ( sink : vec ) */
32864 cp_parser_omp_clause_depend (cp_parser
*parser
, tree list
, location_t loc
)
32867 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
32869 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32872 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
32874 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32875 const char *p
= IDENTIFIER_POINTER (id
);
32877 if (strcmp ("in", p
) == 0)
32878 kind
= OMP_CLAUSE_DEPEND_IN
;
32879 else if (strcmp ("inout", p
) == 0)
32880 kind
= OMP_CLAUSE_DEPEND_INOUT
;
32881 else if (strcmp ("out", p
) == 0)
32882 kind
= OMP_CLAUSE_DEPEND_OUT
;
32883 else if (strcmp ("source", p
) == 0)
32884 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
32885 else if (strcmp ("sink", p
) == 0)
32886 kind
= OMP_CLAUSE_DEPEND_SINK
;
32893 cp_lexer_consume_token (parser
->lexer
);
32895 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
32897 c
= build_omp_clause (loc
, OMP_CLAUSE_DEPEND
);
32898 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
32899 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
32900 OMP_CLAUSE_CHAIN (c
) = list
;
32901 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
32902 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32903 /*or_comma=*/false,
32904 /*consume_paren=*/true);
32908 if (!cp_parser_require (parser
, CPP_COLON
, RT_COLON
))
32911 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
32912 nlist
= cp_parser_omp_clause_depend_sink (parser
, loc
, list
);
32915 nlist
= cp_parser_omp_var_list_no_open (parser
, OMP_CLAUSE_DEPEND
,
32918 for (c
= nlist
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
32919 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
32924 cp_parser_error (parser
, "invalid depend kind");
32926 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32927 /*or_comma=*/false,
32928 /*consume_paren=*/true);
32933 map ( map-kind : variable-list )
32934 map ( variable-list )
32937 alloc | to | from | tofrom
32941 alloc | to | from | tofrom | release | delete
32943 map ( always [,] map-kind: variable-list ) */
32946 cp_parser_omp_clause_map (cp_parser
*parser
, tree list
)
32949 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
32950 bool always
= false;
32952 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
32955 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
32957 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32958 const char *p
= IDENTIFIER_POINTER (id
);
32960 if (strcmp ("always", p
) == 0)
32963 if (cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_COMMA
)
32965 if ((cp_lexer_peek_nth_token (parser
->lexer
, nth
)->type
== CPP_NAME
32966 || (cp_lexer_peek_nth_token (parser
->lexer
, nth
)->keyword
32968 && (cp_lexer_peek_nth_token (parser
->lexer
, nth
+ 1)->type
32972 cp_lexer_consume_token (parser
->lexer
);
32974 cp_lexer_consume_token (parser
->lexer
);
32979 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
)
32980 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_COLON
)
32982 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
32983 const char *p
= IDENTIFIER_POINTER (id
);
32985 if (strcmp ("alloc", p
) == 0)
32986 kind
= GOMP_MAP_ALLOC
;
32987 else if (strcmp ("to", p
) == 0)
32988 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
32989 else if (strcmp ("from", p
) == 0)
32990 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
32991 else if (strcmp ("tofrom", p
) == 0)
32992 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
32993 else if (strcmp ("release", p
) == 0)
32994 kind
= GOMP_MAP_RELEASE
;
32997 cp_parser_error (parser
, "invalid map kind");
32998 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
32999 /*or_comma=*/false,
33000 /*consume_paren=*/true);
33003 cp_lexer_consume_token (parser
->lexer
);
33004 cp_lexer_consume_token (parser
->lexer
);
33006 else if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_DELETE
)
33007 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_COLON
)
33009 kind
= GOMP_MAP_DELETE
;
33010 cp_lexer_consume_token (parser
->lexer
);
33011 cp_lexer_consume_token (parser
->lexer
);
33014 nlist
= cp_parser_omp_var_list_no_open (parser
, OMP_CLAUSE_MAP
, list
,
33017 for (c
= nlist
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
33018 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
33024 device ( expression ) */
33027 cp_parser_omp_clause_device (cp_parser
*parser
, tree list
,
33028 location_t location
)
33032 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
33035 t
= cp_parser_expression (parser
);
33037 if (t
== error_mark_node
33038 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
33039 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
33040 /*or_comma=*/false,
33041 /*consume_paren=*/true);
33043 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
,
33044 "device", location
);
33046 c
= build_omp_clause (location
, OMP_CLAUSE_DEVICE
);
33047 OMP_CLAUSE_DEVICE_ID (c
) = t
;
33048 OMP_CLAUSE_CHAIN (c
) = list
;
33054 dist_schedule ( static )
33055 dist_schedule ( static , expression ) */
33058 cp_parser_omp_clause_dist_schedule (cp_parser
*parser
, tree list
,
33059 location_t location
)
33063 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
33066 c
= build_omp_clause (location
, OMP_CLAUSE_DIST_SCHEDULE
);
33068 if (!cp_lexer_next_token_is_keyword (parser
->lexer
, RID_STATIC
))
33070 cp_lexer_consume_token (parser
->lexer
);
33072 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
33074 cp_lexer_consume_token (parser
->lexer
);
33076 t
= cp_parser_assignment_expression (parser
);
33078 if (t
== error_mark_node
)
33080 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
33082 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
33085 else if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_COMMA_CLOSE_PAREN
))
33088 check_no_duplicate_clause (list
, OMP_CLAUSE_DIST_SCHEDULE
, "dist_schedule",
33090 OMP_CLAUSE_CHAIN (c
) = list
;
33094 cp_parser_error (parser
, "invalid dist_schedule kind");
33096 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
33097 /*or_comma=*/false,
33098 /*consume_paren=*/true);
33103 proc_bind ( proc-bind-kind )
33106 master | close | spread */
33109 cp_parser_omp_clause_proc_bind (cp_parser
*parser
, tree list
,
33110 location_t location
)
33113 enum omp_clause_proc_bind_kind kind
;
33115 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
33118 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
33120 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
33121 const char *p
= IDENTIFIER_POINTER (id
);
33123 if (strcmp ("master", p
) == 0)
33124 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
33125 else if (strcmp ("close", p
) == 0)
33126 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
33127 else if (strcmp ("spread", p
) == 0)
33128 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
33135 cp_lexer_consume_token (parser
->lexer
);
33136 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_COMMA_CLOSE_PAREN
))
33139 c
= build_omp_clause (location
, OMP_CLAUSE_PROC_BIND
);
33140 check_no_duplicate_clause (list
, OMP_CLAUSE_PROC_BIND
, "proc_bind",
33142 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
33143 OMP_CLAUSE_CHAIN (c
) = list
;
33147 cp_parser_error (parser
, "invalid depend kind");
33149 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
33150 /*or_comma=*/false,
33151 /*consume_paren=*/true);
33156 async [( int-expr )] */
33159 cp_parser_oacc_clause_async (cp_parser
*parser
, tree list
)
33162 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
33164 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
33166 if (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_OPEN_PAREN
)
33168 cp_lexer_consume_token (parser
->lexer
);
33170 t
= cp_parser_expression (parser
);
33171 if (t
== error_mark_node
33172 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
33173 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
33174 /*or_comma=*/false,
33175 /*consume_paren=*/true);
33178 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async", loc
);
33180 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
33181 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
33182 OMP_CLAUSE_CHAIN (c
) = list
;
33188 /* Parse all OpenACC clauses. The set clauses allowed by the directive
33189 is a bitmask in MASK. Return the list of clauses found. */
33192 cp_parser_oacc_all_clauses (cp_parser
*parser
, omp_clause_mask mask
,
33193 const char *where
, cp_token
*pragma_tok
,
33194 bool finish_p
= true)
33196 tree clauses
= NULL
;
33199 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
))
33202 pragma_omp_clause c_kind
;
33203 omp_clause_code code
;
33204 const char *c_name
;
33205 tree prev
= clauses
;
33207 if (!first
&& cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
33208 cp_lexer_consume_token (parser
->lexer
);
33210 here
= cp_lexer_peek_token (parser
->lexer
)->location
;
33211 c_kind
= cp_parser_omp_clause_name (parser
);
33215 case PRAGMA_OACC_CLAUSE_ASYNC
:
33216 clauses
= cp_parser_oacc_clause_async (parser
, clauses
);
33219 case PRAGMA_OACC_CLAUSE_AUTO
:
33220 clauses
= cp_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
33224 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
33225 clauses
= cp_parser_omp_clause_collapse (parser
, clauses
, here
);
33226 c_name
= "collapse";
33228 case PRAGMA_OACC_CLAUSE_COPY
:
33229 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33232 case PRAGMA_OACC_CLAUSE_COPYIN
:
33233 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33236 case PRAGMA_OACC_CLAUSE_COPYOUT
:
33237 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33238 c_name
= "copyout";
33240 case PRAGMA_OACC_CLAUSE_CREATE
:
33241 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33244 case PRAGMA_OACC_CLAUSE_DELETE
:
33245 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33248 case PRAGMA_OMP_CLAUSE_DEFAULT
:
33249 clauses
= cp_parser_omp_clause_default (parser
, clauses
, here
, true);
33250 c_name
= "default";
33252 case PRAGMA_OACC_CLAUSE_DEVICE
:
33253 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33256 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
33257 clauses
= cp_parser_oacc_data_clause_deviceptr (parser
, clauses
);
33258 c_name
= "deviceptr";
33260 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
33261 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33262 c_name
= "device_resident";
33264 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
33265 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_FIRSTPRIVATE
,
33267 c_name
= "firstprivate";
33269 case PRAGMA_OACC_CLAUSE_GANG
:
33271 clauses
= cp_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
33274 case PRAGMA_OACC_CLAUSE_HOST
:
33275 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33278 case PRAGMA_OACC_CLAUSE_IF
:
33279 clauses
= cp_parser_omp_clause_if (parser
, clauses
, here
, false);
33282 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
33283 clauses
= cp_parser_oacc_simple_clause (parser
,
33284 OMP_CLAUSE_INDEPENDENT
,
33286 c_name
= "independent";
33288 case PRAGMA_OACC_CLAUSE_LINK
:
33289 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33292 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
33293 code
= OMP_CLAUSE_NUM_GANGS
;
33294 c_name
= "num_gangs";
33295 clauses
= cp_parser_oacc_single_int_clause (parser
, code
, c_name
,
33298 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
33299 c_name
= "num_workers";
33300 code
= OMP_CLAUSE_NUM_WORKERS
;
33301 clauses
= cp_parser_oacc_single_int_clause (parser
, code
, c_name
,
33304 case PRAGMA_OACC_CLAUSE_PRESENT
:
33305 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33306 c_name
= "present";
33308 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
33309 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33310 c_name
= "present_or_copy";
33312 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
33313 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33314 c_name
= "present_or_copyin";
33316 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
33317 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33318 c_name
= "present_or_copyout";
33320 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
33321 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33322 c_name
= "present_or_create";
33324 case PRAGMA_OACC_CLAUSE_PRIVATE
:
33325 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_PRIVATE
,
33327 c_name
= "private";
33329 case PRAGMA_OACC_CLAUSE_REDUCTION
:
33330 clauses
= cp_parser_omp_clause_reduction (parser
, clauses
);
33331 c_name
= "reduction";
33333 case PRAGMA_OACC_CLAUSE_SELF
:
33334 clauses
= cp_parser_oacc_data_clause (parser
, c_kind
, clauses
);
33337 case PRAGMA_OACC_CLAUSE_SEQ
:
33338 clauses
= cp_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
33342 case PRAGMA_OACC_CLAUSE_TILE
:
33343 clauses
= cp_parser_oacc_clause_tile (parser
, here
, clauses
);
33346 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
33347 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
33349 c_name
= "use_device";
33351 case PRAGMA_OACC_CLAUSE_VECTOR
:
33353 clauses
= cp_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
33356 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
33357 c_name
= "vector_length";
33358 code
= OMP_CLAUSE_VECTOR_LENGTH
;
33359 clauses
= cp_parser_oacc_single_int_clause (parser
, code
, c_name
,
33362 case PRAGMA_OACC_CLAUSE_WAIT
:
33363 clauses
= cp_parser_oacc_clause_wait (parser
, clauses
);
33366 case PRAGMA_OACC_CLAUSE_WORKER
:
33368 clauses
= cp_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
33372 cp_parser_error (parser
, "expected %<#pragma acc%> clause");
33378 if (((mask
>> c_kind
) & 1) == 0)
33380 /* Remove the invalid clause(s) from the list to avoid
33381 confusing the rest of the compiler. */
33383 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
33388 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
33391 return finish_omp_clauses (clauses
, C_ORT_ACC
);
33396 /* Parse all OpenMP clauses. The set clauses allowed by the directive
33397 is a bitmask in MASK. Return the list of clauses found; the result
33398 of clause default goes in *pdefault. */
33401 cp_parser_omp_all_clauses (cp_parser
*parser
, omp_clause_mask mask
,
33402 const char *where
, cp_token
*pragma_tok
,
33403 bool finish_p
= true)
33405 tree clauses
= NULL
;
33407 cp_token
*token
= NULL
;
33409 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
))
33411 pragma_omp_clause c_kind
;
33412 const char *c_name
;
33413 tree prev
= clauses
;
33415 if (!first
&& cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
33416 cp_lexer_consume_token (parser
->lexer
);
33418 token
= cp_lexer_peek_token (parser
->lexer
);
33419 c_kind
= cp_parser_omp_clause_name (parser
);
33423 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
33424 clauses
= cp_parser_omp_clause_collapse (parser
, clauses
,
33426 c_name
= "collapse";
33428 case PRAGMA_OMP_CLAUSE_COPYIN
:
33429 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_COPYIN
, clauses
);
33432 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
33433 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_COPYPRIVATE
,
33435 c_name
= "copyprivate";
33437 case PRAGMA_OMP_CLAUSE_DEFAULT
:
33438 clauses
= cp_parser_omp_clause_default (parser
, clauses
,
33439 token
->location
, false);
33440 c_name
= "default";
33442 case PRAGMA_OMP_CLAUSE_FINAL
:
33443 clauses
= cp_parser_omp_clause_final (parser
, clauses
, token
->location
);
33446 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
33447 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_FIRSTPRIVATE
,
33449 c_name
= "firstprivate";
33451 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
33452 clauses
= cp_parser_omp_clause_grainsize (parser
, clauses
,
33454 c_name
= "grainsize";
33456 case PRAGMA_OMP_CLAUSE_HINT
:
33457 clauses
= cp_parser_omp_clause_hint (parser
, clauses
,
33461 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
33462 clauses
= cp_parser_omp_clause_defaultmap (parser
, clauses
,
33464 c_name
= "defaultmap";
33466 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
33467 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
33469 c_name
= "use_device_ptr";
33471 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
33472 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_IS_DEVICE_PTR
,
33474 c_name
= "is_device_ptr";
33476 case PRAGMA_OMP_CLAUSE_IF
:
33477 clauses
= cp_parser_omp_clause_if (parser
, clauses
, token
->location
,
33481 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
33482 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_LASTPRIVATE
,
33484 c_name
= "lastprivate";
33486 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
33487 clauses
= cp_parser_omp_clause_mergeable (parser
, clauses
,
33489 c_name
= "mergeable";
33491 case PRAGMA_OMP_CLAUSE_NOWAIT
:
33492 clauses
= cp_parser_omp_clause_nowait (parser
, clauses
, token
->location
);
33495 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
33496 clauses
= cp_parser_omp_clause_num_tasks (parser
, clauses
,
33498 c_name
= "num_tasks";
33500 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
33501 clauses
= cp_parser_omp_clause_num_threads (parser
, clauses
,
33503 c_name
= "num_threads";
33505 case PRAGMA_OMP_CLAUSE_ORDERED
:
33506 clauses
= cp_parser_omp_clause_ordered (parser
, clauses
,
33508 c_name
= "ordered";
33510 case PRAGMA_OMP_CLAUSE_PRIORITY
:
33511 clauses
= cp_parser_omp_clause_priority (parser
, clauses
,
33513 c_name
= "priority";
33515 case PRAGMA_OMP_CLAUSE_PRIVATE
:
33516 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_PRIVATE
,
33518 c_name
= "private";
33520 case PRAGMA_OMP_CLAUSE_REDUCTION
:
33521 clauses
= cp_parser_omp_clause_reduction (parser
, clauses
);
33522 c_name
= "reduction";
33524 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
33525 clauses
= cp_parser_omp_clause_schedule (parser
, clauses
,
33527 c_name
= "schedule";
33529 case PRAGMA_OMP_CLAUSE_SHARED
:
33530 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_SHARED
,
33534 case PRAGMA_OMP_CLAUSE_UNTIED
:
33535 clauses
= cp_parser_omp_clause_untied (parser
, clauses
,
33539 case PRAGMA_OMP_CLAUSE_INBRANCH
:
33540 case PRAGMA_CILK_CLAUSE_MASK
:
33541 clauses
= cp_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
33542 clauses
, token
->location
);
33543 c_name
= "inbranch";
33545 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
33546 case PRAGMA_CILK_CLAUSE_NOMASK
:
33547 clauses
= cp_parser_omp_clause_branch (parser
,
33548 OMP_CLAUSE_NOTINBRANCH
,
33549 clauses
, token
->location
);
33550 c_name
= "notinbranch";
33552 case PRAGMA_OMP_CLAUSE_PARALLEL
:
33553 clauses
= cp_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
33554 clauses
, token
->location
);
33555 c_name
= "parallel";
33559 error_at (token
->location
, "%qs must be the first clause of %qs",
33564 case PRAGMA_OMP_CLAUSE_FOR
:
33565 clauses
= cp_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
33566 clauses
, token
->location
);
33569 goto clause_not_first
;
33571 case PRAGMA_OMP_CLAUSE_SECTIONS
:
33572 clauses
= cp_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
33573 clauses
, token
->location
);
33574 c_name
= "sections";
33576 goto clause_not_first
;
33578 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
33579 clauses
= cp_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
33580 clauses
, token
->location
);
33581 c_name
= "taskgroup";
33583 goto clause_not_first
;
33585 case PRAGMA_OMP_CLAUSE_LINK
:
33586 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_LINK
, clauses
);
33589 case PRAGMA_OMP_CLAUSE_TO
:
33590 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
33591 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_TO_DECLARE
,
33594 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_TO
, clauses
);
33597 case PRAGMA_OMP_CLAUSE_FROM
:
33598 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_FROM
, clauses
);
33601 case PRAGMA_OMP_CLAUSE_UNIFORM
:
33602 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_UNIFORM
,
33604 c_name
= "uniform";
33606 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
33607 clauses
= cp_parser_omp_clause_num_teams (parser
, clauses
,
33609 c_name
= "num_teams";
33611 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
33612 clauses
= cp_parser_omp_clause_thread_limit (parser
, clauses
,
33614 c_name
= "thread_limit";
33616 case PRAGMA_OMP_CLAUSE_ALIGNED
:
33617 clauses
= cp_parser_omp_clause_aligned (parser
, clauses
);
33618 c_name
= "aligned";
33620 case PRAGMA_OMP_CLAUSE_LINEAR
:
33622 bool cilk_simd_fn
= false, declare_simd
= false;
33623 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
33624 cilk_simd_fn
= true;
33625 else if (((mask
>> PRAGMA_OMP_CLAUSE_UNIFORM
) & 1) != 0)
33626 declare_simd
= true;
33627 clauses
= cp_parser_omp_clause_linear (parser
, clauses
,
33628 cilk_simd_fn
, declare_simd
);
33632 case PRAGMA_OMP_CLAUSE_DEPEND
:
33633 clauses
= cp_parser_omp_clause_depend (parser
, clauses
,
33637 case PRAGMA_OMP_CLAUSE_MAP
:
33638 clauses
= cp_parser_omp_clause_map (parser
, clauses
);
33641 case PRAGMA_OMP_CLAUSE_DEVICE
:
33642 clauses
= cp_parser_omp_clause_device (parser
, clauses
,
33646 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
33647 clauses
= cp_parser_omp_clause_dist_schedule (parser
, clauses
,
33649 c_name
= "dist_schedule";
33651 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
33652 clauses
= cp_parser_omp_clause_proc_bind (parser
, clauses
,
33654 c_name
= "proc_bind";
33656 case PRAGMA_OMP_CLAUSE_SAFELEN
:
33657 clauses
= cp_parser_omp_clause_safelen (parser
, clauses
,
33659 c_name
= "safelen";
33661 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
33662 clauses
= cp_parser_omp_clause_simdlen (parser
, clauses
,
33664 c_name
= "simdlen";
33666 case PRAGMA_OMP_CLAUSE_NOGROUP
:
33667 clauses
= cp_parser_omp_clause_nogroup (parser
, clauses
,
33669 c_name
= "nogroup";
33671 case PRAGMA_OMP_CLAUSE_THREADS
:
33673 = cp_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
33674 clauses
, token
->location
);
33675 c_name
= "threads";
33677 case PRAGMA_OMP_CLAUSE_SIMD
:
33679 = cp_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
33680 clauses
, token
->location
);
33683 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
33684 clauses
= cp_parser_cilk_simd_vectorlength (parser
, clauses
, true);
33685 c_name
= "simdlen";
33688 cp_parser_error (parser
, "expected %<#pragma omp%> clause");
33694 if (((mask
>> c_kind
) & 1) == 0)
33696 /* Remove the invalid clause(s) from the list to avoid
33697 confusing the rest of the compiler. */
33699 error_at (token
->location
, "%qs is not valid for %qs", c_name
, where
);
33703 /* In Cilk Plus SIMD enabled functions there is no pragma_token, so
33704 no reason to skip to the end. */
33705 if (!(flag_cilkplus
&& pragma_tok
== NULL
))
33706 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
33709 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
33710 return finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
33712 return finish_omp_clauses (clauses
, C_ORT_OMP
);
33721 In practice, we're also interested in adding the statement to an
33722 outer node. So it is convenient if we work around the fact that
33723 cp_parser_statement calls add_stmt. */
33726 cp_parser_begin_omp_structured_block (cp_parser
*parser
)
33728 unsigned save
= parser
->in_statement
;
33730 /* Only move the values to IN_OMP_BLOCK if they weren't false.
33731 This preserves the "not within loop or switch" style error messages
33732 for nonsense cases like
33738 if (parser
->in_statement
)
33739 parser
->in_statement
= IN_OMP_BLOCK
;
33745 cp_parser_end_omp_structured_block (cp_parser
*parser
, unsigned save
)
33747 parser
->in_statement
= save
;
33751 cp_parser_omp_structured_block (cp_parser
*parser
, bool *if_p
)
33753 tree stmt
= begin_omp_structured_block ();
33754 unsigned int save
= cp_parser_begin_omp_structured_block (parser
);
33756 cp_parser_statement (parser
, NULL_TREE
, false, if_p
);
33758 cp_parser_end_omp_structured_block (parser
, save
);
33759 return finish_omp_structured_block (stmt
);
33763 # pragma omp atomic new-line
33767 x binop= expr | x++ | ++x | x-- | --x
33769 +, *, -, /, &, ^, |, <<, >>
33771 where x is an lvalue expression with scalar type.
33774 # pragma omp atomic new-line
33777 # pragma omp atomic read new-line
33780 # pragma omp atomic write new-line
33783 # pragma omp atomic update new-line
33786 # pragma omp atomic capture new-line
33789 # pragma omp atomic capture new-line
33797 expression-stmt | x = x binop expr
33799 v = expression-stmt
33801 { v = x; update-stmt; } | { update-stmt; v = x; }
33805 expression-stmt | x = x binop expr | x = expr binop x
33809 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
33811 where x and v are lvalue expressions with scalar type. */
33814 cp_parser_omp_atomic (cp_parser
*parser
, cp_token
*pragma_tok
)
33816 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
, lhs1
= NULL_TREE
;
33817 tree rhs1
= NULL_TREE
, orig_lhs
;
33818 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
33819 bool structured_block
= false;
33820 bool seq_cst
= false;
33822 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
33824 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
33825 const char *p
= IDENTIFIER_POINTER (id
);
33827 if (!strcmp (p
, "seq_cst"))
33830 cp_lexer_consume_token (parser
->lexer
);
33831 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
)
33832 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_NAME
)
33833 cp_lexer_consume_token (parser
->lexer
);
33836 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
33838 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
33839 const char *p
= IDENTIFIER_POINTER (id
);
33841 if (!strcmp (p
, "read"))
33842 code
= OMP_ATOMIC_READ
;
33843 else if (!strcmp (p
, "write"))
33845 else if (!strcmp (p
, "update"))
33847 else if (!strcmp (p
, "capture"))
33848 code
= OMP_ATOMIC_CAPTURE_NEW
;
33852 cp_lexer_consume_token (parser
->lexer
);
33856 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
)
33857 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
== CPP_NAME
)
33858 cp_lexer_consume_token (parser
->lexer
);
33860 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
33862 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
33863 const char *p
= IDENTIFIER_POINTER (id
);
33865 if (!strcmp (p
, "seq_cst"))
33868 cp_lexer_consume_token (parser
->lexer
);
33872 cp_parser_require_pragma_eol (parser
, pragma_tok
);
33876 case OMP_ATOMIC_READ
:
33877 case NOP_EXPR
: /* atomic write */
33878 v
= cp_parser_unary_expression (parser
);
33879 if (v
== error_mark_node
)
33881 if (!cp_parser_require (parser
, CPP_EQ
, RT_EQ
))
33883 if (code
== NOP_EXPR
)
33884 lhs
= cp_parser_expression (parser
);
33886 lhs
= cp_parser_unary_expression (parser
);
33887 if (lhs
== error_mark_node
)
33889 if (code
== NOP_EXPR
)
33891 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
33899 case OMP_ATOMIC_CAPTURE_NEW
:
33900 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
33902 cp_lexer_consume_token (parser
->lexer
);
33903 structured_block
= true;
33907 v
= cp_parser_unary_expression (parser
);
33908 if (v
== error_mark_node
)
33910 if (!cp_parser_require (parser
, CPP_EQ
, RT_EQ
))
33918 lhs
= cp_parser_unary_expression (parser
);
33920 switch (TREE_CODE (lhs
))
33925 case POSTINCREMENT_EXPR
:
33926 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
33927 code
= OMP_ATOMIC_CAPTURE_OLD
;
33929 case PREINCREMENT_EXPR
:
33930 lhs
= TREE_OPERAND (lhs
, 0);
33931 opcode
= PLUS_EXPR
;
33932 rhs
= integer_one_node
;
33935 case POSTDECREMENT_EXPR
:
33936 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
33937 code
= OMP_ATOMIC_CAPTURE_OLD
;
33939 case PREDECREMENT_EXPR
:
33940 lhs
= TREE_OPERAND (lhs
, 0);
33941 opcode
= MINUS_EXPR
;
33942 rhs
= integer_one_node
;
33945 case COMPOUND_EXPR
:
33946 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
33947 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
33948 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
33949 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
33950 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
33951 (TREE_OPERAND (lhs
, 1), 0), 0)))
33953 /* Undo effects of boolean_increment for post {in,de}crement. */
33954 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
33957 if (TREE_CODE (lhs
) == MODIFY_EXPR
33958 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
33960 /* Undo effects of boolean_increment. */
33961 if (integer_onep (TREE_OPERAND (lhs
, 1)))
33963 /* This is pre or post increment. */
33964 rhs
= TREE_OPERAND (lhs
, 1);
33965 lhs
= TREE_OPERAND (lhs
, 0);
33967 if (code
== OMP_ATOMIC_CAPTURE_NEW
33968 && !structured_block
33969 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
33970 code
= OMP_ATOMIC_CAPTURE_OLD
;
33976 switch (cp_lexer_peek_token (parser
->lexer
)->type
)
33979 opcode
= MULT_EXPR
;
33982 opcode
= TRUNC_DIV_EXPR
;
33985 opcode
= PLUS_EXPR
;
33988 opcode
= MINUS_EXPR
;
33990 case CPP_LSHIFT_EQ
:
33991 opcode
= LSHIFT_EXPR
;
33993 case CPP_RSHIFT_EQ
:
33994 opcode
= RSHIFT_EXPR
;
33997 opcode
= BIT_AND_EXPR
;
34000 opcode
= BIT_IOR_EXPR
;
34003 opcode
= BIT_XOR_EXPR
;
34006 enum cp_parser_prec oprec
;
34008 cp_lexer_consume_token (parser
->lexer
);
34009 cp_parser_parse_tentatively (parser
);
34010 rhs1
= cp_parser_simple_cast_expression (parser
);
34011 if (rhs1
== error_mark_node
)
34013 cp_parser_abort_tentative_parse (parser
);
34014 cp_parser_simple_cast_expression (parser
);
34017 token
= cp_lexer_peek_token (parser
->lexer
);
34018 if (token
->type
!= CPP_SEMICOLON
&& !cp_tree_equal (lhs
, rhs1
))
34020 cp_parser_abort_tentative_parse (parser
);
34021 cp_parser_parse_tentatively (parser
);
34022 rhs
= cp_parser_binary_expression (parser
, false, true,
34023 PREC_NOT_OPERATOR
, NULL
);
34024 if (rhs
== error_mark_node
)
34026 cp_parser_abort_tentative_parse (parser
);
34027 cp_parser_binary_expression (parser
, false, true,
34028 PREC_NOT_OPERATOR
, NULL
);
34031 switch (TREE_CODE (rhs
))
34034 case TRUNC_DIV_EXPR
:
34043 if (cp_tree_equal (lhs
, TREE_OPERAND (rhs
, 1)))
34045 if (cp_parser_parse_definitely (parser
))
34047 opcode
= TREE_CODE (rhs
);
34048 rhs1
= TREE_OPERAND (rhs
, 0);
34049 rhs
= TREE_OPERAND (rhs
, 1);
34059 cp_parser_abort_tentative_parse (parser
);
34060 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_OLD
)
34062 rhs
= cp_parser_expression (parser
);
34063 if (rhs
== error_mark_node
)
34069 cp_parser_error (parser
,
34070 "invalid form of %<#pragma omp atomic%>");
34073 if (!cp_parser_parse_definitely (parser
))
34075 switch (token
->type
)
34077 case CPP_SEMICOLON
:
34078 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
34080 code
= OMP_ATOMIC_CAPTURE_OLD
;
34085 cp_lexer_consume_token (parser
->lexer
);
34088 else if (structured_block
)
34095 cp_parser_error (parser
,
34096 "invalid form of %<#pragma omp atomic%>");
34099 opcode
= MULT_EXPR
;
34102 opcode
= TRUNC_DIV_EXPR
;
34105 opcode
= PLUS_EXPR
;
34108 opcode
= MINUS_EXPR
;
34111 opcode
= LSHIFT_EXPR
;
34114 opcode
= RSHIFT_EXPR
;
34117 opcode
= BIT_AND_EXPR
;
34120 opcode
= BIT_IOR_EXPR
;
34123 opcode
= BIT_XOR_EXPR
;
34126 cp_parser_error (parser
,
34127 "invalid operator for %<#pragma omp atomic%>");
34130 oprec
= TOKEN_PRECEDENCE (token
);
34131 gcc_assert (oprec
!= PREC_NOT_OPERATOR
);
34132 if (commutative_tree_code (opcode
))
34133 oprec
= (enum cp_parser_prec
) (oprec
- 1);
34134 cp_lexer_consume_token (parser
->lexer
);
34135 rhs
= cp_parser_binary_expression (parser
, false, false,
34137 if (rhs
== error_mark_node
)
34142 cp_parser_error (parser
,
34143 "invalid operator for %<#pragma omp atomic%>");
34146 cp_lexer_consume_token (parser
->lexer
);
34148 rhs
= cp_parser_expression (parser
);
34149 if (rhs
== error_mark_node
)
34154 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
34156 if (!cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
))
34158 v
= cp_parser_unary_expression (parser
);
34159 if (v
== error_mark_node
)
34161 if (!cp_parser_require (parser
, CPP_EQ
, RT_EQ
))
34163 lhs1
= cp_parser_unary_expression (parser
);
34164 if (lhs1
== error_mark_node
)
34167 if (structured_block
)
34169 cp_parser_consume_semicolon_at_end_of_statement (parser
);
34170 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
34173 finish_omp_atomic (code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
, seq_cst
);
34174 if (!structured_block
)
34175 cp_parser_consume_semicolon_at_end_of_statement (parser
);
34179 cp_parser_skip_to_end_of_block_or_statement (parser
);
34180 if (structured_block
)
34182 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_BRACE
))
34183 cp_lexer_consume_token (parser
->lexer
);
34184 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
34186 cp_parser_skip_to_end_of_block_or_statement (parser
);
34187 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_BRACE
))
34188 cp_lexer_consume_token (parser
->lexer
);
34195 # pragma omp barrier new-line */
34198 cp_parser_omp_barrier (cp_parser
*parser
, cp_token
*pragma_tok
)
34200 cp_parser_require_pragma_eol (parser
, pragma_tok
);
34201 finish_omp_barrier ();
34205 # pragma omp critical [(name)] new-line
34209 # pragma omp critical [(name) [hint(expression)]] new-line
34210 structured-block */
34212 #define OMP_CRITICAL_CLAUSE_MASK \
34213 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
34216 cp_parser_omp_critical (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
34218 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
34220 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
34222 cp_lexer_consume_token (parser
->lexer
);
34224 name
= cp_parser_identifier (parser
);
34226 if (name
== error_mark_node
34227 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
34228 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
34229 /*or_comma=*/false,
34230 /*consume_paren=*/true);
34231 if (name
== error_mark_node
)
34234 clauses
= cp_parser_omp_all_clauses (parser
,
34235 OMP_CRITICAL_CLAUSE_MASK
,
34236 "#pragma omp critical", pragma_tok
);
34239 cp_parser_require_pragma_eol (parser
, pragma_tok
);
34241 stmt
= cp_parser_omp_structured_block (parser
, if_p
);
34242 return c_finish_omp_critical (input_location
, stmt
, name
, clauses
);
34246 # pragma omp flush flush-vars[opt] new-line
34249 ( variable-list ) */
34252 cp_parser_omp_flush (cp_parser
*parser
, cp_token
*pragma_tok
)
34254 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
34255 (void) cp_parser_omp_var_list (parser
, OMP_CLAUSE_ERROR
, NULL
);
34256 cp_parser_require_pragma_eol (parser
, pragma_tok
);
34258 finish_omp_flush ();
34261 /* Helper function, to parse omp for increment expression. */
34264 cp_parser_omp_for_cond (cp_parser
*parser
, tree decl
, enum tree_code code
)
34266 tree cond
= cp_parser_binary_expression (parser
, false, true,
34267 PREC_NOT_OPERATOR
, NULL
);
34268 if (cond
== error_mark_node
34269 || cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
34271 cp_parser_skip_to_end_of_statement (parser
);
34272 return error_mark_node
;
34275 switch (TREE_CODE (cond
))
34283 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
34285 /* Fall through: OpenMP disallows NE_EXPR. */
34286 gcc_fallthrough ();
34288 return error_mark_node
;
34291 /* If decl is an iterator, preserve LHS and RHS of the relational
34292 expr until finish_omp_for. */
34294 && (type_dependent_expression_p (decl
)
34295 || CLASS_TYPE_P (TREE_TYPE (decl
))))
34298 return build_x_binary_op (EXPR_LOC_OR_LOC (cond
, input_location
),
34300 TREE_OPERAND (cond
, 0), ERROR_MARK
,
34301 TREE_OPERAND (cond
, 1), ERROR_MARK
,
34302 /*overload=*/NULL
, tf_warning_or_error
);
34305 /* Helper function, to parse omp for increment expression. */
34308 cp_parser_omp_for_incr (cp_parser
*parser
, tree decl
)
34310 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
34316 if (token
->type
== CPP_PLUS_PLUS
|| token
->type
== CPP_MINUS_MINUS
)
34318 op
= (token
->type
== CPP_PLUS_PLUS
34319 ? PREINCREMENT_EXPR
: PREDECREMENT_EXPR
);
34320 cp_lexer_consume_token (parser
->lexer
);
34321 lhs
= cp_parser_simple_cast_expression (parser
);
34323 && (!processing_template_decl
|| !cp_tree_equal (lhs
, decl
)))
34324 return error_mark_node
;
34325 return build2 (op
, TREE_TYPE (decl
), decl
, NULL_TREE
);
34328 lhs
= cp_parser_primary_expression (parser
, false, false, false, &idk
);
34330 && (!processing_template_decl
|| !cp_tree_equal (lhs
, decl
)))
34331 return error_mark_node
;
34333 token
= cp_lexer_peek_token (parser
->lexer
);
34334 if (token
->type
== CPP_PLUS_PLUS
|| token
->type
== CPP_MINUS_MINUS
)
34336 op
= (token
->type
== CPP_PLUS_PLUS
34337 ? POSTINCREMENT_EXPR
: POSTDECREMENT_EXPR
);
34338 cp_lexer_consume_token (parser
->lexer
);
34339 return build2 (op
, TREE_TYPE (decl
), decl
, NULL_TREE
);
34342 op
= cp_parser_assignment_operator_opt (parser
);
34343 if (op
== ERROR_MARK
)
34344 return error_mark_node
;
34346 if (op
!= NOP_EXPR
)
34348 rhs
= cp_parser_assignment_expression (parser
);
34349 rhs
= build2 (op
, TREE_TYPE (decl
), decl
, rhs
);
34350 return build2 (MODIFY_EXPR
, TREE_TYPE (decl
), decl
, rhs
);
34353 lhs
= cp_parser_binary_expression (parser
, false, false,
34354 PREC_ADDITIVE_EXPRESSION
, NULL
);
34355 token
= cp_lexer_peek_token (parser
->lexer
);
34356 decl_first
= (lhs
== decl
34357 || (processing_template_decl
&& cp_tree_equal (lhs
, decl
)));
34360 if (token
->type
!= CPP_PLUS
34361 && token
->type
!= CPP_MINUS
)
34362 return error_mark_node
;
34366 op
= token
->type
== CPP_PLUS
? PLUS_EXPR
: MINUS_EXPR
;
34367 cp_lexer_consume_token (parser
->lexer
);
34368 rhs
= cp_parser_binary_expression (parser
, false, false,
34369 PREC_ADDITIVE_EXPRESSION
, NULL
);
34370 token
= cp_lexer_peek_token (parser
->lexer
);
34371 if (token
->type
== CPP_PLUS
|| token
->type
== CPP_MINUS
|| decl_first
)
34373 if (lhs
== NULL_TREE
)
34375 if (op
== PLUS_EXPR
)
34378 lhs
= build_x_unary_op (input_location
, NEGATE_EXPR
, rhs
,
34379 tf_warning_or_error
);
34382 lhs
= build_x_binary_op (input_location
, op
, lhs
, ERROR_MARK
, rhs
,
34383 ERROR_MARK
, NULL
, tf_warning_or_error
);
34386 while (token
->type
== CPP_PLUS
|| token
->type
== CPP_MINUS
);
34391 && (!processing_template_decl
|| !cp_tree_equal (rhs
, decl
)))
34392 || op
== MINUS_EXPR
)
34393 return error_mark_node
;
34394 rhs
= build2 (op
, TREE_TYPE (decl
), lhs
, decl
);
34397 rhs
= build2 (PLUS_EXPR
, TREE_TYPE (decl
), decl
, lhs
);
34399 return build2 (MODIFY_EXPR
, TREE_TYPE (decl
), decl
, rhs
);
34402 /* Parse the initialization statement of either an OpenMP for loop or
34403 a Cilk Plus for loop.
34405 Return true if the resulting construct should have an
34406 OMP_CLAUSE_PRIVATE added to it. */
34409 cp_parser_omp_for_loop_init (cp_parser
*parser
,
34410 enum tree_code code
,
34411 tree
&this_pre_body
,
34412 vec
<tree
, va_gc
> *for_block
,
34418 if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
34421 tree add_private_clause
= NULL_TREE
;
34423 /* See 2.5.1 (in OpenMP 3.0, similar wording is in 2.5 standard too):
34427 integer-type var = lb
34428 random-access-iterator-type var = lb
34429 pointer-type var = lb
34431 cp_decl_specifier_seq type_specifiers
;
34433 /* First, try to parse as an initialized declaration. See
34434 cp_parser_condition, from whence the bulk of this is copied. */
34436 cp_parser_parse_tentatively (parser
);
34437 cp_parser_type_specifier_seq (parser
, /*is_declaration=*/true,
34438 /*is_trailing_return=*/false,
34440 if (cp_parser_parse_definitely (parser
))
34442 /* If parsing a type specifier seq succeeded, then this
34443 MUST be a initialized declaration. */
34444 tree asm_specification
, attributes
;
34445 cp_declarator
*declarator
;
34447 declarator
= cp_parser_declarator (parser
,
34448 CP_PARSER_DECLARATOR_NAMED
,
34449 /*ctor_dtor_or_conv_p=*/NULL
,
34450 /*parenthesized_p=*/NULL
,
34451 /*member_p=*/false,
34452 /*friend_p=*/false);
34453 attributes
= cp_parser_attributes_opt (parser
);
34454 asm_specification
= cp_parser_asm_specification_opt (parser
);
34456 if (declarator
== cp_error_declarator
)
34457 cp_parser_skip_to_end_of_statement (parser
);
34461 tree pushed_scope
, auto_node
;
34463 decl
= start_decl (declarator
, &type_specifiers
,
34464 SD_INITIALIZED
, attributes
,
34465 /*prefix_attributes=*/NULL_TREE
,
34468 auto_node
= type_uses_auto (TREE_TYPE (decl
));
34469 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_EQ
))
34471 if (cp_lexer_next_token_is (parser
->lexer
,
34474 if (code
!= CILK_SIMD
&& code
!= CILK_FOR
)
34475 error ("parenthesized initialization is not allowed in "
34476 "OpenMP %<for%> loop");
34478 error ("parenthesized initialization is "
34479 "not allowed in for-loop");
34482 /* Trigger an error. */
34483 cp_parser_require (parser
, CPP_EQ
, RT_EQ
);
34485 init
= error_mark_node
;
34486 cp_parser_skip_to_end_of_statement (parser
);
34488 else if (CLASS_TYPE_P (TREE_TYPE (decl
))
34489 || type_dependent_expression_p (decl
)
34492 bool is_direct_init
, is_non_constant_init
;
34494 init
= cp_parser_initializer (parser
,
34496 &is_non_constant_init
);
34501 = do_auto_deduction (TREE_TYPE (decl
), init
,
34504 if (!CLASS_TYPE_P (TREE_TYPE (decl
))
34505 && !type_dependent_expression_p (decl
))
34509 cp_finish_decl (decl
, init
, !is_non_constant_init
,
34511 LOOKUP_ONLYCONVERTING
);
34513 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
34515 vec_safe_push (for_block
, this_pre_body
);
34520 init
= pop_stmt_list (this_pre_body
);
34521 if (init
&& TREE_CODE (init
) == STATEMENT_LIST
)
34523 tree_stmt_iterator i
= tsi_start (init
);
34524 /* Move lambda DECL_EXPRs to FOR_BLOCK. */
34525 while (!tsi_end_p (i
))
34527 tree t
= tsi_stmt (i
);
34528 if (TREE_CODE (t
) == DECL_EXPR
34529 && TREE_CODE (DECL_EXPR_DECL (t
)) == TYPE_DECL
)
34532 vec_safe_push (for_block
, t
);
34537 if (tsi_one_before_end_p (i
))
34539 tree t
= tsi_stmt (i
);
34541 free_stmt_list (init
);
34546 this_pre_body
= NULL_TREE
;
34551 cp_lexer_consume_token (parser
->lexer
);
34552 init
= cp_parser_assignment_expression (parser
);
34555 if (TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
)
34556 init
= error_mark_node
;
34558 cp_finish_decl (decl
, NULL_TREE
,
34559 /*init_const_expr_p=*/false,
34561 LOOKUP_ONLYCONVERTING
);
34565 pop_scope (pushed_scope
);
34571 /* If parsing a type specifier sequence failed, then
34572 this MUST be a simple expression. */
34573 if (code
== CILK_FOR
)
34574 error ("%<_Cilk_for%> allows expression instead of declaration only "
34575 "in C, not in C++");
34576 cp_parser_parse_tentatively (parser
);
34577 decl
= cp_parser_primary_expression (parser
, false, false,
34579 cp_token
*last_tok
= cp_lexer_peek_token (parser
->lexer
);
34580 if (!cp_parser_error_occurred (parser
)
34582 && (TREE_CODE (decl
) == COMPONENT_REF
34583 || (TREE_CODE (decl
) == SCOPE_REF
&& TREE_TYPE (decl
))))
34585 cp_parser_abort_tentative_parse (parser
);
34586 cp_parser_parse_tentatively (parser
);
34587 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
34588 tree name
= cp_parser_id_expression (parser
, /*template_p=*/false,
34589 /*check_dependency_p=*/true,
34590 /*template_p=*/NULL
,
34591 /*declarator_p=*/false,
34592 /*optional_p=*/false);
34593 if (name
!= error_mark_node
34594 && last_tok
== cp_lexer_peek_token (parser
->lexer
))
34596 decl
= cp_parser_lookup_name_simple (parser
, name
,
34598 if (TREE_CODE (decl
) == FIELD_DECL
)
34599 add_private_clause
= omp_privatize_field (decl
, false);
34601 cp_parser_abort_tentative_parse (parser
);
34602 cp_parser_parse_tentatively (parser
);
34603 decl
= cp_parser_primary_expression (parser
, false, false,
34606 if (!cp_parser_error_occurred (parser
)
34609 && CLASS_TYPE_P (TREE_TYPE (decl
)))
34613 cp_parser_parse_definitely (parser
);
34614 cp_parser_require (parser
, CPP_EQ
, RT_EQ
);
34615 rhs
= cp_parser_assignment_expression (parser
);
34617 finish_expr_stmt (build_x_modify_expr (EXPR_LOCATION (rhs
),
34620 tf_warning_or_error
));
34621 if (!add_private_clause
)
34622 add_private_clause
= decl
;
34627 cp_parser_abort_tentative_parse (parser
);
34628 init
= cp_parser_expression (parser
);
34631 if (TREE_CODE (init
) == MODIFY_EXPR
34632 || TREE_CODE (init
) == MODOP_EXPR
)
34633 real_decl
= TREE_OPERAND (init
, 0);
34637 return add_private_clause
;
34640 /* Parse the restricted form of the for statement allowed by OpenMP. */
34643 cp_parser_omp_for_loop (cp_parser
*parser
, enum tree_code code
, tree clauses
,
34644 tree
*cclauses
, bool *if_p
)
34646 tree init
, orig_init
, cond
, incr
, body
, decl
, pre_body
= NULL_TREE
, ret
;
34647 tree real_decl
, initv
, condv
, incrv
, declv
;
34648 tree this_pre_body
, cl
, ordered_cl
= NULL_TREE
;
34649 location_t loc_first
;
34650 bool collapse_err
= false;
34651 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
34652 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
34653 auto_vec
<tree
, 4> orig_inits
;
34654 bool tiling
= false;
34656 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
34657 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
34658 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
34659 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
34662 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
34664 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
34665 && OMP_CLAUSE_ORDERED_EXPR (cl
))
34668 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
34671 if (ordered
&& ordered
< collapse
)
34673 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
34674 "%<ordered%> clause parameter is less than %<collapse%>");
34675 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
34676 = build_int_cst (NULL_TREE
, collapse
);
34677 ordered
= collapse
;
34681 for (tree
*pc
= &clauses
; *pc
; )
34682 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
34684 error_at (OMP_CLAUSE_LOCATION (*pc
),
34685 "%<linear%> clause may not be specified together "
34686 "with %<ordered%> clause with a parameter");
34687 *pc
= OMP_CLAUSE_CHAIN (*pc
);
34690 pc
= &OMP_CLAUSE_CHAIN (*pc
);
34693 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
34694 count
= ordered
? ordered
: collapse
;
34696 declv
= make_tree_vec (count
);
34697 initv
= make_tree_vec (count
);
34698 condv
= make_tree_vec (count
);
34699 incrv
= make_tree_vec (count
);
34701 loc_first
= cp_lexer_peek_token (parser
->lexer
)->location
;
34703 for (i
= 0; i
< count
; i
++)
34705 int bracecount
= 0;
34706 tree add_private_clause
= NULL_TREE
;
34709 if (code
!= CILK_FOR
34710 && !cp_lexer_next_token_is_keyword (parser
->lexer
, RID_FOR
))
34713 cp_parser_error (parser
, "for statement expected");
34716 if (code
== CILK_FOR
34717 && !cp_lexer_next_token_is_keyword (parser
->lexer
, RID_CILK_FOR
))
34720 cp_parser_error (parser
, "_Cilk_for statement expected");
34723 loc
= cp_lexer_consume_token (parser
->lexer
)->location
;
34725 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
34728 init
= orig_init
= decl
= real_decl
= NULL
;
34729 this_pre_body
= push_stmt_list ();
34732 = cp_parser_omp_for_loop_init (parser
, code
,
34733 this_pre_body
, for_block
,
34734 init
, orig_init
, decl
, real_decl
);
34736 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
34739 this_pre_body
= pop_stmt_list (this_pre_body
);
34743 pre_body
= push_stmt_list ();
34745 add_stmt (this_pre_body
);
34746 pre_body
= pop_stmt_list (pre_body
);
34749 pre_body
= this_pre_body
;
34754 if (cclauses
!= NULL
34755 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
34756 && real_decl
!= NULL_TREE
)
34759 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
34760 if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
34761 && OMP_CLAUSE_DECL (*c
) == real_decl
)
34763 error_at (loc
, "iteration variable %qD"
34764 " should not be firstprivate", real_decl
);
34765 *c
= OMP_CLAUSE_CHAIN (*c
);
34767 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_LASTPRIVATE
34768 && OMP_CLAUSE_DECL (*c
) == real_decl
)
34770 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
34772 *c
= OMP_CLAUSE_CHAIN (*c
);
34773 if (code
== OMP_SIMD
)
34775 OMP_CLAUSE_CHAIN (l
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
34776 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
34780 OMP_CLAUSE_CHAIN (l
) = clauses
;
34783 add_private_clause
= NULL_TREE
;
34787 if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_PRIVATE
34788 && OMP_CLAUSE_DECL (*c
) == real_decl
)
34789 add_private_clause
= NULL_TREE
;
34790 c
= &OMP_CLAUSE_CHAIN (*c
);
34794 if (add_private_clause
)
34797 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
34799 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
34800 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
34801 && OMP_CLAUSE_DECL (c
) == decl
)
34803 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
34804 && OMP_CLAUSE_DECL (c
) == decl
)
34805 error_at (loc
, "iteration variable %qD "
34806 "should not be firstprivate",
34808 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
34809 && OMP_CLAUSE_DECL (c
) == decl
)
34810 error_at (loc
, "iteration variable %qD should not be reduction",
34815 if (code
!= OMP_SIMD
)
34816 c
= build_omp_clause (loc
, OMP_CLAUSE_PRIVATE
);
34817 else if (collapse
== 1)
34818 c
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
34820 c
= build_omp_clause (loc
, OMP_CLAUSE_LASTPRIVATE
);
34821 OMP_CLAUSE_DECL (c
) = add_private_clause
;
34822 c
= finish_omp_clauses (c
, C_ORT_OMP
);
34825 OMP_CLAUSE_CHAIN (c
) = clauses
;
34827 /* For linear, signal that we need to fill up
34828 the so far unknown linear step. */
34829 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
)
34830 OMP_CLAUSE_LINEAR_STEP (c
) = NULL_TREE
;
34836 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_SEMICOLON
))
34837 cond
= cp_parser_omp_for_cond (parser
, decl
, code
);
34838 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
34841 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_CLOSE_PAREN
))
34843 /* If decl is an iterator, preserve the operator on decl
34844 until finish_omp_for. */
34846 && ((processing_template_decl
34847 && (TREE_TYPE (real_decl
) == NULL_TREE
34848 || !POINTER_TYPE_P (TREE_TYPE (real_decl
))))
34849 || CLASS_TYPE_P (TREE_TYPE (real_decl
))))
34850 incr
= cp_parser_omp_for_incr (parser
, real_decl
);
34852 incr
= cp_parser_expression (parser
);
34853 if (!EXPR_HAS_LOCATION (incr
))
34854 protected_set_expr_location (incr
, input_location
);
34857 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
34858 cp_parser_skip_to_closing_parenthesis (parser
, /*recovering=*/true,
34859 /*or_comma=*/false,
34860 /*consume_paren=*/true);
34862 TREE_VEC_ELT (declv
, i
) = decl
;
34863 TREE_VEC_ELT (initv
, i
) = init
;
34864 TREE_VEC_ELT (condv
, i
) = cond
;
34865 TREE_VEC_ELT (incrv
, i
) = incr
;
34868 orig_inits
.safe_grow_cleared (i
+ 1);
34869 orig_inits
[i
] = orig_init
;
34872 if (i
== count
- 1)
34875 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
34876 in between the collapsed for loops to be still considered perfectly
34877 nested. Hopefully the final version clarifies this.
34878 For now handle (multiple) {'s and empty statements. */
34879 cp_parser_parse_tentatively (parser
);
34882 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_FOR
))
34884 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_BRACE
))
34886 cp_lexer_consume_token (parser
->lexer
);
34889 else if (bracecount
34890 && cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
34891 cp_lexer_consume_token (parser
->lexer
);
34894 loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
34895 error_at (loc
, "not enough for loops to collapse");
34896 collapse_err
= true;
34897 cp_parser_abort_tentative_parse (parser
);
34905 cp_parser_parse_definitely (parser
);
34906 nbraces
+= bracecount
;
34913 /* Note that we saved the original contents of this flag when we entered
34914 the structured block, and so we don't need to re-save it here. */
34915 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
34916 parser
->in_statement
= IN_CILK_SIMD_FOR
;
34918 parser
->in_statement
= IN_OMP_FOR
;
34920 /* Note that the grammar doesn't call for a structured block here,
34921 though the loop as a whole is a structured block. */
34922 body
= push_stmt_list ();
34923 cp_parser_statement (parser
, NULL_TREE
, false, if_p
);
34924 body
= pop_stmt_list (body
);
34926 if (declv
== NULL_TREE
)
34929 ret
= finish_omp_for (loc_first
, code
, declv
, NULL
, initv
, condv
, incrv
,
34930 body
, pre_body
, &orig_inits
, clauses
);
34934 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_BRACE
))
34936 cp_lexer_consume_token (parser
->lexer
);
34939 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_SEMICOLON
))
34940 cp_lexer_consume_token (parser
->lexer
);
34945 error_at (cp_lexer_peek_token (parser
->lexer
)->location
,
34946 "collapsed loops not perfectly nested");
34948 collapse_err
= true;
34949 cp_parser_statement_seq_opt (parser
, NULL
);
34950 if (cp_lexer_next_token_is (parser
->lexer
, CPP_EOF
))
34955 while (!for_block
->is_empty ())
34957 tree t
= for_block
->pop ();
34958 if (TREE_CODE (t
) == STATEMENT_LIST
)
34959 add_stmt (pop_stmt_list (t
));
34963 release_tree_vector (for_block
);
34968 /* Helper function for OpenMP parsing, split clauses and call
34969 finish_omp_clauses on each of the set of clauses afterwards. */
34972 cp_omp_split_clauses (location_t loc
, enum tree_code code
,
34973 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
34976 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
34977 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
34979 cclauses
[i
] = finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
34983 #pragma omp simd simd-clause[optseq] new-line
34986 #define OMP_SIMD_CLAUSE_MASK \
34987 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
34988 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
34989 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
34990 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
34991 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
34992 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
34993 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
34994 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
34997 cp_parser_omp_simd (cp_parser
*parser
, cp_token
*pragma_tok
,
34998 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
35001 tree clauses
, sb
, ret
;
35003 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
35005 strcat (p_name
, " simd");
35006 mask
|= OMP_SIMD_CLAUSE_MASK
;
35008 clauses
= cp_parser_omp_all_clauses (parser
, mask
, p_name
, pragma_tok
,
35012 cp_omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
35013 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
35014 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
35015 OMP_CLAUSE_ORDERED
);
35016 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
35018 error_at (OMP_CLAUSE_LOCATION (c
),
35019 "%<ordered%> clause with parameter may not be specified "
35020 "on %qs construct", p_name
);
35021 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
35025 sb
= begin_omp_structured_block ();
35026 save
= cp_parser_begin_omp_structured_block (parser
);
35028 ret
= cp_parser_omp_for_loop (parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
35030 cp_parser_end_omp_structured_block (parser
, save
);
35031 add_stmt (finish_omp_structured_block (sb
));
35037 #pragma omp for for-clause[optseq] new-line
35041 #pragma omp for simd for-simd-clause[optseq] new-line
35044 #define OMP_FOR_CLAUSE_MASK \
35045 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
35046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
35047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
35048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
35049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
35050 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
35051 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
35052 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
35053 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
35056 cp_parser_omp_for (cp_parser
*parser
, cp_token
*pragma_tok
,
35057 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
35060 tree clauses
, sb
, ret
;
35062 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
35064 strcat (p_name
, " for");
35065 mask
|= OMP_FOR_CLAUSE_MASK
;
35066 /* parallel for{, simd} disallows nowait clause, but for
35067 target {teams distribute ,}parallel for{, simd} it should be accepted. */
35068 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
35069 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
35070 /* Composite distribute parallel for{, simd} disallows ordered clause. */
35071 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
35072 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
35074 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
35076 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
35077 const char *p
= IDENTIFIER_POINTER (id
);
35079 if (strcmp (p
, "simd") == 0)
35081 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
35082 if (cclauses
== NULL
)
35083 cclauses
= cclauses_buf
;
35085 cp_lexer_consume_token (parser
->lexer
);
35086 if (!flag_openmp
) /* flag_openmp_simd */
35087 return cp_parser_omp_simd (parser
, pragma_tok
, p_name
, mask
,
35089 sb
= begin_omp_structured_block ();
35090 save
= cp_parser_begin_omp_structured_block (parser
);
35091 ret
= cp_parser_omp_simd (parser
, pragma_tok
, p_name
, mask
,
35093 cp_parser_end_omp_structured_block (parser
, save
);
35094 tree body
= finish_omp_structured_block (sb
);
35097 ret
= make_node (OMP_FOR
);
35098 TREE_TYPE (ret
) = void_type_node
;
35099 OMP_FOR_BODY (ret
) = body
;
35100 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
35101 SET_EXPR_LOCATION (ret
, loc
);
35106 if (!flag_openmp
) /* flag_openmp_simd */
35108 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35112 /* Composite distribute parallel for disallows linear clause. */
35113 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
35114 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
35116 clauses
= cp_parser_omp_all_clauses (parser
, mask
, p_name
, pragma_tok
,
35120 cp_omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
35121 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
35124 sb
= begin_omp_structured_block ();
35125 save
= cp_parser_begin_omp_structured_block (parser
);
35127 ret
= cp_parser_omp_for_loop (parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
35129 cp_parser_end_omp_structured_block (parser
, save
);
35130 add_stmt (finish_omp_structured_block (sb
));
35136 # pragma omp master new-line
35137 structured-block */
35140 cp_parser_omp_master (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
35142 cp_parser_require_pragma_eol (parser
, pragma_tok
);
35143 return c_finish_omp_master (input_location
,
35144 cp_parser_omp_structured_block (parser
, if_p
));
35148 # pragma omp ordered new-line
35152 # pragma omp ordered ordered-clauses new-line
35153 structured-block */
35155 #define OMP_ORDERED_CLAUSE_MASK \
35156 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
35157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
35159 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
35160 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
35163 cp_parser_omp_ordered (cp_parser
*parser
, cp_token
*pragma_tok
,
35164 enum pragma_context context
, bool *if_p
)
35166 location_t loc
= pragma_tok
->location
;
35168 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
35170 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
35171 const char *p
= IDENTIFIER_POINTER (id
);
35173 if (strcmp (p
, "depend") == 0)
35175 if (context
== pragma_stmt
)
35177 error_at (pragma_tok
->location
, "%<#pragma omp ordered%> with "
35178 "%<depend%> clause may only be used in compound "
35180 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35184 = cp_parser_omp_all_clauses (parser
,
35185 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
35186 "#pragma omp ordered", pragma_tok
);
35187 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
35193 = cp_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
35194 "#pragma omp ordered", pragma_tok
);
35195 c_finish_omp_ordered (loc
, clauses
,
35196 cp_parser_omp_structured_block (parser
, if_p
));
35203 { section-sequence }
35206 section-directive[opt] structured-block
35207 section-sequence section-directive structured-block */
35210 cp_parser_omp_sections_scope (cp_parser
*parser
)
35212 tree stmt
, substmt
;
35213 bool error_suppress
= false;
35216 if (!cp_parser_require (parser
, CPP_OPEN_BRACE
, RT_OPEN_BRACE
))
35219 stmt
= push_stmt_list ();
35221 if (cp_parser_pragma_kind (cp_lexer_peek_token (parser
->lexer
))
35222 != PRAGMA_OMP_SECTION
)
35224 substmt
= cp_parser_omp_structured_block (parser
, NULL
);
35225 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
35226 add_stmt (substmt
);
35231 tok
= cp_lexer_peek_token (parser
->lexer
);
35232 if (tok
->type
== CPP_CLOSE_BRACE
)
35234 if (tok
->type
== CPP_EOF
)
35237 if (cp_parser_pragma_kind (tok
) == PRAGMA_OMP_SECTION
)
35239 cp_lexer_consume_token (parser
->lexer
);
35240 cp_parser_require_pragma_eol (parser
, tok
);
35241 error_suppress
= false;
35243 else if (!error_suppress
)
35245 cp_parser_error (parser
, "expected %<#pragma omp section%> or %<}%>");
35246 error_suppress
= true;
35249 substmt
= cp_parser_omp_structured_block (parser
, NULL
);
35250 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
35251 add_stmt (substmt
);
35253 cp_parser_require (parser
, CPP_CLOSE_BRACE
, RT_CLOSE_BRACE
);
35255 substmt
= pop_stmt_list (stmt
);
35257 stmt
= make_node (OMP_SECTIONS
);
35258 TREE_TYPE (stmt
) = void_type_node
;
35259 OMP_SECTIONS_BODY (stmt
) = substmt
;
35266 # pragma omp sections sections-clause[optseq] newline
35269 #define OMP_SECTIONS_CLAUSE_MASK \
35270 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
35271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
35272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
35273 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
35274 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
35277 cp_parser_omp_sections (cp_parser
*parser
, cp_token
*pragma_tok
,
35278 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
35281 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
35283 strcat (p_name
, " sections");
35284 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
35286 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
35288 clauses
= cp_parser_omp_all_clauses (parser
, mask
, p_name
, pragma_tok
,
35292 cp_omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
35293 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
35296 ret
= cp_parser_omp_sections_scope (parser
);
35298 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
35304 # pragma omp parallel parallel-clause[optseq] new-line
35306 # pragma omp parallel for parallel-for-clause[optseq] new-line
35308 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
35312 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
35313 structured-block */
35315 #define OMP_PARALLEL_CLAUSE_MASK \
35316 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
35317 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
35318 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
35319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
35320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
35321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
35322 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
35323 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
35324 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
35327 cp_parser_omp_parallel (cp_parser
*parser
, cp_token
*pragma_tok
,
35328 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
35331 tree stmt
, clauses
, block
;
35333 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
35335 strcat (p_name
, " parallel");
35336 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
35337 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
35338 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
35339 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
35340 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
35342 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_FOR
))
35344 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
35345 if (cclauses
== NULL
)
35346 cclauses
= cclauses_buf
;
35348 cp_lexer_consume_token (parser
->lexer
);
35349 if (!flag_openmp
) /* flag_openmp_simd */
35350 return cp_parser_omp_for (parser
, pragma_tok
, p_name
, mask
, cclauses
,
35352 block
= begin_omp_parallel ();
35353 save
= cp_parser_begin_omp_structured_block (parser
);
35354 tree ret
= cp_parser_omp_for (parser
, pragma_tok
, p_name
, mask
, cclauses
,
35356 cp_parser_end_omp_structured_block (parser
, save
);
35357 stmt
= finish_omp_parallel (cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
35359 if (ret
== NULL_TREE
)
35361 OMP_PARALLEL_COMBINED (stmt
) = 1;
35364 /* When combined with distribute, parallel has to be followed by for.
35365 #pragma omp target parallel is allowed though. */
35367 && (mask
& (OMP_CLAUSE_MASK_1
35368 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
35370 error_at (loc
, "expected %<for%> after %qs", p_name
);
35371 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35374 else if (!flag_openmp
) /* flag_openmp_simd */
35376 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35379 else if (cclauses
== NULL
&& cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
35381 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
35382 const char *p
= IDENTIFIER_POINTER (id
);
35383 if (strcmp (p
, "sections") == 0)
35385 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
35386 cclauses
= cclauses_buf
;
35388 cp_lexer_consume_token (parser
->lexer
);
35389 block
= begin_omp_parallel ();
35390 save
= cp_parser_begin_omp_structured_block (parser
);
35391 cp_parser_omp_sections (parser
, pragma_tok
, p_name
, mask
, cclauses
);
35392 cp_parser_end_omp_structured_block (parser
, save
);
35393 stmt
= finish_omp_parallel (cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
35395 OMP_PARALLEL_COMBINED (stmt
) = 1;
35400 clauses
= cp_parser_omp_all_clauses (parser
, mask
, p_name
, pragma_tok
,
35404 cp_omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
35405 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
35408 block
= begin_omp_parallel ();
35409 save
= cp_parser_begin_omp_structured_block (parser
);
35410 cp_parser_statement (parser
, NULL_TREE
, false, if_p
);
35411 cp_parser_end_omp_structured_block (parser
, save
);
35412 stmt
= finish_omp_parallel (clauses
, block
);
35417 # pragma omp single single-clause[optseq] new-line
35418 structured-block */
35420 #define OMP_SINGLE_CLAUSE_MASK \
35421 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
35422 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
35423 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
35424 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
35427 cp_parser_omp_single (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
35429 tree stmt
= make_node (OMP_SINGLE
);
35430 TREE_TYPE (stmt
) = void_type_node
;
35432 OMP_SINGLE_CLAUSES (stmt
)
35433 = cp_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
35434 "#pragma omp single", pragma_tok
);
35435 OMP_SINGLE_BODY (stmt
) = cp_parser_omp_structured_block (parser
, if_p
);
35437 return add_stmt (stmt
);
35441 # pragma omp task task-clause[optseq] new-line
35442 structured-block */
35444 #define OMP_TASK_CLAUSE_MASK \
35445 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
35446 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
35447 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
35448 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
35449 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
35450 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
35451 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
35452 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
35453 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
35454 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
35457 cp_parser_omp_task (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
35459 tree clauses
, block
;
35462 clauses
= cp_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
35463 "#pragma omp task", pragma_tok
);
35464 block
= begin_omp_task ();
35465 save
= cp_parser_begin_omp_structured_block (parser
);
35466 cp_parser_statement (parser
, NULL_TREE
, false, if_p
);
35467 cp_parser_end_omp_structured_block (parser
, save
);
35468 return finish_omp_task (clauses
, block
);
35472 # pragma omp taskwait new-line */
35475 cp_parser_omp_taskwait (cp_parser
*parser
, cp_token
*pragma_tok
)
35477 cp_parser_require_pragma_eol (parser
, pragma_tok
);
35478 finish_omp_taskwait ();
35482 # pragma omp taskyield new-line */
35485 cp_parser_omp_taskyield (cp_parser
*parser
, cp_token
*pragma_tok
)
35487 cp_parser_require_pragma_eol (parser
, pragma_tok
);
35488 finish_omp_taskyield ();
35492 # pragma omp taskgroup new-line
35493 structured-block */
35496 cp_parser_omp_taskgroup (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
35498 cp_parser_require_pragma_eol (parser
, pragma_tok
);
35499 return c_finish_omp_taskgroup (input_location
,
35500 cp_parser_omp_structured_block (parser
,
35506 # pragma omp threadprivate (variable-list) */
35509 cp_parser_omp_threadprivate (cp_parser
*parser
, cp_token
*pragma_tok
)
35513 vars
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_ERROR
, NULL
);
35514 cp_parser_require_pragma_eol (parser
, pragma_tok
);
35516 finish_omp_threadprivate (vars
);
35520 # pragma omp cancel cancel-clause[optseq] new-line */
35522 #define OMP_CANCEL_CLAUSE_MASK \
35523 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
35524 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
35525 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
35526 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
35527 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
35530 cp_parser_omp_cancel (cp_parser
*parser
, cp_token
*pragma_tok
)
35532 tree clauses
= cp_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
35533 "#pragma omp cancel", pragma_tok
);
35534 finish_omp_cancel (clauses
);
35538 # pragma omp cancellation point cancelpt-clause[optseq] new-line */
35540 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
35541 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
35542 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
35543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
35544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
35547 cp_parser_omp_cancellation_point (cp_parser
*parser
, cp_token
*pragma_tok
,
35548 enum pragma_context context
)
35551 bool point_seen
= false;
35553 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
35555 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
35556 const char *p
= IDENTIFIER_POINTER (id
);
35558 if (strcmp (p
, "point") == 0)
35560 cp_lexer_consume_token (parser
->lexer
);
35566 cp_parser_error (parser
, "expected %<point%>");
35567 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35571 if (context
!= pragma_compound
)
35573 if (context
== pragma_stmt
)
35574 error_at (pragma_tok
->location
,
35575 "%<#pragma %s%> may only be used in compound statements",
35576 "omp cancellation point");
35578 cp_parser_error (parser
, "expected declaration specifiers");
35579 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35583 clauses
= cp_parser_omp_all_clauses (parser
,
35584 OMP_CANCELLATION_POINT_CLAUSE_MASK
,
35585 "#pragma omp cancellation point",
35587 finish_omp_cancellation_point (clauses
);
35591 #pragma omp distribute distribute-clause[optseq] new-line
35594 #define OMP_DISTRIBUTE_CLAUSE_MASK \
35595 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
35596 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
35597 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
35598 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
35599 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
35602 cp_parser_omp_distribute (cp_parser
*parser
, cp_token
*pragma_tok
,
35603 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
35606 tree clauses
, sb
, ret
;
35608 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
35610 strcat (p_name
, " distribute");
35611 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
35613 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
35615 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
35616 const char *p
= IDENTIFIER_POINTER (id
);
35618 bool parallel
= false;
35620 if (strcmp (p
, "simd") == 0)
35623 parallel
= strcmp (p
, "parallel") == 0;
35624 if (parallel
|| simd
)
35626 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
35627 if (cclauses
== NULL
)
35628 cclauses
= cclauses_buf
;
35629 cp_lexer_consume_token (parser
->lexer
);
35630 if (!flag_openmp
) /* flag_openmp_simd */
35633 return cp_parser_omp_simd (parser
, pragma_tok
, p_name
, mask
,
35636 return cp_parser_omp_parallel (parser
, pragma_tok
, p_name
, mask
,
35639 sb
= begin_omp_structured_block ();
35640 save
= cp_parser_begin_omp_structured_block (parser
);
35642 ret
= cp_parser_omp_simd (parser
, pragma_tok
, p_name
, mask
,
35645 ret
= cp_parser_omp_parallel (parser
, pragma_tok
, p_name
, mask
,
35647 cp_parser_end_omp_structured_block (parser
, save
);
35648 tree body
= finish_omp_structured_block (sb
);
35651 ret
= make_node (OMP_DISTRIBUTE
);
35652 TREE_TYPE (ret
) = void_type_node
;
35653 OMP_FOR_BODY (ret
) = body
;
35654 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
35655 SET_EXPR_LOCATION (ret
, loc
);
35660 if (!flag_openmp
) /* flag_openmp_simd */
35662 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35666 clauses
= cp_parser_omp_all_clauses (parser
, mask
, p_name
, pragma_tok
,
35670 cp_omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
35671 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
35674 sb
= begin_omp_structured_block ();
35675 save
= cp_parser_begin_omp_structured_block (parser
);
35677 ret
= cp_parser_omp_for_loop (parser
, OMP_DISTRIBUTE
, clauses
, NULL
, if_p
);
35679 cp_parser_end_omp_structured_block (parser
, save
);
35680 add_stmt (finish_omp_structured_block (sb
));
35686 # pragma omp teams teams-clause[optseq] new-line
35687 structured-block */
35689 #define OMP_TEAMS_CLAUSE_MASK \
35690 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
35691 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
35692 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
35693 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
35694 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
35695 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
35696 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
35699 cp_parser_omp_teams (cp_parser
*parser
, cp_token
*pragma_tok
,
35700 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
35703 tree clauses
, sb
, ret
;
35705 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
35707 strcat (p_name
, " teams");
35708 mask
|= OMP_TEAMS_CLAUSE_MASK
;
35710 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
35712 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
35713 const char *p
= IDENTIFIER_POINTER (id
);
35714 if (strcmp (p
, "distribute") == 0)
35716 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
35717 if (cclauses
== NULL
)
35718 cclauses
= cclauses_buf
;
35720 cp_lexer_consume_token (parser
->lexer
);
35721 if (!flag_openmp
) /* flag_openmp_simd */
35722 return cp_parser_omp_distribute (parser
, pragma_tok
, p_name
, mask
,
35724 sb
= begin_omp_structured_block ();
35725 save
= cp_parser_begin_omp_structured_block (parser
);
35726 ret
= cp_parser_omp_distribute (parser
, pragma_tok
, p_name
, mask
,
35728 cp_parser_end_omp_structured_block (parser
, save
);
35729 tree body
= finish_omp_structured_block (sb
);
35732 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
35733 ret
= make_node (OMP_TEAMS
);
35734 TREE_TYPE (ret
) = void_type_node
;
35735 OMP_TEAMS_CLAUSES (ret
) = clauses
;
35736 OMP_TEAMS_BODY (ret
) = body
;
35737 OMP_TEAMS_COMBINED (ret
) = 1;
35738 SET_EXPR_LOCATION (ret
, loc
);
35739 return add_stmt (ret
);
35742 if (!flag_openmp
) /* flag_openmp_simd */
35744 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35748 clauses
= cp_parser_omp_all_clauses (parser
, mask
, p_name
, pragma_tok
,
35752 cp_omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
35753 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
35756 tree stmt
= make_node (OMP_TEAMS
);
35757 TREE_TYPE (stmt
) = void_type_node
;
35758 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
35759 OMP_TEAMS_BODY (stmt
) = cp_parser_omp_structured_block (parser
, if_p
);
35760 SET_EXPR_LOCATION (stmt
, loc
);
35762 return add_stmt (stmt
);
35766 # pragma omp target data target-data-clause[optseq] new-line
35767 structured-block */
35769 #define OMP_TARGET_DATA_CLAUSE_MASK \
35770 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
35771 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
35772 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
35773 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
35776 cp_parser_omp_target_data (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
35779 = cp_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
35780 "#pragma omp target data", pragma_tok
);
35782 for (tree
*pc
= &clauses
; *pc
;)
35784 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
35785 switch (OMP_CLAUSE_MAP_KIND (*pc
))
35788 case GOMP_MAP_ALWAYS_TO
:
35789 case GOMP_MAP_FROM
:
35790 case GOMP_MAP_ALWAYS_FROM
:
35791 case GOMP_MAP_TOFROM
:
35792 case GOMP_MAP_ALWAYS_TOFROM
:
35793 case GOMP_MAP_ALLOC
:
35796 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
35797 case GOMP_MAP_FIRSTPRIVATE_REFERENCE
:
35798 case GOMP_MAP_ALWAYS_POINTER
:
35802 error_at (OMP_CLAUSE_LOCATION (*pc
),
35803 "%<#pragma omp target data%> with map-type other "
35804 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
35805 "on %<map%> clause");
35806 *pc
= OMP_CLAUSE_CHAIN (*pc
);
35809 pc
= &OMP_CLAUSE_CHAIN (*pc
);
35815 error_at (pragma_tok
->location
,
35816 "%<#pragma omp target data%> must contain at least "
35817 "one %<map%> clause");
35821 tree stmt
= make_node (OMP_TARGET_DATA
);
35822 TREE_TYPE (stmt
) = void_type_node
;
35823 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
35825 keep_next_level (true);
35826 OMP_TARGET_DATA_BODY (stmt
) = cp_parser_omp_structured_block (parser
, if_p
);
35828 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
35829 return add_stmt (stmt
);
35833 # pragma omp target enter data target-enter-data-clause[optseq] new-line
35834 structured-block */
35836 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
35837 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
35838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
35839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
35840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
35841 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
35844 cp_parser_omp_target_enter_data (cp_parser
*parser
, cp_token
*pragma_tok
,
35845 enum pragma_context context
)
35847 bool data_seen
= false;
35848 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
35850 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
35851 const char *p
= IDENTIFIER_POINTER (id
);
35853 if (strcmp (p
, "data") == 0)
35855 cp_lexer_consume_token (parser
->lexer
);
35861 cp_parser_error (parser
, "expected %<data%>");
35862 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35866 if (context
== pragma_stmt
)
35868 error_at (pragma_tok
->location
,
35869 "%<#pragma %s%> may only be used in compound statements",
35870 "omp target enter data");
35871 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35876 = cp_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
35877 "#pragma omp target enter data", pragma_tok
);
35879 for (tree
*pc
= &clauses
; *pc
;)
35881 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
35882 switch (OMP_CLAUSE_MAP_KIND (*pc
))
35885 case GOMP_MAP_ALWAYS_TO
:
35886 case GOMP_MAP_ALLOC
:
35889 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
35890 case GOMP_MAP_FIRSTPRIVATE_REFERENCE
:
35891 case GOMP_MAP_ALWAYS_POINTER
:
35895 error_at (OMP_CLAUSE_LOCATION (*pc
),
35896 "%<#pragma omp target enter data%> with map-type other "
35897 "than %<to%> or %<alloc%> on %<map%> clause");
35898 *pc
= OMP_CLAUSE_CHAIN (*pc
);
35901 pc
= &OMP_CLAUSE_CHAIN (*pc
);
35907 error_at (pragma_tok
->location
,
35908 "%<#pragma omp target enter data%> must contain at least "
35909 "one %<map%> clause");
35913 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
35914 TREE_TYPE (stmt
) = void_type_node
;
35915 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
35916 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
35917 return add_stmt (stmt
);
35921 # pragma omp target exit data target-enter-data-clause[optseq] new-line
35922 structured-block */
35924 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
35925 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
35926 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
35927 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
35928 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
35929 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
35932 cp_parser_omp_target_exit_data (cp_parser
*parser
, cp_token
*pragma_tok
,
35933 enum pragma_context context
)
35935 bool data_seen
= false;
35936 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
35938 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
35939 const char *p
= IDENTIFIER_POINTER (id
);
35941 if (strcmp (p
, "data") == 0)
35943 cp_lexer_consume_token (parser
->lexer
);
35949 cp_parser_error (parser
, "expected %<data%>");
35950 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35954 if (context
== pragma_stmt
)
35956 error_at (pragma_tok
->location
,
35957 "%<#pragma %s%> may only be used in compound statements",
35958 "omp target exit data");
35959 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
35964 = cp_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
35965 "#pragma omp target exit data", pragma_tok
);
35967 for (tree
*pc
= &clauses
; *pc
;)
35969 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
35970 switch (OMP_CLAUSE_MAP_KIND (*pc
))
35972 case GOMP_MAP_FROM
:
35973 case GOMP_MAP_ALWAYS_FROM
:
35974 case GOMP_MAP_RELEASE
:
35975 case GOMP_MAP_DELETE
:
35978 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
35979 case GOMP_MAP_FIRSTPRIVATE_REFERENCE
:
35980 case GOMP_MAP_ALWAYS_POINTER
:
35984 error_at (OMP_CLAUSE_LOCATION (*pc
),
35985 "%<#pragma omp target exit data%> with map-type other "
35986 "than %<from%>, %<release%> or %<delete%> on %<map%>"
35988 *pc
= OMP_CLAUSE_CHAIN (*pc
);
35991 pc
= &OMP_CLAUSE_CHAIN (*pc
);
35997 error_at (pragma_tok
->location
,
35998 "%<#pragma omp target exit data%> must contain at least "
35999 "one %<map%> clause");
36003 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
36004 TREE_TYPE (stmt
) = void_type_node
;
36005 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
36006 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
36007 return add_stmt (stmt
);
36011 # pragma omp target update target-update-clause[optseq] new-line */
36013 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
36014 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
36015 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
36016 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
36017 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
36018 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
36019 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
36022 cp_parser_omp_target_update (cp_parser
*parser
, cp_token
*pragma_tok
,
36023 enum pragma_context context
)
36025 if (context
== pragma_stmt
)
36027 error_at (pragma_tok
->location
,
36028 "%<#pragma %s%> may only be used in compound statements",
36029 "omp target update");
36030 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
36035 = cp_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
36036 "#pragma omp target update", pragma_tok
);
36037 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
36038 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
36040 error_at (pragma_tok
->location
,
36041 "%<#pragma omp target update%> must contain at least one "
36042 "%<from%> or %<to%> clauses");
36046 tree stmt
= make_node (OMP_TARGET_UPDATE
);
36047 TREE_TYPE (stmt
) = void_type_node
;
36048 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
36049 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
36055 # pragma omp target target-clause[optseq] new-line
36056 structured-block */
36058 #define OMP_TARGET_CLAUSE_MASK \
36059 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
36060 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
36061 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
36062 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
36063 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
36064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
36065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
36066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
36067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
36070 cp_parser_omp_target (cp_parser
*parser
, cp_token
*pragma_tok
,
36071 enum pragma_context context
, bool *if_p
)
36073 tree
*pc
= NULL
, stmt
;
36075 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
36077 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
36078 const char *p
= IDENTIFIER_POINTER (id
);
36079 enum tree_code ccode
= ERROR_MARK
;
36081 if (strcmp (p
, "teams") == 0)
36083 else if (strcmp (p
, "parallel") == 0)
36084 ccode
= OMP_PARALLEL
;
36085 else if (strcmp (p
, "simd") == 0)
36087 if (ccode
!= ERROR_MARK
)
36089 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
36090 char p_name
[sizeof ("#pragma omp target teams distribute "
36091 "parallel for simd")];
36093 cp_lexer_consume_token (parser
->lexer
);
36094 strcpy (p_name
, "#pragma omp target");
36095 if (!flag_openmp
) /* flag_openmp_simd */
36101 stmt
= cp_parser_omp_teams (parser
, pragma_tok
, p_name
,
36102 OMP_TARGET_CLAUSE_MASK
,
36106 stmt
= cp_parser_omp_parallel (parser
, pragma_tok
, p_name
,
36107 OMP_TARGET_CLAUSE_MASK
,
36111 stmt
= cp_parser_omp_simd (parser
, pragma_tok
, p_name
,
36112 OMP_TARGET_CLAUSE_MASK
,
36116 gcc_unreachable ();
36118 return stmt
!= NULL_TREE
;
36120 keep_next_level (true);
36121 tree sb
= begin_omp_structured_block (), ret
;
36122 unsigned save
= cp_parser_begin_omp_structured_block (parser
);
36126 ret
= cp_parser_omp_teams (parser
, pragma_tok
, p_name
,
36127 OMP_TARGET_CLAUSE_MASK
, cclauses
,
36131 ret
= cp_parser_omp_parallel (parser
, pragma_tok
, p_name
,
36132 OMP_TARGET_CLAUSE_MASK
, cclauses
,
36136 ret
= cp_parser_omp_simd (parser
, pragma_tok
, p_name
,
36137 OMP_TARGET_CLAUSE_MASK
, cclauses
,
36141 gcc_unreachable ();
36143 cp_parser_end_omp_structured_block (parser
, save
);
36144 tree body
= finish_omp_structured_block (sb
);
36145 if (ret
== NULL_TREE
)
36147 if (ccode
== OMP_TEAMS
&& !processing_template_decl
)
36149 /* For combined target teams, ensure the num_teams and
36150 thread_limit clause expressions are evaluated on the host,
36151 before entering the target construct. */
36153 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
36154 c
; c
= OMP_CLAUSE_CHAIN (c
))
36155 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
36156 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
36157 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
36159 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
36160 expr
= force_target_expr (TREE_TYPE (expr
), expr
, tf_none
);
36161 if (expr
== error_mark_node
)
36163 tree tmp
= TARGET_EXPR_SLOT (expr
);
36165 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
36166 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
36167 OMP_CLAUSE_FIRSTPRIVATE
);
36168 OMP_CLAUSE_DECL (tc
) = tmp
;
36169 OMP_CLAUSE_CHAIN (tc
)
36170 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
36171 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
36174 tree stmt
= make_node (OMP_TARGET
);
36175 TREE_TYPE (stmt
) = void_type_node
;
36176 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
36177 OMP_TARGET_BODY (stmt
) = body
;
36178 OMP_TARGET_COMBINED (stmt
) = 1;
36179 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
36181 pc
= &OMP_TARGET_CLAUSES (stmt
);
36182 goto check_clauses
;
36184 else if (!flag_openmp
) /* flag_openmp_simd */
36186 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
36189 else if (strcmp (p
, "data") == 0)
36191 cp_lexer_consume_token (parser
->lexer
);
36192 cp_parser_omp_target_data (parser
, pragma_tok
, if_p
);
36195 else if (strcmp (p
, "enter") == 0)
36197 cp_lexer_consume_token (parser
->lexer
);
36198 cp_parser_omp_target_enter_data (parser
, pragma_tok
, context
);
36201 else if (strcmp (p
, "exit") == 0)
36203 cp_lexer_consume_token (parser
->lexer
);
36204 cp_parser_omp_target_exit_data (parser
, pragma_tok
, context
);
36207 else if (strcmp (p
, "update") == 0)
36209 cp_lexer_consume_token (parser
->lexer
);
36210 return cp_parser_omp_target_update (parser
, pragma_tok
, context
);
36213 if (!flag_openmp
) /* flag_openmp_simd */
36215 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
36219 stmt
= make_node (OMP_TARGET
);
36220 TREE_TYPE (stmt
) = void_type_node
;
36222 OMP_TARGET_CLAUSES (stmt
)
36223 = cp_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
36224 "#pragma omp target", pragma_tok
);
36225 pc
= &OMP_TARGET_CLAUSES (stmt
);
36226 keep_next_level (true);
36227 OMP_TARGET_BODY (stmt
) = cp_parser_omp_structured_block (parser
, if_p
);
36229 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
36235 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
36236 switch (OMP_CLAUSE_MAP_KIND (*pc
))
36239 case GOMP_MAP_ALWAYS_TO
:
36240 case GOMP_MAP_FROM
:
36241 case GOMP_MAP_ALWAYS_FROM
:
36242 case GOMP_MAP_TOFROM
:
36243 case GOMP_MAP_ALWAYS_TOFROM
:
36244 case GOMP_MAP_ALLOC
:
36245 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
36246 case GOMP_MAP_FIRSTPRIVATE_REFERENCE
:
36247 case GOMP_MAP_ALWAYS_POINTER
:
36250 error_at (OMP_CLAUSE_LOCATION (*pc
),
36251 "%<#pragma omp target%> with map-type other "
36252 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
36253 "on %<map%> clause");
36254 *pc
= OMP_CLAUSE_CHAIN (*pc
);
36257 pc
= &OMP_CLAUSE_CHAIN (*pc
);
36263 # pragma acc cache (variable-list) new-line
36267 cp_parser_oacc_cache (cp_parser
*parser
, cp_token
*pragma_tok
)
36269 tree stmt
, clauses
;
36271 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE__CACHE_
, NULL_TREE
);
36272 clauses
= finish_omp_clauses (clauses
, C_ORT_ACC
);
36274 cp_parser_require_pragma_eol (parser
, cp_lexer_peek_token (parser
->lexer
));
36276 stmt
= make_node (OACC_CACHE
);
36277 TREE_TYPE (stmt
) = void_type_node
;
36278 OACC_CACHE_CLAUSES (stmt
) = clauses
;
36279 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
36286 # pragma acc data oacc-data-clause[optseq] new-line
36287 structured-block */
36289 #define OACC_DATA_CLAUSE_MASK \
36290 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
36291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
36292 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
36293 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
36294 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
36295 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
36296 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
36297 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
36298 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
36299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
36300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE))
36303 cp_parser_oacc_data (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
36305 tree stmt
, clauses
, block
;
36308 clauses
= cp_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
36309 "#pragma acc data", pragma_tok
);
36311 block
= begin_omp_parallel ();
36312 save
= cp_parser_begin_omp_structured_block (parser
);
36313 cp_parser_statement (parser
, NULL_TREE
, false, if_p
);
36314 cp_parser_end_omp_structured_block (parser
, save
);
36315 stmt
= finish_oacc_data (clauses
, block
);
36320 # pragma acc host_data <clauses> new-line
36321 structured-block */
36323 #define OACC_HOST_DATA_CLAUSE_MASK \
36324 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
36327 cp_parser_oacc_host_data (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
36329 tree stmt
, clauses
, block
;
36332 clauses
= cp_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
36333 "#pragma acc host_data", pragma_tok
);
36335 block
= begin_omp_parallel ();
36336 save
= cp_parser_begin_omp_structured_block (parser
);
36337 cp_parser_statement (parser
, NULL_TREE
, false, if_p
);
36338 cp_parser_end_omp_structured_block (parser
, save
);
36339 stmt
= finish_oacc_host_data (clauses
, block
);
36344 # pragma acc declare oacc-data-clause[optseq] new-line
36347 #define OACC_DECLARE_CLAUSE_MASK \
36348 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
36349 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
36350 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
36351 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
36352 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
36353 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
36354 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
36355 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
36356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
36357 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
36358 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
36359 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE))
36362 cp_parser_oacc_declare (cp_parser
*parser
, cp_token
*pragma_tok
)
36364 tree clauses
, stmt
;
36365 bool error
= false;
36367 clauses
= cp_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
36368 "#pragma acc declare", pragma_tok
, true);
36371 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
36373 error_at (pragma_tok
->location
,
36374 "no valid clauses specified in %<#pragma acc declare%>");
36378 for (tree t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
36380 location_t loc
= OMP_CLAUSE_LOCATION (t
);
36381 tree decl
= OMP_CLAUSE_DECL (t
);
36382 if (!DECL_P (decl
))
36384 error_at (loc
, "array section in %<#pragma acc declare%>");
36388 gcc_assert (OMP_CLAUSE_CODE (t
) == OMP_CLAUSE_MAP
);
36389 switch (OMP_CLAUSE_MAP_KIND (t
))
36391 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
36392 case GOMP_MAP_FORCE_ALLOC
:
36393 case GOMP_MAP_FORCE_TO
:
36394 case GOMP_MAP_FORCE_DEVICEPTR
:
36395 case GOMP_MAP_DEVICE_RESIDENT
:
36398 case GOMP_MAP_LINK
:
36399 if (!global_bindings_p ()
36400 && (TREE_STATIC (decl
)
36401 || !DECL_EXTERNAL (decl
)))
36404 "%qD must be a global variable in "
36405 "%<#pragma acc declare link%>",
36413 if (global_bindings_p ())
36415 error_at (loc
, "invalid OpenACC clause at file scope");
36419 if (DECL_EXTERNAL (decl
))
36422 "invalid use of %<extern%> variable %qD "
36423 "in %<#pragma acc declare%>", decl
);
36427 else if (TREE_PUBLIC (decl
))
36430 "invalid use of %<global%> variable %qD "
36431 "in %<#pragma acc declare%>", decl
);
36438 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
36439 || lookup_attribute ("omp declare target link",
36440 DECL_ATTRIBUTES (decl
)))
36442 error_at (loc
, "variable %qD used more than once with "
36443 "%<#pragma acc declare%>", decl
);
36452 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
36453 id
= get_identifier ("omp declare target link");
36455 id
= get_identifier ("omp declare target");
36457 DECL_ATTRIBUTES (decl
)
36458 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
36459 if (global_bindings_p ())
36461 symtab_node
*node
= symtab_node::get (decl
);
36464 node
->offloadable
= 1;
36465 if (ENABLE_OFFLOADING
)
36467 g
->have_offload
= true;
36468 if (is_a
<varpool_node
*> (node
))
36469 vec_safe_push (offload_vars
, decl
);
36476 if (error
|| global_bindings_p ())
36479 stmt
= make_node (OACC_DECLARE
);
36480 TREE_TYPE (stmt
) = void_type_node
;
36481 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
36482 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
36490 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
36494 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
36496 LOC is the location of the #pragma token.
36499 #define OACC_ENTER_DATA_CLAUSE_MASK \
36500 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
36501 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
36502 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
36503 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
36504 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
36505 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
36506 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
36508 #define OACC_EXIT_DATA_CLAUSE_MASK \
36509 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
36510 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
36511 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
36512 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
36513 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
36516 cp_parser_oacc_enter_exit_data (cp_parser
*parser
, cp_token
*pragma_tok
,
36519 location_t loc
= pragma_tok
->location
;
36520 tree stmt
, clauses
;
36521 const char *p
= "";
36523 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
36524 p
= IDENTIFIER_POINTER (cp_lexer_peek_token (parser
->lexer
)->u
.value
);
36526 if (strcmp (p
, "data") != 0)
36528 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
36529 enter
? "enter" : "exit");
36530 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
36534 cp_lexer_consume_token (parser
->lexer
);
36537 clauses
= cp_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
36538 "#pragma acc enter data", pragma_tok
);
36540 clauses
= cp_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
36541 "#pragma acc exit data", pragma_tok
);
36543 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
36545 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
36546 enter
? "enter" : "exit");
36550 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
36551 TREE_TYPE (stmt
) = void_type_node
;
36552 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
36553 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
36559 # pragma acc loop oacc-loop-clause[optseq] new-line
36560 structured-block */
36562 #define OACC_LOOP_CLAUSE_MASK \
36563 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
36564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
36565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
36566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
36567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
36568 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
36569 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
36570 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
36571 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
36572 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE))
36575 cp_parser_oacc_loop (cp_parser
*parser
, cp_token
*pragma_tok
, char *p_name
,
36576 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
36578 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
36580 strcat (p_name
, " loop");
36581 mask
|= OACC_LOOP_CLAUSE_MASK
;
36583 tree clauses
= cp_parser_oacc_all_clauses (parser
, mask
, p_name
, pragma_tok
,
36587 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
36589 *cclauses
= finish_omp_clauses (*cclauses
, C_ORT_ACC
);
36591 clauses
= finish_omp_clauses (clauses
, C_ORT_ACC
);
36594 tree block
= begin_omp_structured_block ();
36595 int save
= cp_parser_begin_omp_structured_block (parser
);
36596 tree stmt
= cp_parser_omp_for_loop (parser
, OACC_LOOP
, clauses
, NULL
, if_p
);
36597 cp_parser_end_omp_structured_block (parser
, save
);
36598 add_stmt (finish_omp_structured_block (block
));
36604 # pragma acc kernels oacc-kernels-clause[optseq] new-line
36609 # pragma acc parallel oacc-parallel-clause[optseq] new-line
36613 #define OACC_KERNELS_CLAUSE_MASK \
36614 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
36615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
36616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
36617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
36618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
36619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
36620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
36621 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
36622 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
36623 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
36624 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
36625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
36626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
36627 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
36628 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
36629 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
36630 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
36632 #define OACC_PARALLEL_CLAUSE_MASK \
36633 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
36634 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
36635 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
36636 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
36637 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
36638 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
36639 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
36640 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
36641 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
36642 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
36643 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
36644 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
36645 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
36646 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
36647 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
36648 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
36649 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
36650 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
36651 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
36652 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
36655 cp_parser_oacc_kernels_parallel (cp_parser
*parser
, cp_token
*pragma_tok
,
36656 char *p_name
, bool *if_p
)
36658 omp_clause_mask mask
;
36659 enum tree_code code
;
36660 switch (cp_parser_pragma_kind (pragma_tok
))
36662 case PRAGMA_OACC_KERNELS
:
36663 strcat (p_name
, " kernels");
36664 mask
= OACC_KERNELS_CLAUSE_MASK
;
36665 code
= OACC_KERNELS
;
36667 case PRAGMA_OACC_PARALLEL
:
36668 strcat (p_name
, " parallel");
36669 mask
= OACC_PARALLEL_CLAUSE_MASK
;
36670 code
= OACC_PARALLEL
;
36673 gcc_unreachable ();
36676 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
36679 = IDENTIFIER_POINTER (cp_lexer_peek_token (parser
->lexer
)->u
.value
);
36680 if (strcmp (p
, "loop") == 0)
36682 cp_lexer_consume_token (parser
->lexer
);
36683 tree block
= begin_omp_parallel ();
36685 cp_parser_oacc_loop (parser
, pragma_tok
, p_name
, mask
, &clauses
,
36687 return finish_omp_construct (code
, block
, clauses
);
36691 tree clauses
= cp_parser_oacc_all_clauses (parser
, mask
, p_name
, pragma_tok
);
36693 tree block
= begin_omp_parallel ();
36694 unsigned int save
= cp_parser_begin_omp_structured_block (parser
);
36695 cp_parser_statement (parser
, NULL_TREE
, false, if_p
);
36696 cp_parser_end_omp_structured_block (parser
, save
);
36697 return finish_omp_construct (code
, block
, clauses
);
36701 # pragma acc update oacc-update-clause[optseq] new-line
36704 #define OACC_UPDATE_CLAUSE_MASK \
36705 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
36706 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
36707 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
36708 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
36709 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
36710 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT))
36713 cp_parser_oacc_update (cp_parser
*parser
, cp_token
*pragma_tok
)
36715 tree stmt
, clauses
;
36717 clauses
= cp_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
36718 "#pragma acc update", pragma_tok
);
36720 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
36722 error_at (pragma_tok
->location
,
36723 "%<#pragma acc update%> must contain at least one "
36724 "%<device%> or %<host%> or %<self%> clause");
36728 stmt
= make_node (OACC_UPDATE
);
36729 TREE_TYPE (stmt
) = void_type_node
;
36730 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
36731 SET_EXPR_LOCATION (stmt
, pragma_tok
->location
);
36737 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
36739 LOC is the location of the #pragma token.
36742 #define OACC_WAIT_CLAUSE_MASK \
36743 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC))
36746 cp_parser_oacc_wait (cp_parser
*parser
, cp_token
*pragma_tok
)
36748 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
36749 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
36751 if (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_OPEN_PAREN
)
36752 list
= cp_parser_oacc_wait_list (parser
, loc
, list
);
36754 clauses
= cp_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
,
36755 "#pragma acc wait", pragma_tok
);
36757 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
36758 stmt
= finish_expr_stmt (stmt
);
36764 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
36766 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
36767 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
36768 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
36769 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
36770 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
36771 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
36772 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
36775 cp_parser_omp_declare_simd (cp_parser
*parser
, cp_token
*pragma_tok
,
36776 enum pragma_context context
)
36778 bool first_p
= parser
->omp_declare_simd
== NULL
;
36779 cp_omp_declare_simd_data data
;
36782 data
.error_seen
= false;
36783 data
.fndecl_seen
= false;
36784 data
.tokens
= vNULL
;
36785 data
.clauses
= NULL_TREE
;
36786 /* It is safe to take the address of a local variable; it will only be
36787 used while this scope is live. */
36788 parser
->omp_declare_simd
= &data
;
36791 /* Store away all pragma tokens. */
36792 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
)
36793 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_EOF
))
36794 cp_lexer_consume_token (parser
->lexer
);
36795 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
))
36796 parser
->omp_declare_simd
->error_seen
= true;
36797 cp_parser_require_pragma_eol (parser
, pragma_tok
);
36798 struct cp_token_cache
*cp
36799 = cp_token_cache_new (pragma_tok
, cp_lexer_peek_token (parser
->lexer
));
36800 parser
->omp_declare_simd
->tokens
.safe_push (cp
);
36804 while (cp_lexer_next_token_is (parser
->lexer
, CPP_PRAGMA
))
36805 cp_parser_pragma (parser
, context
, NULL
);
36808 case pragma_external
:
36809 cp_parser_declaration (parser
);
36811 case pragma_member
:
36812 cp_parser_member_declaration (parser
);
36814 case pragma_objc_icode
:
36815 cp_parser_block_declaration (parser
, /*statement_p=*/false);
36818 cp_parser_declaration_statement (parser
);
36821 if (parser
->omp_declare_simd
36822 && !parser
->omp_declare_simd
->error_seen
36823 && !parser
->omp_declare_simd
->fndecl_seen
)
36824 error_at (pragma_tok
->location
,
36825 "%<#pragma omp declare simd%> not immediately followed by "
36826 "function declaration or definition");
36827 data
.tokens
.release ();
36828 parser
->omp_declare_simd
= NULL
;
36832 /* Handles the delayed parsing of the Cilk Plus SIMD-enabled function.
36833 This function is modelled similar to the late parsing of omp declare
36837 cp_parser_late_parsing_cilk_simd_fn_info (cp_parser
*parser
, tree attrs
)
36839 struct cp_token_cache
*ce
;
36840 cp_omp_declare_simd_data
*info
= parser
->cilk_simd_fn_info
;
36843 if (parser
->omp_declare_simd
!= NULL
36844 || lookup_attribute ("simd", attrs
))
36846 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
36847 "used in the same function marked as a Cilk Plus SIMD-enabled "
36849 parser
->cilk_simd_fn_info
->tokens
.release ();
36850 XDELETE (parser
->cilk_simd_fn_info
);
36851 parser
->cilk_simd_fn_info
= NULL
;
36854 if (!info
->error_seen
&& info
->fndecl_seen
)
36856 error ("vector attribute not immediately followed by a single function"
36857 " declaration or definition");
36858 info
->error_seen
= true;
36860 if (info
->error_seen
)
36863 FOR_EACH_VEC_ELT (info
->tokens
, ii
, ce
)
36867 cp_parser_push_lexer_for_tokens (parser
, ce
);
36868 parser
->lexer
->in_pragma
= true;
36869 cl
= cp_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
36870 "SIMD-enabled functions attribute",
36872 cp_parser_pop_lexer (parser
);
36874 cl
= tree_cons (NULL_TREE
, cl
, NULL_TREE
);
36876 c
= build_tree_list (get_identifier ("cilk simd function"), NULL_TREE
);
36877 TREE_CHAIN (c
) = attrs
;
36880 c
= build_tree_list (get_identifier ("omp declare simd"), cl
);
36881 TREE_CHAIN (c
) = attrs
;
36882 if (processing_template_decl
)
36883 ATTR_IS_DEPENDENT (c
) = 1;
36886 info
->fndecl_seen
= true;
36887 parser
->cilk_simd_fn_info
->tokens
.release ();
36888 XDELETE (parser
->cilk_simd_fn_info
);
36889 parser
->cilk_simd_fn_info
= NULL
;
36893 /* Finalize #pragma omp declare simd clauses after direct declarator has
36894 been parsed, and put that into "omp declare simd" attribute. */
36897 cp_parser_late_parsing_omp_declare_simd (cp_parser
*parser
, tree attrs
)
36899 struct cp_token_cache
*ce
;
36900 cp_omp_declare_simd_data
*data
= parser
->omp_declare_simd
;
36903 if (!data
->error_seen
&& data
->fndecl_seen
)
36905 error ("%<#pragma omp declare simd%> not immediately followed by "
36906 "a single function declaration or definition");
36907 data
->error_seen
= true;
36909 if (data
->error_seen
)
36912 FOR_EACH_VEC_ELT (data
->tokens
, i
, ce
)
36916 cp_parser_push_lexer_for_tokens (parser
, ce
);
36917 parser
->lexer
->in_pragma
= true;
36918 gcc_assert (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_PRAGMA
);
36919 cp_token
*pragma_tok
= cp_lexer_consume_token (parser
->lexer
);
36920 cp_lexer_consume_token (parser
->lexer
);
36921 cl
= cp_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
36922 "#pragma omp declare simd", pragma_tok
);
36923 cp_parser_pop_lexer (parser
);
36925 cl
= tree_cons (NULL_TREE
, cl
, NULL_TREE
);
36926 c
= build_tree_list (get_identifier ("omp declare simd"), cl
);
36927 TREE_CHAIN (c
) = attrs
;
36928 if (processing_template_decl
)
36929 ATTR_IS_DEPENDENT (c
) = 1;
36933 data
->fndecl_seen
= true;
36939 # pragma omp declare target new-line
36940 declarations and definitions
36941 # pragma omp end declare target new-line
36944 # pragma omp declare target ( extended-list ) new-line
36946 # pragma omp declare target declare-target-clauses[seq] new-line */
36948 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
36949 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
36950 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
36953 cp_parser_omp_declare_target (cp_parser
*parser
, cp_token
*pragma_tok
)
36955 tree clauses
= NULL_TREE
;
36956 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
36958 = cp_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
36959 "#pragma omp declare target", pragma_tok
);
36960 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
36962 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_TO_DECLARE
,
36964 clauses
= finish_omp_clauses (clauses
, C_ORT_OMP
);
36965 cp_parser_require_pragma_eol (parser
, pragma_tok
);
36969 cp_parser_require_pragma_eol (parser
, pragma_tok
);
36970 scope_chain
->omp_declare_target_attribute
++;
36973 if (scope_chain
->omp_declare_target_attribute
)
36974 error_at (pragma_tok
->location
,
36975 "%<#pragma omp declare target%> with clauses in between "
36976 "%<#pragma omp declare target%> without clauses and "
36977 "%<#pragma omp end declare target%>");
36978 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
36980 tree t
= OMP_CLAUSE_DECL (c
), id
;
36981 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
36982 tree at2
= lookup_attribute ("omp declare target link",
36983 DECL_ATTRIBUTES (t
));
36984 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
36986 id
= get_identifier ("omp declare target link");
36987 std::swap (at1
, at2
);
36990 id
= get_identifier ("omp declare target");
36993 error_at (OMP_CLAUSE_LOCATION (c
),
36994 "%qD specified both in declare target %<link%> and %<to%>"
37000 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
37001 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
37004 symtab_node
*node
= symtab_node::get (t
);
37007 node
->offloadable
= 1;
37008 if (ENABLE_OFFLOADING
)
37010 g
->have_offload
= true;
37011 if (is_a
<varpool_node
*> (node
))
37012 vec_safe_push (offload_vars
, t
);
37020 cp_parser_omp_end_declare_target (cp_parser
*parser
, cp_token
*pragma_tok
)
37022 const char *p
= "";
37023 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
37025 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
37026 p
= IDENTIFIER_POINTER (id
);
37028 if (strcmp (p
, "declare") == 0)
37030 cp_lexer_consume_token (parser
->lexer
);
37032 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
37034 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
37035 p
= IDENTIFIER_POINTER (id
);
37037 if (strcmp (p
, "target") == 0)
37038 cp_lexer_consume_token (parser
->lexer
);
37041 cp_parser_error (parser
, "expected %<target%>");
37042 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
37048 cp_parser_error (parser
, "expected %<declare%>");
37049 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
37052 cp_parser_require_pragma_eol (parser
, pragma_tok
);
37053 if (!scope_chain
->omp_declare_target_attribute
)
37054 error_at (pragma_tok
->location
,
37055 "%<#pragma omp end declare target%> without corresponding "
37056 "%<#pragma omp declare target%>");
37058 scope_chain
->omp_declare_target_attribute
--;
37061 /* Helper function of cp_parser_omp_declare_reduction. Parse the combiner
37062 expression and optional initializer clause of
37063 #pragma omp declare reduction. We store the expression(s) as
37064 either 3, 6 or 7 special statements inside of the artificial function's
37065 body. The first two statements are DECL_EXPRs for the artificial
37066 OMP_OUT resp. OMP_IN variables, followed by a statement with the combiner
37067 expression that uses those variables.
37068 If there was any INITIALIZER clause, this is followed by further statements,
37069 the fourth and fifth statements are DECL_EXPRs for the artificial
37070 OMP_PRIV resp. OMP_ORIG variables. If the INITIALIZER clause wasn't the
37071 constructor variant (first token after open paren is not omp_priv),
37072 then the sixth statement is a statement with the function call expression
37073 that uses the OMP_PRIV and optionally OMP_ORIG variable.
37074 Otherwise, the sixth statement is whatever statement cp_finish_decl emits
37075 to initialize the OMP_PRIV artificial variable and there is seventh
37076 statement, a DECL_EXPR of the OMP_PRIV statement again. */
37079 cp_parser_omp_declare_reduction_exprs (tree fndecl
, cp_parser
*parser
)
37081 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
37082 gcc_assert (TREE_CODE (type
) == REFERENCE_TYPE
);
37083 type
= TREE_TYPE (type
);
37084 tree omp_out
= build_lang_decl (VAR_DECL
, get_identifier ("omp_out"), type
);
37085 DECL_ARTIFICIAL (omp_out
) = 1;
37086 pushdecl (omp_out
);
37087 add_decl_expr (omp_out
);
37088 tree omp_in
= build_lang_decl (VAR_DECL
, get_identifier ("omp_in"), type
);
37089 DECL_ARTIFICIAL (omp_in
) = 1;
37091 add_decl_expr (omp_in
);
37093 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
, initializer
= NULL_TREE
;
37095 keep_next_level (true);
37096 tree block
= begin_omp_structured_block ();
37097 combiner
= cp_parser_expression (parser
);
37098 finish_expr_stmt (combiner
);
37099 block
= finish_omp_structured_block (block
);
37102 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
37105 const char *p
= "";
37106 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
37108 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
37109 p
= IDENTIFIER_POINTER (id
);
37112 if (strcmp (p
, "initializer") == 0)
37114 cp_lexer_consume_token (parser
->lexer
);
37115 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
37119 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
37121 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
37122 p
= IDENTIFIER_POINTER (id
);
37125 omp_priv
= build_lang_decl (VAR_DECL
, get_identifier ("omp_priv"), type
);
37126 DECL_ARTIFICIAL (omp_priv
) = 1;
37127 pushdecl (omp_priv
);
37128 add_decl_expr (omp_priv
);
37129 omp_orig
= build_lang_decl (VAR_DECL
, get_identifier ("omp_orig"), type
);
37130 DECL_ARTIFICIAL (omp_orig
) = 1;
37131 pushdecl (omp_orig
);
37132 add_decl_expr (omp_orig
);
37134 keep_next_level (true);
37135 block
= begin_omp_structured_block ();
37138 if (strcmp (p
, "omp_priv") == 0)
37140 bool is_direct_init
, is_non_constant_init
;
37142 cp_lexer_consume_token (parser
->lexer
);
37143 /* Reject initializer (omp_priv) and initializer (omp_priv ()). */
37144 if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_PAREN
)
37145 || (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
)
37146 && cp_lexer_peek_nth_token (parser
->lexer
, 2)->type
37148 && cp_lexer_peek_nth_token (parser
->lexer
, 3)->type
37149 == CPP_CLOSE_PAREN
))
37151 finish_omp_structured_block (block
);
37152 error ("invalid initializer clause");
37155 initializer
= cp_parser_initializer (parser
, &is_direct_init
,
37156 &is_non_constant_init
);
37157 cp_finish_decl (omp_priv
, initializer
, !is_non_constant_init
,
37158 NULL_TREE
, LOOKUP_ONLYCONVERTING
);
37162 cp_parser_parse_tentatively (parser
);
37163 tree fn_name
= cp_parser_id_expression (parser
, /*template_p=*/false,
37164 /*check_dependency_p=*/true,
37165 /*template_p=*/NULL
,
37166 /*declarator_p=*/false,
37167 /*optional_p=*/false);
37168 vec
<tree
, va_gc
> *args
;
37169 if (fn_name
== error_mark_node
37170 || cp_parser_error_occurred (parser
)
37171 || !cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
)
37172 || ((args
= cp_parser_parenthesized_expression_list
37173 (parser
, non_attr
, /*cast_p=*/false,
37174 /*allow_expansion_p=*/true,
37175 /*non_constant_p=*/NULL
)),
37176 cp_parser_error_occurred (parser
)))
37178 finish_omp_structured_block (block
);
37179 cp_parser_abort_tentative_parse (parser
);
37180 cp_parser_error (parser
, "expected id-expression (arguments)");
37185 FOR_EACH_VEC_SAFE_ELT (args
, i
, arg
)
37186 if (arg
== omp_priv
37187 || (TREE_CODE (arg
) == ADDR_EXPR
37188 && TREE_OPERAND (arg
, 0) == omp_priv
))
37190 cp_parser_abort_tentative_parse (parser
);
37191 if (arg
== NULL_TREE
)
37192 error ("one of the initializer call arguments should be %<omp_priv%>"
37193 " or %<&omp_priv%>");
37194 initializer
= cp_parser_postfix_expression (parser
, false, false, false,
37196 finish_expr_stmt (initializer
);
37199 block
= finish_omp_structured_block (block
);
37200 cp_walk_tree (&block
, cp_remove_omp_priv_cleanup_stmt
, omp_priv
, NULL
);
37204 add_decl_expr (omp_orig
);
37206 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
37210 if (!cp_lexer_next_token_is (parser
->lexer
, CPP_PRAGMA_EOL
))
37211 cp_parser_required_error (parser
, RT_PRAGMA_EOL
, /*keyword=*/false);
37217 #pragma omp declare reduction (reduction-id : typename-list : expression) \
37218 initializer-clause[opt] new-line
37220 initializer-clause:
37221 initializer (omp_priv initializer)
37222 initializer (function-name (argument-list)) */
37225 cp_parser_omp_declare_reduction (cp_parser
*parser
, cp_token
*pragma_tok
,
37226 enum pragma_context
)
37228 auto_vec
<tree
> types
;
37229 enum tree_code reduc_code
= ERROR_MARK
;
37230 tree reduc_id
= NULL_TREE
, orig_reduc_id
= NULL_TREE
, type
;
37232 cp_token
*first_token
;
37233 cp_token_cache
*cp
;
37237 /* Get the high-water mark for the DECLARATOR_OBSTACK. */
37238 p
= obstack_alloc (&declarator_obstack
, 0);
37240 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
37243 switch (cp_lexer_peek_token (parser
->lexer
)->type
)
37246 reduc_code
= PLUS_EXPR
;
37249 reduc_code
= MULT_EXPR
;
37252 reduc_code
= MINUS_EXPR
;
37255 reduc_code
= BIT_AND_EXPR
;
37258 reduc_code
= BIT_XOR_EXPR
;
37261 reduc_code
= BIT_IOR_EXPR
;
37264 reduc_code
= TRUTH_ANDIF_EXPR
;
37267 reduc_code
= TRUTH_ORIF_EXPR
;
37270 reduc_id
= orig_reduc_id
= cp_parser_identifier (parser
);
37273 cp_parser_error (parser
, "expected %<+%>, %<*%>, %<-%>, %<&%>, %<^%>, "
37274 "%<|%>, %<&&%>, %<||%> or identifier");
37278 if (reduc_code
!= ERROR_MARK
)
37279 cp_lexer_consume_token (parser
->lexer
);
37281 reduc_id
= omp_reduction_id (reduc_code
, reduc_id
, NULL_TREE
);
37282 if (reduc_id
== error_mark_node
)
37285 if (!cp_parser_require (parser
, CPP_COLON
, RT_COLON
))
37288 /* Types may not be defined in declare reduction type list. */
37289 const char *saved_message
;
37290 saved_message
= parser
->type_definition_forbidden_message
;
37291 parser
->type_definition_forbidden_message
37292 = G_("types may not be defined in declare reduction type list");
37293 bool saved_colon_corrects_to_scope_p
;
37294 saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
37295 parser
->colon_corrects_to_scope_p
= false;
37296 bool saved_colon_doesnt_start_class_def_p
;
37297 saved_colon_doesnt_start_class_def_p
37298 = parser
->colon_doesnt_start_class_def_p
;
37299 parser
->colon_doesnt_start_class_def_p
= true;
37303 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
37304 type
= cp_parser_type_id (parser
);
37305 if (type
== error_mark_node
)
37307 else if (ARITHMETIC_TYPE_P (type
)
37308 && (orig_reduc_id
== NULL_TREE
37309 || (TREE_CODE (type
) != COMPLEX_TYPE
37310 && (id_equal (orig_reduc_id
, "min")
37311 || id_equal (orig_reduc_id
, "max")))))
37312 error_at (loc
, "predeclared arithmetic type %qT in "
37313 "%<#pragma omp declare reduction%>", type
);
37314 else if (TREE_CODE (type
) == FUNCTION_TYPE
37315 || TREE_CODE (type
) == METHOD_TYPE
37316 || TREE_CODE (type
) == ARRAY_TYPE
)
37317 error_at (loc
, "function or array type %qT in "
37318 "%<#pragma omp declare reduction%>", type
);
37319 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
37320 error_at (loc
, "reference type %qT in "
37321 "%<#pragma omp declare reduction%>", type
);
37322 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
37323 error_at (loc
, "const, volatile or __restrict qualified type %qT in "
37324 "%<#pragma omp declare reduction%>", type
);
37326 types
.safe_push (type
);
37328 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
37329 cp_lexer_consume_token (parser
->lexer
);
37334 /* Restore the saved message. */
37335 parser
->type_definition_forbidden_message
= saved_message
;
37336 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
37337 parser
->colon_doesnt_start_class_def_p
37338 = saved_colon_doesnt_start_class_def_p
;
37340 if (!cp_parser_require (parser
, CPP_COLON
, RT_COLON
)
37341 || types
.is_empty ())
37344 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
37348 first_token
= cp_lexer_peek_token (parser
->lexer
);
37351 FOR_EACH_VEC_ELT (types
, i
, type
)
37354 = build_function_type_list (void_type_node
,
37355 cp_build_reference_type (type
, false),
37357 tree this_reduc_id
= reduc_id
;
37358 if (!dependent_type_p (type
))
37359 this_reduc_id
= omp_reduction_id (ERROR_MARK
, reduc_id
, type
);
37360 tree fndecl
= build_lang_decl (FUNCTION_DECL
, this_reduc_id
, fntype
);
37361 DECL_SOURCE_LOCATION (fndecl
) = pragma_tok
->location
;
37362 DECL_ARTIFICIAL (fndecl
) = 1;
37363 DECL_EXTERNAL (fndecl
) = 1;
37364 DECL_DECLARED_INLINE_P (fndecl
) = 1;
37365 DECL_IGNORED_P (fndecl
) = 1;
37366 DECL_OMP_DECLARE_REDUCTION_P (fndecl
) = 1;
37367 SET_DECL_ASSEMBLER_NAME (fndecl
, get_identifier ("<udr>"));
37368 DECL_ATTRIBUTES (fndecl
)
37369 = tree_cons (get_identifier ("gnu_inline"), NULL_TREE
,
37370 DECL_ATTRIBUTES (fndecl
));
37371 if (processing_template_decl
)
37372 fndecl
= push_template_decl (fndecl
);
37373 bool block_scope
= false;
37374 tree block
= NULL_TREE
;
37375 if (current_function_decl
)
37377 block_scope
= true;
37378 DECL_CONTEXT (fndecl
) = global_namespace
;
37379 if (!processing_template_decl
)
37382 else if (current_class_type
)
37386 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
)
37387 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_EOF
))
37388 cp_lexer_consume_token (parser
->lexer
);
37389 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
))
37391 cp
= cp_token_cache_new (first_token
,
37392 cp_lexer_peek_nth_token (parser
->lexer
,
37395 DECL_STATIC_FUNCTION_P (fndecl
) = 1;
37396 finish_member_declaration (fndecl
);
37397 DECL_PENDING_INLINE_INFO (fndecl
) = cp
;
37398 DECL_PENDING_INLINE_P (fndecl
) = 1;
37399 vec_safe_push (unparsed_funs_with_definitions
, fndecl
);
37404 DECL_CONTEXT (fndecl
) = current_namespace
;
37408 start_preparsed_function (fndecl
, NULL_TREE
, SF_PRE_PARSED
);
37410 block
= begin_omp_structured_block ();
37413 cp_parser_push_lexer_for_tokens (parser
, cp
);
37414 parser
->lexer
->in_pragma
= true;
37416 if (!cp_parser_omp_declare_reduction_exprs (fndecl
, parser
))
37419 finish_function (0);
37421 DECL_CONTEXT (fndecl
) = current_function_decl
;
37423 cp_parser_pop_lexer (parser
);
37427 cp_parser_pop_lexer (parser
);
37429 finish_function (0);
37432 DECL_CONTEXT (fndecl
) = current_function_decl
;
37433 block
= finish_omp_structured_block (block
);
37434 if (TREE_CODE (block
) == BIND_EXPR
)
37435 DECL_SAVED_TREE (fndecl
) = BIND_EXPR_BODY (block
);
37436 else if (TREE_CODE (block
) == STATEMENT_LIST
)
37437 DECL_SAVED_TREE (fndecl
) = block
;
37438 if (processing_template_decl
)
37439 add_decl_expr (fndecl
);
37441 cp_check_omp_declare_reduction (fndecl
);
37442 if (cp
== NULL
&& types
.length () > 1)
37443 cp
= cp_token_cache_new (first_token
,
37444 cp_lexer_peek_nth_token (parser
->lexer
, 2));
37445 if (errs
!= errorcount
)
37449 cp_parser_require_pragma_eol (parser
, pragma_tok
);
37452 /* Free any declarators allocated. */
37453 obstack_free (&declarator_obstack
, p
);
37457 #pragma omp declare simd declare-simd-clauses[optseq] new-line
37458 #pragma omp declare reduction (reduction-id : typename-list : expression) \
37459 initializer-clause[opt] new-line
37460 #pragma omp declare target new-line */
37463 cp_parser_omp_declare (cp_parser
*parser
, cp_token
*pragma_tok
,
37464 enum pragma_context context
)
37466 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
37468 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
37469 const char *p
= IDENTIFIER_POINTER (id
);
37471 if (strcmp (p
, "simd") == 0)
37473 cp_lexer_consume_token (parser
->lexer
);
37474 cp_parser_omp_declare_simd (parser
, pragma_tok
,
37478 cp_ensure_no_omp_declare_simd (parser
);
37479 if (strcmp (p
, "reduction") == 0)
37481 cp_lexer_consume_token (parser
->lexer
);
37482 cp_parser_omp_declare_reduction (parser
, pragma_tok
,
37486 if (!flag_openmp
) /* flag_openmp_simd */
37488 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
37491 if (strcmp (p
, "target") == 0)
37493 cp_lexer_consume_token (parser
->lexer
);
37494 cp_parser_omp_declare_target (parser
, pragma_tok
);
37498 cp_parser_error (parser
, "expected %<simd%> or %<reduction%> "
37500 cp_parser_require_pragma_eol (parser
, pragma_tok
);
37504 #pragma omp taskloop taskloop-clause[optseq] new-line
37507 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
37510 #define OMP_TASKLOOP_CLAUSE_MASK \
37511 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
37512 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
37513 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
37514 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
37515 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
37516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
37517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
37518 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
37519 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
37520 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
37521 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
37522 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
37523 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
37524 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
37527 cp_parser_omp_taskloop (cp_parser
*parser
, cp_token
*pragma_tok
,
37528 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
37531 tree clauses
, sb
, ret
;
37533 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
37535 strcat (p_name
, " taskloop");
37536 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
37538 if (cp_lexer_next_token_is (parser
->lexer
, CPP_NAME
))
37540 tree id
= cp_lexer_peek_token (parser
->lexer
)->u
.value
;
37541 const char *p
= IDENTIFIER_POINTER (id
);
37543 if (strcmp (p
, "simd") == 0)
37545 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
37546 if (cclauses
== NULL
)
37547 cclauses
= cclauses_buf
;
37549 cp_lexer_consume_token (parser
->lexer
);
37550 if (!flag_openmp
) /* flag_openmp_simd */
37551 return cp_parser_omp_simd (parser
, pragma_tok
, p_name
, mask
,
37553 sb
= begin_omp_structured_block ();
37554 save
= cp_parser_begin_omp_structured_block (parser
);
37555 ret
= cp_parser_omp_simd (parser
, pragma_tok
, p_name
, mask
,
37557 cp_parser_end_omp_structured_block (parser
, save
);
37558 tree body
= finish_omp_structured_block (sb
);
37561 ret
= make_node (OMP_TASKLOOP
);
37562 TREE_TYPE (ret
) = void_type_node
;
37563 OMP_FOR_BODY (ret
) = body
;
37564 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
37565 SET_EXPR_LOCATION (ret
, loc
);
37570 if (!flag_openmp
) /* flag_openmp_simd */
37572 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
37576 clauses
= cp_parser_omp_all_clauses (parser
, mask
, p_name
, pragma_tok
,
37580 cp_omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
37581 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
37584 sb
= begin_omp_structured_block ();
37585 save
= cp_parser_begin_omp_structured_block (parser
);
37587 ret
= cp_parser_omp_for_loop (parser
, OMP_TASKLOOP
, clauses
, cclauses
,
37590 cp_parser_end_omp_structured_block (parser
, save
);
37591 add_stmt (finish_omp_structured_block (sb
));
37598 # pragma acc routine oacc-routine-clause[optseq] new-line
37599 function-definition
37601 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
37604 #define OACC_ROUTINE_CLAUSE_MASK \
37605 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
37606 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
37607 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
37608 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ))
37611 /* Parse the OpenACC routine pragma. This has an optional '( name )'
37612 component, which must resolve to a declared namespace-scope
37613 function. The clauses are either processed directly (for a named
37614 function), or defered until the immediatley following declaration
37618 cp_parser_oacc_routine (cp_parser
*parser
, cp_token
*pragma_tok
,
37619 enum pragma_context context
)
37621 gcc_checking_assert (context
== pragma_external
);
37622 /* The checking for "another pragma following this one" in the "no optional
37623 '( name )'" case makes sure that we dont re-enter. */
37624 gcc_checking_assert (parser
->oacc_routine
== NULL
);
37626 cp_oacc_routine_data data
;
37627 data
.error_seen
= false;
37628 data
.fndecl_seen
= false;
37629 data
.tokens
= vNULL
;
37630 data
.clauses
= NULL_TREE
;
37631 data
.loc
= pragma_tok
->location
;
37632 /* It is safe to take the address of a local variable; it will only be
37633 used while this scope is live. */
37634 parser
->oacc_routine
= &data
;
37636 /* Look for optional '( name )'. */
37637 if (cp_lexer_next_token_is (parser
->lexer
, CPP_OPEN_PAREN
))
37639 cp_lexer_consume_token (parser
->lexer
); /* '(' */
37641 /* We parse the name as an id-expression. If it resolves to
37642 anything other than a non-overloaded function at namespace
37643 scope, it's an error. */
37644 location_t name_loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
37645 tree name
= cp_parser_id_expression (parser
,
37646 /*template_keyword_p=*/false,
37647 /*check_dependency_p=*/false,
37648 /*template_p=*/NULL
,
37649 /*declarator_p=*/false,
37650 /*optional_p=*/false);
37651 tree decl
= cp_parser_lookup_name_simple (parser
, name
, name_loc
);
37652 if (name
!= error_mark_node
&& decl
== error_mark_node
)
37653 cp_parser_name_lookup_error (parser
, name
, decl
, NLE_NULL
, name_loc
);
37655 if (decl
== error_mark_node
37656 || !cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
37658 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
37659 parser
->oacc_routine
= NULL
;
37664 = cp_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
37665 "#pragma acc routine",
37666 cp_lexer_peek_token (parser
->lexer
));
37668 if (decl
&& is_overloaded_fn (decl
)
37669 && (TREE_CODE (decl
) != FUNCTION_DECL
37670 || DECL_FUNCTION_TEMPLATE_P (decl
)))
37672 error_at (name_loc
,
37673 "%<#pragma acc routine%> names a set of overloads");
37674 parser
->oacc_routine
= NULL
;
37678 /* Perhaps we should use the same rule as declarations in different
37680 if (!DECL_NAMESPACE_SCOPE_P (decl
))
37682 error_at (name_loc
,
37683 "%qD does not refer to a namespace scope function", decl
);
37684 parser
->oacc_routine
= NULL
;
37688 if (TREE_CODE (decl
) != FUNCTION_DECL
)
37690 error_at (name_loc
, "%qD does not refer to a function", decl
);
37691 parser
->oacc_routine
= NULL
;
37695 cp_finalize_oacc_routine (parser
, decl
, false);
37696 parser
->oacc_routine
= NULL
;
37698 else /* No optional '( name )'. */
37700 /* Store away all pragma tokens. */
37701 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
)
37702 && cp_lexer_next_token_is_not (parser
->lexer
, CPP_EOF
))
37703 cp_lexer_consume_token (parser
->lexer
);
37704 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
))
37705 parser
->oacc_routine
->error_seen
= true;
37706 cp_parser_require_pragma_eol (parser
, pragma_tok
);
37707 struct cp_token_cache
*cp
37708 = cp_token_cache_new (pragma_tok
, cp_lexer_peek_token (parser
->lexer
));
37709 parser
->oacc_routine
->tokens
.safe_push (cp
);
37711 /* Emit a helpful diagnostic if there's another pragma following this
37713 if (cp_lexer_next_token_is (parser
->lexer
, CPP_PRAGMA
))
37715 cp_ensure_no_oacc_routine (parser
);
37716 data
.tokens
.release ();
37717 /* ..., and then just keep going. */
37721 /* We only have to consider the pragma_external case here. */
37722 cp_parser_declaration (parser
);
37723 if (parser
->oacc_routine
37724 && !parser
->oacc_routine
->fndecl_seen
)
37725 cp_ensure_no_oacc_routine (parser
);
37727 parser
->oacc_routine
= NULL
;
37728 data
.tokens
.release ();
37732 /* Finalize #pragma acc routine clauses after direct declarator has
37736 cp_parser_late_parsing_oacc_routine (cp_parser
*parser
, tree attrs
)
37738 struct cp_token_cache
*ce
;
37739 cp_oacc_routine_data
*data
= parser
->oacc_routine
;
37741 if (!data
->error_seen
&& data
->fndecl_seen
)
37743 error_at (data
->loc
,
37744 "%<#pragma acc routine%> not immediately followed by "
37745 "a single function declaration or definition");
37746 data
->error_seen
= true;
37748 if (data
->error_seen
)
37751 gcc_checking_assert (data
->tokens
.length () == 1);
37752 ce
= data
->tokens
[0];
37754 cp_parser_push_lexer_for_tokens (parser
, ce
);
37755 parser
->lexer
->in_pragma
= true;
37756 gcc_assert (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_PRAGMA
);
37758 cp_token
*pragma_tok
= cp_lexer_consume_token (parser
->lexer
);
37759 gcc_checking_assert (parser
->oacc_routine
->clauses
== NULL_TREE
);
37760 parser
->oacc_routine
->clauses
37761 = cp_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
37762 "#pragma acc routine", pragma_tok
);
37763 cp_parser_pop_lexer (parser
);
37764 /* Later, cp_finalize_oacc_routine will process the clauses, and then set
37770 /* Apply any saved OpenACC routine clauses to a just-parsed
37774 cp_finalize_oacc_routine (cp_parser
*parser
, tree fndecl
, bool is_defn
)
37776 if (__builtin_expect (parser
->oacc_routine
!= NULL
, 0))
37778 /* Keep going if we're in error reporting mode. */
37779 if (parser
->oacc_routine
->error_seen
37780 || fndecl
== error_mark_node
)
37783 if (parser
->oacc_routine
->fndecl_seen
)
37785 error_at (parser
->oacc_routine
->loc
,
37786 "%<#pragma acc routine%> not immediately followed by"
37787 " a single function declaration or definition");
37788 parser
->oacc_routine
= NULL
;
37791 if (TREE_CODE (fndecl
) != FUNCTION_DECL
)
37793 cp_ensure_no_oacc_routine (parser
);
37797 if (oacc_get_fn_attrib (fndecl
))
37799 error_at (parser
->oacc_routine
->loc
,
37800 "%<#pragma acc routine%> already applied to %qD", fndecl
);
37801 parser
->oacc_routine
= NULL
;
37805 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
37807 error_at (parser
->oacc_routine
->loc
,
37809 ? G_("%<#pragma acc routine%> must be applied before use")
37810 : G_("%<#pragma acc routine%> must be applied before "
37812 parser
->oacc_routine
= NULL
;
37816 /* Process the routine's dimension clauses. */
37817 tree dims
= oacc_build_routine_dims (parser
->oacc_routine
->clauses
);
37818 oacc_replace_fn_attrib (fndecl
, dims
);
37820 /* Add an "omp declare target" attribute. */
37821 DECL_ATTRIBUTES (fndecl
)
37822 = tree_cons (get_identifier ("omp declare target"),
37823 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
37825 /* Don't unset parser->oacc_routine here: we may still need it to
37826 diagnose wrong usage. But, remember that we've used this "#pragma acc
37828 parser
->oacc_routine
->fndecl_seen
= true;
37832 /* Main entry point to OpenMP statement pragmas. */
37835 cp_parser_omp_construct (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
37838 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
37839 omp_clause_mask
mask (0);
37841 switch (cp_parser_pragma_kind (pragma_tok
))
37843 case PRAGMA_OACC_ATOMIC
:
37844 cp_parser_omp_atomic (parser
, pragma_tok
);
37846 case PRAGMA_OACC_CACHE
:
37847 stmt
= cp_parser_oacc_cache (parser
, pragma_tok
);
37849 case PRAGMA_OACC_DATA
:
37850 stmt
= cp_parser_oacc_data (parser
, pragma_tok
, if_p
);
37852 case PRAGMA_OACC_ENTER_DATA
:
37853 stmt
= cp_parser_oacc_enter_exit_data (parser
, pragma_tok
, true);
37855 case PRAGMA_OACC_EXIT_DATA
:
37856 stmt
= cp_parser_oacc_enter_exit_data (parser
, pragma_tok
, false);
37858 case PRAGMA_OACC_HOST_DATA
:
37859 stmt
= cp_parser_oacc_host_data (parser
, pragma_tok
, if_p
);
37861 case PRAGMA_OACC_KERNELS
:
37862 case PRAGMA_OACC_PARALLEL
:
37863 strcpy (p_name
, "#pragma acc");
37864 stmt
= cp_parser_oacc_kernels_parallel (parser
, pragma_tok
, p_name
,
37867 case PRAGMA_OACC_LOOP
:
37868 strcpy (p_name
, "#pragma acc");
37869 stmt
= cp_parser_oacc_loop (parser
, pragma_tok
, p_name
, mask
, NULL
,
37872 case PRAGMA_OACC_UPDATE
:
37873 stmt
= cp_parser_oacc_update (parser
, pragma_tok
);
37875 case PRAGMA_OACC_WAIT
:
37876 stmt
= cp_parser_oacc_wait (parser
, pragma_tok
);
37878 case PRAGMA_OMP_ATOMIC
:
37879 cp_parser_omp_atomic (parser
, pragma_tok
);
37881 case PRAGMA_OMP_CRITICAL
:
37882 stmt
= cp_parser_omp_critical (parser
, pragma_tok
, if_p
);
37884 case PRAGMA_OMP_DISTRIBUTE
:
37885 strcpy (p_name
, "#pragma omp");
37886 stmt
= cp_parser_omp_distribute (parser
, pragma_tok
, p_name
, mask
, NULL
,
37889 case PRAGMA_OMP_FOR
:
37890 strcpy (p_name
, "#pragma omp");
37891 stmt
= cp_parser_omp_for (parser
, pragma_tok
, p_name
, mask
, NULL
,
37894 case PRAGMA_OMP_MASTER
:
37895 stmt
= cp_parser_omp_master (parser
, pragma_tok
, if_p
);
37897 case PRAGMA_OMP_PARALLEL
:
37898 strcpy (p_name
, "#pragma omp");
37899 stmt
= cp_parser_omp_parallel (parser
, pragma_tok
, p_name
, mask
, NULL
,
37902 case PRAGMA_OMP_SECTIONS
:
37903 strcpy (p_name
, "#pragma omp");
37904 stmt
= cp_parser_omp_sections (parser
, pragma_tok
, p_name
, mask
, NULL
);
37906 case PRAGMA_OMP_SIMD
:
37907 strcpy (p_name
, "#pragma omp");
37908 stmt
= cp_parser_omp_simd (parser
, pragma_tok
, p_name
, mask
, NULL
,
37911 case PRAGMA_OMP_SINGLE
:
37912 stmt
= cp_parser_omp_single (parser
, pragma_tok
, if_p
);
37914 case PRAGMA_OMP_TASK
:
37915 stmt
= cp_parser_omp_task (parser
, pragma_tok
, if_p
);
37917 case PRAGMA_OMP_TASKGROUP
:
37918 stmt
= cp_parser_omp_taskgroup (parser
, pragma_tok
, if_p
);
37920 case PRAGMA_OMP_TASKLOOP
:
37921 strcpy (p_name
, "#pragma omp");
37922 stmt
= cp_parser_omp_taskloop (parser
, pragma_tok
, p_name
, mask
, NULL
,
37925 case PRAGMA_OMP_TEAMS
:
37926 strcpy (p_name
, "#pragma omp");
37927 stmt
= cp_parser_omp_teams (parser
, pragma_tok
, p_name
, mask
, NULL
,
37931 gcc_unreachable ();
37934 protected_set_expr_location (stmt
, pragma_tok
->location
);
37937 /* Transactional Memory parsing routines. */
37939 /* Parse a transaction attribute.
37945 We use this instead of cp_parser_attributes_opt for transactions to avoid
37946 the pedwarn in C++98 mode. */
37949 cp_parser_txn_attribute_opt (cp_parser
*parser
)
37952 tree attr_name
, attr
= NULL
;
37954 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_ATTRIBUTE
))
37955 return cp_parser_attributes_opt (parser
);
37957 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_OPEN_SQUARE
))
37959 cp_lexer_consume_token (parser
->lexer
);
37960 if (!cp_parser_require (parser
, CPP_OPEN_SQUARE
, RT_OPEN_SQUARE
))
37963 token
= cp_lexer_peek_token (parser
->lexer
);
37964 if (token
->type
== CPP_NAME
|| token
->type
== CPP_KEYWORD
)
37966 token
= cp_lexer_consume_token (parser
->lexer
);
37968 attr_name
= (token
->type
== CPP_KEYWORD
37969 /* For keywords, use the canonical spelling,
37970 not the parsed identifier. */
37971 ? ridpointers
[(int) token
->keyword
]
37973 attr
= build_tree_list (attr_name
, NULL_TREE
);
37976 cp_parser_error (parser
, "expected identifier");
37978 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
37980 cp_parser_require (parser
, CPP_CLOSE_SQUARE
, RT_CLOSE_SQUARE
);
37984 /* Parse a __transaction_atomic or __transaction_relaxed statement.
37986 transaction-statement:
37987 __transaction_atomic txn-attribute[opt] txn-noexcept-spec[opt]
37989 __transaction_relaxed txn-noexcept-spec[opt] compound-statement
37993 cp_parser_transaction (cp_parser
*parser
, cp_token
*token
)
37995 unsigned char old_in
= parser
->in_transaction
;
37996 unsigned char this_in
= 1, new_in
;
37997 enum rid keyword
= token
->keyword
;
37998 tree stmt
, attrs
, noex
;
38000 cp_lexer_consume_token (parser
->lexer
);
38002 if (keyword
== RID_TRANSACTION_RELAXED
38003 || keyword
== RID_SYNCHRONIZED
)
38004 this_in
|= TM_STMT_ATTR_RELAXED
;
38007 attrs
= cp_parser_txn_attribute_opt (parser
);
38009 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
38012 /* Parse a noexcept specification. */
38013 if (keyword
== RID_ATOMIC_NOEXCEPT
)
38014 noex
= boolean_true_node
;
38015 else if (keyword
== RID_ATOMIC_CANCEL
)
38017 /* cancel-and-throw is unimplemented. */
38018 sorry ("atomic_cancel");
38022 noex
= cp_parser_noexcept_specification_opt (parser
, true, NULL
, true);
38024 /* Keep track if we're in the lexical scope of an outer transaction. */
38025 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
38027 stmt
= begin_transaction_stmt (token
->location
, NULL
, this_in
);
38029 parser
->in_transaction
= new_in
;
38030 cp_parser_compound_statement (parser
, NULL
, BCS_TRANSACTION
, false);
38031 parser
->in_transaction
= old_in
;
38033 finish_transaction_stmt (stmt
, NULL
, this_in
, noex
);
38038 /* Parse a __transaction_atomic or __transaction_relaxed expression.
38040 transaction-expression:
38041 __transaction_atomic txn-noexcept-spec[opt] ( expression )
38042 __transaction_relaxed txn-noexcept-spec[opt] ( expression )
38046 cp_parser_transaction_expression (cp_parser
*parser
, enum rid keyword
)
38048 unsigned char old_in
= parser
->in_transaction
;
38049 unsigned char this_in
= 1;
38053 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
38055 gcc_assert (keyword
== RID_TRANSACTION_ATOMIC
38056 || keyword
== RID_TRANSACTION_RELAXED
);
38060 keyword
== RID_TRANSACTION_RELAXED
38061 ? G_("%<__transaction_relaxed%> without transactional memory "
38063 : G_("%<__transaction_atomic%> without transactional memory "
38064 "support enabled"));
38066 token
= cp_parser_require_keyword (parser
, keyword
,
38067 (keyword
== RID_TRANSACTION_ATOMIC
? RT_TRANSACTION_ATOMIC
38068 : RT_TRANSACTION_RELAXED
));
38069 gcc_assert (token
!= NULL
);
38071 if (keyword
== RID_TRANSACTION_RELAXED
)
38072 this_in
|= TM_STMT_ATTR_RELAXED
;
38074 /* Set this early. This might mean that we allow transaction_cancel in
38075 an expression that we find out later actually has to be a constexpr.
38076 However, we expect that cxx_constant_value will be able to deal with
38077 this; also, if the noexcept has no constexpr, then what we parse next
38078 really is a transaction's body. */
38079 parser
->in_transaction
= this_in
;
38081 /* Parse a noexcept specification. */
38082 noex
= cp_parser_noexcept_specification_opt (parser
, false, &noex_expr
,
38085 if (!noex
|| !noex_expr
38086 || cp_lexer_peek_token (parser
->lexer
)->type
== CPP_OPEN_PAREN
)
38088 cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
);
38090 expr
= cp_parser_expression (parser
);
38091 expr
= finish_parenthesized_expr (expr
);
38093 cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
);
38097 /* The only expression that is available got parsed for the noexcept
38098 already. noexcept is true then. */
38100 noex
= boolean_true_node
;
38103 expr
= build_transaction_expr (token
->location
, expr
, this_in
, noex
);
38104 parser
->in_transaction
= old_in
;
38106 if (cp_parser_non_integral_constant_expression (parser
, NIC_TRANSACTION
))
38107 return error_mark_node
;
38109 return (flag_tm
? expr
: error_mark_node
);
38112 /* Parse a function-transaction-block.
38114 function-transaction-block:
38115 __transaction_atomic txn-attribute[opt] ctor-initializer[opt]
38117 __transaction_atomic txn-attribute[opt] function-try-block
38118 __transaction_relaxed ctor-initializer[opt] function-body
38119 __transaction_relaxed function-try-block
38123 cp_parser_function_transaction (cp_parser
*parser
, enum rid keyword
)
38125 unsigned char old_in
= parser
->in_transaction
;
38126 unsigned char new_in
= 1;
38127 tree compound_stmt
, stmt
, attrs
;
38128 bool ctor_initializer_p
;
38131 gcc_assert (keyword
== RID_TRANSACTION_ATOMIC
38132 || keyword
== RID_TRANSACTION_RELAXED
);
38133 token
= cp_parser_require_keyword (parser
, keyword
,
38134 (keyword
== RID_TRANSACTION_ATOMIC
? RT_TRANSACTION_ATOMIC
38135 : RT_TRANSACTION_RELAXED
));
38136 gcc_assert (token
!= NULL
);
38138 if (keyword
== RID_TRANSACTION_RELAXED
)
38139 new_in
|= TM_STMT_ATTR_RELAXED
;
38142 attrs
= cp_parser_txn_attribute_opt (parser
);
38144 new_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
38147 stmt
= begin_transaction_stmt (token
->location
, &compound_stmt
, new_in
);
38149 parser
->in_transaction
= new_in
;
38151 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_TRY
))
38152 ctor_initializer_p
= cp_parser_function_try_block (parser
);
38154 ctor_initializer_p
= cp_parser_ctor_initializer_opt_and_function_body
38155 (parser
, /*in_function_try_block=*/false);
38157 parser
->in_transaction
= old_in
;
38159 finish_transaction_stmt (stmt
, compound_stmt
, new_in
, NULL_TREE
);
38161 return ctor_initializer_p
;
38164 /* Parse a __transaction_cancel statement.
38167 __transaction_cancel txn-attribute[opt] ;
38168 __transaction_cancel txn-attribute[opt] throw-expression ;
38170 ??? Cancel and throw is not yet implemented. */
38173 cp_parser_transaction_cancel (cp_parser
*parser
)
38176 bool is_outer
= false;
38179 token
= cp_parser_require_keyword (parser
, RID_TRANSACTION_CANCEL
,
38180 RT_TRANSACTION_CANCEL
);
38181 gcc_assert (token
!= NULL
);
38183 attrs
= cp_parser_txn_attribute_opt (parser
);
38185 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
38187 /* ??? Parse cancel-and-throw here. */
38189 cp_parser_require (parser
, CPP_SEMICOLON
, RT_SEMICOLON
);
38193 error_at (token
->location
, "%<__transaction_cancel%> without "
38194 "transactional memory support enabled");
38195 return error_mark_node
;
38197 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
38199 error_at (token
->location
, "%<__transaction_cancel%> within a "
38200 "%<__transaction_relaxed%>");
38201 return error_mark_node
;
38205 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
38206 && !is_tm_may_cancel_outer (current_function_decl
))
38208 error_at (token
->location
, "outer %<__transaction_cancel%> not "
38209 "within outer %<__transaction_atomic%>");
38210 error_at (token
->location
,
38211 " or a %<transaction_may_cancel_outer%> function");
38212 return error_mark_node
;
38215 else if (parser
->in_transaction
== 0)
38217 error_at (token
->location
, "%<__transaction_cancel%> not within "
38218 "%<__transaction_atomic%>");
38219 return error_mark_node
;
38222 stmt
= build_tm_abort_call (token
->location
, is_outer
);
38230 static GTY (()) cp_parser
*the_parser
;
38233 /* Special handling for the first token or line in the file. The first
38234 thing in the file might be #pragma GCC pch_preprocess, which loads a
38235 PCH file, which is a GC collection point. So we need to handle this
38236 first pragma without benefit of an existing lexer structure.
38238 Always returns one token to the caller in *FIRST_TOKEN. This is
38239 either the true first token of the file, or the first token after
38240 the initial pragma. */
38243 cp_parser_initial_pragma (cp_token
*first_token
)
38247 cp_lexer_get_preprocessor_token (NULL
, first_token
);
38248 if (cp_parser_pragma_kind (first_token
) != PRAGMA_GCC_PCH_PREPROCESS
)
38251 cp_lexer_get_preprocessor_token (NULL
, first_token
);
38252 if (first_token
->type
== CPP_STRING
)
38254 name
= first_token
->u
.value
;
38256 cp_lexer_get_preprocessor_token (NULL
, first_token
);
38257 if (first_token
->type
!= CPP_PRAGMA_EOL
)
38258 error_at (first_token
->location
,
38259 "junk at end of %<#pragma GCC pch_preprocess%>");
38262 error_at (first_token
->location
, "expected string literal");
38264 /* Skip to the end of the pragma. */
38265 while (first_token
->type
!= CPP_PRAGMA_EOL
&& first_token
->type
!= CPP_EOF
)
38266 cp_lexer_get_preprocessor_token (NULL
, first_token
);
38268 /* Now actually load the PCH file. */
38270 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
38272 /* Read one more token to return to our caller. We have to do this
38273 after reading the PCH file in, since its pointers have to be
38275 cp_lexer_get_preprocessor_token (NULL
, first_token
);
38278 /* Parses the grainsize pragma for the _Cilk_for statement.
38280 #pragma cilk grainsize = <VALUE>. */
38283 cp_parser_cilk_grainsize (cp_parser
*parser
, cp_token
*pragma_tok
, bool *if_p
)
38285 if (cp_parser_require (parser
, CPP_EQ
, RT_EQ
))
38287 tree exp
= cp_parser_binary_expression (parser
, false, false,
38288 PREC_NOT_OPERATOR
, NULL
);
38289 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
38290 if (!exp
|| exp
== error_mark_node
)
38292 error_at (pragma_tok
->location
, "invalid grainsize for _Cilk_for");
38296 /* Make sure the next token is _Cilk_for, it is invalid otherwise. */
38297 if (cp_lexer_next_token_is_keyword (parser
->lexer
, RID_CILK_FOR
))
38298 cp_parser_cilk_for (parser
, exp
, if_p
);
38300 warning_at (cp_lexer_peek_token (parser
->lexer
)->location
, 0,
38301 "%<#pragma cilk grainsize%> is not followed by "
38305 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
38308 /* Normal parsing of a pragma token. Here we can (and must) use the
38312 cp_parser_pragma (cp_parser
*parser
, enum pragma_context context
, bool *if_p
)
38314 cp_token
*pragma_tok
;
38319 pragma_tok
= cp_lexer_consume_token (parser
->lexer
);
38320 gcc_assert (pragma_tok
->type
== CPP_PRAGMA
);
38321 parser
->lexer
->in_pragma
= true;
38323 id
= cp_parser_pragma_kind (pragma_tok
);
38324 if (id
!= PRAGMA_OMP_DECLARE
&& id
!= PRAGMA_OACC_ROUTINE
)
38325 cp_ensure_no_omp_declare_simd (parser
);
38328 case PRAGMA_GCC_PCH_PREPROCESS
:
38329 error_at (pragma_tok
->location
,
38330 "%<#pragma GCC pch_preprocess%> must be first");
38333 case PRAGMA_OMP_BARRIER
:
38336 case pragma_compound
:
38337 cp_parser_omp_barrier (parser
, pragma_tok
);
38340 error_at (pragma_tok
->location
, "%<#pragma %s%> may only be "
38341 "used in compound statements", "omp barrier");
38348 case PRAGMA_OMP_FLUSH
:
38351 case pragma_compound
:
38352 cp_parser_omp_flush (parser
, pragma_tok
);
38355 error_at (pragma_tok
->location
, "%<#pragma %s%> may only be "
38356 "used in compound statements", "omp flush");
38363 case PRAGMA_OMP_TASKWAIT
:
38366 case pragma_compound
:
38367 cp_parser_omp_taskwait (parser
, pragma_tok
);
38370 error_at (pragma_tok
->location
,
38371 "%<#pragma %s%> may only be used in compound statements",
38379 case PRAGMA_OMP_TASKYIELD
:
38382 case pragma_compound
:
38383 cp_parser_omp_taskyield (parser
, pragma_tok
);
38386 error_at (pragma_tok
->location
,
38387 "%<#pragma %s%> may only be used in compound statements",
38395 case PRAGMA_OMP_CANCEL
:
38398 case pragma_compound
:
38399 cp_parser_omp_cancel (parser
, pragma_tok
);
38402 error_at (pragma_tok
->location
,
38403 "%<#pragma %s%> may only be used in compound statements",
38411 case PRAGMA_OMP_CANCELLATION_POINT
:
38412 cp_parser_omp_cancellation_point (parser
, pragma_tok
, context
);
38415 case PRAGMA_OMP_THREADPRIVATE
:
38416 cp_parser_omp_threadprivate (parser
, pragma_tok
);
38419 case PRAGMA_OMP_DECLARE
:
38420 cp_parser_omp_declare (parser
, pragma_tok
, context
);
38423 case PRAGMA_OACC_DECLARE
:
38424 cp_parser_oacc_declare (parser
, pragma_tok
);
38427 case PRAGMA_OACC_ENTER_DATA
:
38428 if (context
== pragma_stmt
)
38430 error_at (pragma_tok
->location
,
38431 "%<#pragma %s%> may only be used in compound statements",
38435 else if (context
!= pragma_compound
)
38437 cp_parser_omp_construct (parser
, pragma_tok
, if_p
);
38440 case PRAGMA_OACC_EXIT_DATA
:
38441 if (context
== pragma_stmt
)
38443 error_at (pragma_tok
->location
,
38444 "%<#pragma %s%> may only be used in compound statements",
38448 else if (context
!= pragma_compound
)
38450 cp_parser_omp_construct (parser
, pragma_tok
, if_p
);
38453 case PRAGMA_OACC_ROUTINE
:
38454 if (context
!= pragma_external
)
38456 error_at (pragma_tok
->location
,
38457 "%<#pragma acc routine%> must be at file scope");
38460 cp_parser_oacc_routine (parser
, pragma_tok
, context
);
38463 case PRAGMA_OACC_UPDATE
:
38464 if (context
== pragma_stmt
)
38466 error_at (pragma_tok
->location
,
38467 "%<#pragma %s%> may only be used in compound statements",
38471 else if (context
!= pragma_compound
)
38473 cp_parser_omp_construct (parser
, pragma_tok
, if_p
);
38476 case PRAGMA_OACC_WAIT
:
38477 if (context
== pragma_stmt
)
38479 error_at (pragma_tok
->location
,
38480 "%<#pragma %s%> may only be used in compound statements",
38484 else if (context
!= pragma_compound
)
38486 cp_parser_omp_construct (parser
, pragma_tok
, if_p
);
38489 case PRAGMA_OACC_ATOMIC
:
38490 case PRAGMA_OACC_CACHE
:
38491 case PRAGMA_OACC_DATA
:
38492 case PRAGMA_OACC_HOST_DATA
:
38493 case PRAGMA_OACC_KERNELS
:
38494 case PRAGMA_OACC_PARALLEL
:
38495 case PRAGMA_OACC_LOOP
:
38496 case PRAGMA_OMP_ATOMIC
:
38497 case PRAGMA_OMP_CRITICAL
:
38498 case PRAGMA_OMP_DISTRIBUTE
:
38499 case PRAGMA_OMP_FOR
:
38500 case PRAGMA_OMP_MASTER
:
38501 case PRAGMA_OMP_PARALLEL
:
38502 case PRAGMA_OMP_SECTIONS
:
38503 case PRAGMA_OMP_SIMD
:
38504 case PRAGMA_OMP_SINGLE
:
38505 case PRAGMA_OMP_TASK
:
38506 case PRAGMA_OMP_TASKGROUP
:
38507 case PRAGMA_OMP_TASKLOOP
:
38508 case PRAGMA_OMP_TEAMS
:
38509 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
38511 stmt
= push_omp_privatization_clauses (false);
38512 cp_parser_omp_construct (parser
, pragma_tok
, if_p
);
38513 pop_omp_privatization_clauses (stmt
);
38516 case PRAGMA_OMP_ORDERED
:
38517 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
38519 stmt
= push_omp_privatization_clauses (false);
38520 ret
= cp_parser_omp_ordered (parser
, pragma_tok
, context
, if_p
);
38521 pop_omp_privatization_clauses (stmt
);
38524 case PRAGMA_OMP_TARGET
:
38525 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
38527 stmt
= push_omp_privatization_clauses (false);
38528 ret
= cp_parser_omp_target (parser
, pragma_tok
, context
, if_p
);
38529 pop_omp_privatization_clauses (stmt
);
38532 case PRAGMA_OMP_END_DECLARE_TARGET
:
38533 cp_parser_omp_end_declare_target (parser
, pragma_tok
);
38536 case PRAGMA_OMP_SECTION
:
38537 error_at (pragma_tok
->location
,
38538 "%<#pragma omp section%> may only be used in "
38539 "%<#pragma omp sections%> construct");
38544 if (context
== pragma_external
)
38546 error_at (pragma_tok
->location
,
38547 "%<#pragma GCC ivdep%> must be inside a function");
38550 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
38552 tok
= cp_lexer_peek_token (the_parser
->lexer
);
38553 if (tok
->type
!= CPP_KEYWORD
38554 || (tok
->keyword
!= RID_FOR
&& tok
->keyword
!= RID_WHILE
38555 && tok
->keyword
!= RID_DO
))
38557 cp_parser_error (parser
, "for, while or do statement expected");
38560 cp_parser_iteration_statement (parser
, if_p
, true);
38564 case PRAGMA_CILK_SIMD
:
38565 if (context
== pragma_external
)
38567 error_at (pragma_tok
->location
,
38568 "%<#pragma simd%> must be inside a function");
38571 stmt
= push_omp_privatization_clauses (false);
38572 cp_parser_cilk_simd (parser
, pragma_tok
, if_p
);
38573 pop_omp_privatization_clauses (stmt
);
38576 case PRAGMA_CILK_GRAINSIZE
:
38577 if (context
== pragma_external
)
38579 error_at (pragma_tok
->location
,
38580 "%<#pragma cilk grainsize%> must be inside a function");
38584 /* Ignore the pragma if Cilk Plus is not enabled. */
38587 cp_parser_cilk_grainsize (parser
, pragma_tok
, if_p
);
38592 error_at (pragma_tok
->location
, "-fcilkplus must be enabled to use "
38593 "%<#pragma cilk grainsize%>");
38598 gcc_assert (id
>= PRAGMA_FIRST_EXTERNAL
);
38599 c_invoke_pragma_handler (id
);
38603 cp_parser_error (parser
, "expected declaration specifiers");
38607 cp_parser_skip_to_pragma_eol (parser
, pragma_tok
);
38611 /* The interface the pragma parsers have to the lexer. */
38614 pragma_lex (tree
*value
, location_t
*loc
)
38616 cp_token
*tok
= cp_lexer_peek_token (the_parser
->lexer
);
38617 enum cpp_ttype ret
= tok
->type
;
38619 *value
= tok
->u
.value
;
38621 *loc
= tok
->location
;
38623 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
38625 else if (ret
== CPP_STRING
)
38626 *value
= cp_parser_string_literal (the_parser
, false, false);
38629 if (ret
== CPP_KEYWORD
)
38631 cp_lexer_consume_token (the_parser
->lexer
);
38638 /* External interface. */
38640 /* Parse one entire translation unit. */
38643 c_parse_file (void)
38645 static bool already_called
= false;
38647 if (already_called
)
38648 fatal_error (input_location
,
38649 "inter-module optimizations not implemented for C++");
38650 already_called
= true;
38652 the_parser
= cp_parser_new ();
38653 push_deferring_access_checks (flag_access_control
38654 ? dk_no_deferred
: dk_no_check
);
38655 cp_parser_translation_unit (the_parser
);
38659 /* Parses the Cilk Plus #pragma simd and SIMD-enabled function attribute's
38660 vectorlength clause:
38662 vectorlength ( constant-expression ) */
38665 cp_parser_cilk_simd_vectorlength (cp_parser
*parser
, tree clauses
,
38668 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
38670 /* The vectorlength clause in #pragma simd behaves exactly like OpenMP's
38671 safelen clause. Thus, vectorlength is represented as OMP 4.0
38672 safelen. For SIMD-enabled function it is represented by OMP 4.0
38675 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength",
38678 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength",
38681 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
38682 return error_mark_node
;
38684 expr
= cp_parser_constant_expression (parser
);
38685 expr
= maybe_constant_value (expr
);
38687 /* If expr == error_mark_node, then don't emit any errors nor
38688 create a clause. if any of the above functions returns
38689 error mark node then they would have emitted an error message. */
38690 if (expr
== error_mark_node
)
38692 else if (!TREE_TYPE (expr
)
38693 || !TREE_CONSTANT (expr
)
38694 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
38695 error_at (loc
, "vectorlength must be an integer constant");
38696 else if (TREE_CONSTANT (expr
)
38697 && !pow2p_hwi (TREE_INT_CST_LOW (expr
)))
38698 error_at (loc
, "vectorlength must be a power of 2");
38704 c
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
38705 OMP_CLAUSE_SAFELEN_EXPR (c
) = expr
;
38706 OMP_CLAUSE_CHAIN (c
) = clauses
;
38711 c
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
38712 OMP_CLAUSE_SIMDLEN_EXPR (c
) = expr
;
38713 OMP_CLAUSE_CHAIN (c
) = clauses
;
38718 if (!cp_parser_require (parser
, CPP_CLOSE_PAREN
, RT_CLOSE_PAREN
))
38719 return error_mark_node
;
38723 /* Handles the Cilk Plus #pragma simd linear clause.
38725 linear ( simd-linear-variable-list )
38727 simd-linear-variable-list:
38728 simd-linear-variable
38729 simd-linear-variable-list , simd-linear-variable
38731 simd-linear-variable:
38733 id-expression : simd-linear-step
38736 conditional-expression */
38739 cp_parser_cilk_simd_linear (cp_parser
*parser
, tree clauses
)
38741 location_t loc
= cp_lexer_peek_token (parser
->lexer
)->location
;
38743 if (!cp_parser_require (parser
, CPP_OPEN_PAREN
, RT_OPEN_PAREN
))
38745 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_NAME
))
38747 cp_parser_error (parser
, "expected identifier");
38748 cp_parser_skip_to_closing_parenthesis (parser
, false, false, true);
38749 return error_mark_node
;
38752 bool saved_colon_corrects_to_scope_p
= parser
->colon_corrects_to_scope_p
;
38753 parser
->colon_corrects_to_scope_p
= false;
38756 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
38757 if (cp_lexer_next_token_is_not (parser
->lexer
, CPP_NAME
))
38759 cp_parser_error (parser
, "expected variable-name");
38760 clauses
= error_mark_node
;
38764 tree var_name
= cp_parser_id_expression (parser
, false, true, NULL
,
38766 tree decl
= cp_parser_lookup_name_simple (parser
, var_name
,
38768 if (decl
== error_mark_node
)
38770 cp_parser_name_lookup_error (parser
, var_name
, decl
, NLE_NULL
,
38772 clauses
= error_mark_node
;
38776 tree e
= NULL_TREE
;
38777 tree step_size
= integer_one_node
;
38779 /* If present, parse the linear step. Otherwise, assume the default
38781 if (cp_lexer_peek_token (parser
->lexer
)->type
== CPP_COLON
)
38783 cp_lexer_consume_token (parser
->lexer
);
38785 e
= cp_parser_assignment_expression (parser
);
38786 e
= maybe_constant_value (e
);
38788 if (e
== error_mark_node
)
38790 /* If an error has occurred, then the whole pragma is
38791 considered ill-formed. Thus, no reason to keep
38793 clauses
= error_mark_node
;
38796 else if (type_dependent_expression_p (e
)
38797 || value_dependent_expression_p (e
)
38799 && INTEGRAL_TYPE_P (TREE_TYPE (e
))
38800 && (TREE_CONSTANT (e
)
38804 cp_parser_error (parser
,
38805 "step size must be an integer constant "
38806 "expression or an integer variable");
38809 /* Use the OMP_CLAUSE_LINEAR, which has the same semantics. */
38810 tree l
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
38811 OMP_CLAUSE_DECL (l
) = decl
;
38812 OMP_CLAUSE_LINEAR_STEP (l
) = step_size
;
38813 OMP_CLAUSE_CHAIN (l
) = clauses
;
38816 if (cp_lexer_next_token_is (parser
->lexer
, CPP_COMMA
))
38817 cp_lexer_consume_token (parser
->lexer
);
38818 else if (cp_lexer_next_token_is (parser
->lexer
, CPP_CLOSE_PAREN
))
38822 error_at (cp_lexer_peek_token (parser
->lexer
)->location
,
38823 "expected %<,%> or %<)%> after %qE", decl
);
38824 clauses
= error_mark_node
;
38828 parser
->colon_corrects_to_scope_p
= saved_colon_corrects_to_scope_p
;
38829 cp_parser_skip_to_closing_parenthesis (parser
, false, false, true);
38833 /* Returns the name of the next clause. If the clause is not
38834 recognized, then PRAGMA_CILK_CLAUSE_NONE is returned and the next
38835 token is not consumed. Otherwise, the appropriate enum from the
38836 pragma_simd_clause is returned and the token is consumed. */
38838 static pragma_omp_clause
38839 cp_parser_cilk_simd_clause_name (cp_parser
*parser
)
38841 pragma_omp_clause clause_type
;
38842 cp_token
*token
= cp_lexer_peek_token (parser
->lexer
);
38844 if (token
->keyword
== RID_PRIVATE
)
38845 clause_type
= PRAGMA_CILK_CLAUSE_PRIVATE
;
38846 else if (!token
->u
.value
|| token
->type
!= CPP_NAME
)
38847 return PRAGMA_CILK_CLAUSE_NONE
;
38848 else if (id_equal (token
->u
.value
, "vectorlength"))
38849 clause_type
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
38850 else if (id_equal (token
->u
.value
, "linear"))
38851 clause_type
= PRAGMA_CILK_CLAUSE_LINEAR
;
38852 else if (id_equal (token
->u
.value
, "firstprivate"))
38853 clause_type
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
38854 else if (id_equal (token
->u
.value
, "lastprivate"))
38855 clause_type
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
38856 else if (id_equal (token
->u
.value
, "reduction"))
38857 clause_type
= PRAGMA_CILK_CLAUSE_REDUCTION
;
38859 return PRAGMA_CILK_CLAUSE_NONE
;
38861 cp_lexer_consume_token (parser
->lexer
);
38862 return clause_type
;
38865 /* Parses all the #pragma simd clauses. Returns a list of clauses found. */
38868 cp_parser_cilk_simd_all_clauses (cp_parser
*parser
, cp_token
*pragma_token
)
38870 tree clauses
= NULL_TREE
;
38872 while (cp_lexer_next_token_is_not (parser
->lexer
, CPP_PRAGMA_EOL
)
38873 && clauses
!= error_mark_node
)
38875 pragma_omp_clause c_kind
;
38876 c_kind
= cp_parser_cilk_simd_clause_name (parser
);
38877 if (c_kind
== PRAGMA_CILK_CLAUSE_VECTORLENGTH
)
38878 clauses
= cp_parser_cilk_simd_vectorlength (parser
, clauses
, false);
38879 else if (c_kind
== PRAGMA_CILK_CLAUSE_LINEAR
)
38880 clauses
= cp_parser_cilk_simd_linear (parser
, clauses
);
38881 else if (c_kind
== PRAGMA_CILK_CLAUSE_PRIVATE
)
38882 /* Use the OpenMP 4.0 equivalent function. */
38883 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_PRIVATE
, clauses
);
38884 else if (c_kind
== PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
)
38885 /* Use the OpenMP 4.0 equivalent function. */
38886 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_FIRSTPRIVATE
,
38888 else if (c_kind
== PRAGMA_CILK_CLAUSE_LASTPRIVATE
)
38889 /* Use the OMP 4.0 equivalent function. */
38890 clauses
= cp_parser_omp_var_list (parser
, OMP_CLAUSE_LASTPRIVATE
,
38892 else if (c_kind
== PRAGMA_CILK_CLAUSE_REDUCTION
)
38893 /* Use the OMP 4.0 equivalent function. */
38894 clauses
= cp_parser_omp_clause_reduction (parser
, clauses
);
38897 clauses
= error_mark_node
;
38898 cp_parser_error (parser
, "expected %<#pragma simd%> clause");
38903 cp_parser_skip_to_pragma_eol (parser
, pragma_token
);
38905 if (clauses
== error_mark_node
)
38906 return error_mark_node
;
38908 return finish_omp_clauses (clauses
, C_ORT_CILK
);
38911 /* Main entry-point for parsing Cilk Plus <#pragma simd> for loops. */
38914 cp_parser_cilk_simd (cp_parser
*parser
, cp_token
*pragma_token
, bool *if_p
)
38916 tree clauses
= cp_parser_cilk_simd_all_clauses (parser
, pragma_token
);
38918 if (clauses
== error_mark_node
)
38921 if (cp_lexer_next_token_is_not_keyword (parser
->lexer
, RID_FOR
))
38923 error_at (cp_lexer_peek_token (parser
->lexer
)->location
,
38924 "for statement expected");
38928 tree sb
= begin_omp_structured_block ();
38929 int save
= cp_parser_begin_omp_structured_block (parser
);
38930 tree ret
= cp_parser_omp_for_loop (parser
, CILK_SIMD
, clauses
, NULL
, if_p
);
38932 cpp_validate_cilk_plus_loop (OMP_FOR_BODY (ret
));
38933 cp_parser_end_omp_structured_block (parser
, save
);
38934 add_stmt (finish_omp_structured_block (sb
));
38937 /* Main entry-point for parsing Cilk Plus _Cilk_for
38938 loops. The return value is error_mark_node
38939 when errors happen and CILK_FOR tree on success. */
38942 cp_parser_cilk_for (cp_parser
*parser
, tree grain
, bool *if_p
)
38944 if (cp_lexer_next_token_is_not_keyword (parser
->lexer
, RID_CILK_FOR
))
38945 gcc_unreachable ();
38947 tree sb
= begin_omp_structured_block ();
38948 int save
= cp_parser_begin_omp_structured_block (parser
);
38950 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
38951 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
38952 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
38953 clauses
= finish_omp_clauses (clauses
, C_ORT_CILK
);
38955 tree ret
= cp_parser_omp_for_loop (parser
, CILK_FOR
, clauses
, NULL
, if_p
);
38957 cpp_validate_cilk_plus_loop (ret
);
38959 ret
= error_mark_node
;
38961 cp_parser_end_omp_structured_block (parser
, save
);
38962 add_stmt (finish_omp_structured_block (sb
));
38966 /* Create an identifier for a generic parameter type (a synthesized
38967 template parameter implied by `auto' or a concept identifier). */
38969 static GTY(()) int generic_parm_count
;
38971 make_generic_type_name ()
38974 sprintf (buf
, "auto:%d", ++generic_parm_count
);
38975 return get_identifier (buf
);
38978 /* Add an implicit template type parameter to the CURRENT_TEMPLATE_PARMS
38979 (creating a new template parameter list if necessary). Returns the newly
38980 created template type parm. */
38983 synthesize_implicit_template_parm (cp_parser
*parser
, tree constr
)
38985 gcc_assert (current_binding_level
->kind
== sk_function_parms
);
38987 /* Before committing to modifying any scope, if we're in an
38988 implicit template scope, and we're trying to synthesize a
38989 constrained parameter, try to find a previous parameter with
38990 the same name. This is the same-type rule for abbreviated
38991 function templates.
38993 NOTE: We can generate implicit parameters when tentatively
38994 parsing a nested name specifier, only to reject that parse
38995 later. However, matching the same template-id as part of a
38996 direct-declarator should generate an identical template
38997 parameter, so this rule will merge them. */
38998 if (parser
->implicit_template_scope
&& constr
)
39000 tree t
= parser
->implicit_template_parms
;
39003 if (equivalent_placeholder_constraints (TREE_TYPE (t
), constr
))
39005 tree d
= TREE_VALUE (t
);
39006 if (TREE_CODE (d
) == PARM_DECL
)
39007 /* Return the TEMPLATE_PARM_INDEX. */
39008 d
= DECL_INITIAL (d
);
39011 t
= TREE_CHAIN (t
);
39015 /* We are either continuing a function template that already contains implicit
39016 template parameters, creating a new fully-implicit function template, or
39017 extending an existing explicit function template with implicit template
39020 cp_binding_level
*const entry_scope
= current_binding_level
;
39022 bool become_template
= false;
39023 cp_binding_level
*parent_scope
= 0;
39025 if (parser
->implicit_template_scope
)
39027 gcc_assert (parser
->implicit_template_parms
);
39029 current_binding_level
= parser
->implicit_template_scope
;
39033 /* Roll back to the existing template parameter scope (in the case of
39034 extending an explicit function template) or introduce a new template
39035 parameter scope ahead of the function parameter scope (or class scope
39036 in the case of out-of-line member definitions). The function scope is
39037 added back after template parameter synthesis below. */
39039 cp_binding_level
*scope
= entry_scope
;
39041 while (scope
->kind
== sk_function_parms
)
39043 parent_scope
= scope
;
39044 scope
= scope
->level_chain
;
39046 if (current_class_type
&& !LAMBDA_TYPE_P (current_class_type
))
39048 /* If not defining a class, then any class scope is a scope level in
39049 an out-of-line member definition. In this case simply wind back
39050 beyond the first such scope to inject the template parameter list.
39051 Otherwise wind back to the class being defined. The latter can
39052 occur in class member friend declarations such as:
39058 friend void A::foo (auto);
39061 The template parameter list synthesized for the friend declaration
39062 must be injected in the scope of 'B'. This can also occur in
39063 erroneous cases such as:
39069 void B::foo (auto) {}
39072 Here the attempted definition of 'B::foo' within 'A' is ill-formed
39073 but, nevertheless, the template parameter list synthesized for the
39074 declarator should be injected into the scope of 'A' as if the
39075 ill-formed template was specified explicitly. */
39077 while (scope
->kind
== sk_class
&& !scope
->defining_class_p
)
39079 parent_scope
= scope
;
39080 scope
= scope
->level_chain
;
39084 current_binding_level
= scope
;
39086 if (scope
->kind
!= sk_template_parms
39087 || !function_being_declared_is_template_p (parser
))
39089 /* Introduce a new template parameter list for implicit template
39092 become_template
= true;
39094 parser
->implicit_template_scope
39095 = begin_scope (sk_template_parms
, NULL
);
39097 ++processing_template_decl
;
39099 parser
->fully_implicit_function_template_p
= true;
39100 ++parser
->num_template_parameter_lists
;
39104 /* Synthesize implicit template parameters at the end of the explicit
39105 template parameter list. */
39107 gcc_assert (current_template_parms
);
39109 parser
->implicit_template_scope
= scope
;
39111 tree v
= INNERMOST_TEMPLATE_PARMS (current_template_parms
);
39112 parser
->implicit_template_parms
39113 = TREE_VEC_ELT (v
, TREE_VEC_LENGTH (v
) - 1);
39117 /* Synthesize a new template parameter and track the current template
39118 parameter chain with implicit_template_parms. */
39120 tree proto
= constr
? DECL_INITIAL (constr
) : NULL_TREE
;
39121 tree synth_id
= make_generic_type_name ();
39122 tree synth_tmpl_parm
;
39123 bool non_type
= false;
39125 if (proto
== NULL_TREE
|| TREE_CODE (proto
) == TYPE_DECL
)
39127 = finish_template_type_parm (class_type_node
, synth_id
);
39128 else if (TREE_CODE (proto
) == TEMPLATE_DECL
)
39130 = finish_constrained_template_template_parm (proto
, synth_id
);
39133 synth_tmpl_parm
= copy_decl (proto
);
39134 DECL_NAME (synth_tmpl_parm
) = synth_id
;
39138 // Attach the constraint to the parm before processing.
39139 tree node
= build_tree_list (NULL_TREE
, synth_tmpl_parm
);
39140 TREE_TYPE (node
) = constr
;
39142 = process_template_parm (parser
->implicit_template_parms
,
39145 /*non_type=*/non_type
,
39146 /*param_pack=*/false);
39148 // Chain the new parameter to the list of implicit parameters.
39149 if (parser
->implicit_template_parms
)
39150 parser
->implicit_template_parms
39151 = TREE_CHAIN (parser
->implicit_template_parms
);
39153 parser
->implicit_template_parms
= new_parm
;
39155 tree new_decl
= get_local_decls ();
39157 /* Return the TEMPLATE_PARM_INDEX, not the PARM_DECL. */
39158 new_decl
= DECL_INITIAL (new_decl
);
39160 /* If creating a fully implicit function template, start the new implicit
39161 template parameter list with this synthesized type, otherwise grow the
39162 current template parameter list. */
39164 if (become_template
)
39166 parent_scope
->level_chain
= current_binding_level
;
39168 tree new_parms
= make_tree_vec (1);
39169 TREE_VEC_ELT (new_parms
, 0) = parser
->implicit_template_parms
;
39170 current_template_parms
= tree_cons (size_int (processing_template_decl
),
39171 new_parms
, current_template_parms
);
39175 tree
& new_parms
= INNERMOST_TEMPLATE_PARMS (current_template_parms
);
39176 int new_parm_idx
= TREE_VEC_LENGTH (new_parms
);
39177 new_parms
= grow_tree_vec (new_parms
, new_parm_idx
+ 1);
39178 TREE_VEC_ELT (new_parms
, new_parm_idx
) = parser
->implicit_template_parms
;
39181 // If the new parameter was constrained, we need to add that to the
39182 // constraints in the template parameter list.
39183 if (tree req
= TEMPLATE_PARM_CONSTRAINTS (tree_last (new_parm
)))
39185 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
39186 reqs
= conjoin_constraints (reqs
, req
);
39187 TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
) = reqs
;
39190 current_binding_level
= entry_scope
;
39195 /* Finish the declaration of a fully implicit function template. Such a
39196 template has no explicit template parameter list so has not been through the
39197 normal template head and tail processing. synthesize_implicit_template_parm
39198 tries to do the head; this tries to do the tail. MEMBER_DECL_OPT should be
39199 provided if the declaration is a class member such that its template
39200 declaration can be completed. If MEMBER_DECL_OPT is provided the finished
39201 form is returned. Otherwise NULL_TREE is returned. */
39204 finish_fully_implicit_template (cp_parser
*parser
, tree member_decl_opt
)
39206 gcc_assert (parser
->fully_implicit_function_template_p
);
39208 if (member_decl_opt
&& member_decl_opt
!= error_mark_node
39209 && DECL_VIRTUAL_P (member_decl_opt
))
39211 error_at (DECL_SOURCE_LOCATION (member_decl_opt
),
39212 "implicit templates may not be %<virtual%>");
39213 DECL_VIRTUAL_P (member_decl_opt
) = false;
39216 if (member_decl_opt
)
39217 member_decl_opt
= finish_member_template_decl (member_decl_opt
);
39218 end_template_decl ();
39220 parser
->fully_implicit_function_template_p
= false;
39221 --parser
->num_template_parameter_lists
;
39223 return member_decl_opt
;
39226 #include "gt-cp-parser.h"