Bug Summary

File:build/gcc/cp/parser.c
Warning:line 32583, column 4
3rd function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name parser.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -resource-dir /usr/lib64/clang/13.0.0 -D IN_GCC_FRONTEND -D IN_GCC -D HAVE_CONFIG_H -I . -I cp -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcpp/include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcody -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber/bid -I ../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libbacktrace -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11 -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/x86_64-suse-linux -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/backward -internal-isystem /usr/lib64/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-narrowing -Wwrite-strings -Wno-error=format-diag -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fdeprecated-macro -fdebug-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=plist-html -analyzer-config silence-checkers=core.NullDereference -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/clang-static-analyzer/2021-11-20-133755-20252-1/report-wDoybH.plist -x c++ /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c
1/* -*- C++ -*- Parser.
2 Copyright (C) 2000-2021 Free Software Foundation, Inc.
3 Written by Mark Mitchell <mark@codesourcery.com>.
4
5 This file is part of GCC.
6
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)
10 any later version.
11
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.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#include "config.h"
22#define INCLUDE_UNIQUE_PTR
23#include "system.h"
24#include "coretypes.h"
25#include "cp-tree.h"
26#include "c-family/c-common.h"
27#include "timevar.h"
28#include "stringpool.h"
29#include "cgraph.h"
30#include "print-tree.h"
31#include "attribs.h"
32#include "trans-mem.h"
33#include "intl.h"
34#include "decl.h"
35#include "c-family/c-objc.h"
36#include "plugin.h"
37#include "tree-pretty-print.h"
38#include "parser.h"
39#include "gomp-constants.h"
40#include "omp-general.h"
41#include "omp-offload.h"
42#include "c-family/c-indentation.h"
43#include "context.h"
44#include "gcc-rich-location.h"
45#include "tree-iterator.h"
46#include "cp-name-hint.h"
47#include "memmodel.h"
48#include "c-family/known-headers.h"
49
50
51/* The lexer. */
52
53/* The cp_lexer_* routines mediate between the lexer proper (in libcpp
54 and c-lex.c) and the C++ parser. */
55
56/* The various kinds of non integral constant we encounter. */
57enum non_integral_constant {
58 NIC_NONE,
59 /* floating-point literal */
60 NIC_FLOAT,
61 /* %<this%> */
62 NIC_THIS,
63 /* %<__FUNCTION__%> */
64 NIC_FUNC_NAME,
65 /* %<__PRETTY_FUNCTION__%> */
66 NIC_PRETTY_FUNC,
67 /* %<__func__%> */
68 NIC_C99_FUNC,
69 /* "%<va_arg%> */
70 NIC_VA_ARG,
71 /* a cast */
72 NIC_CAST,
73 /* %<typeid%> operator */
74 NIC_TYPEID,
75 /* non-constant compound literals */
76 NIC_NCC,
77 /* a function call */
78 NIC_FUNC_CALL,
79 /* an increment */
80 NIC_INC,
81 /* an decrement */
82 NIC_DEC,
83 /* an array reference */
84 NIC_ARRAY_REF,
85 /* %<->%> */
86 NIC_ARROW,
87 /* %<.%> */
88 NIC_POINT,
89 /* the address of a label */
90 NIC_ADDR_LABEL,
91 /* %<*%> */
92 NIC_STAR,
93 /* %<&%> */
94 NIC_ADDR,
95 /* %<++%> */
96 NIC_PREINCREMENT,
97 /* %<--%> */
98 NIC_PREDECREMENT,
99 /* %<new%> */
100 NIC_NEW,
101 /* %<delete%> */
102 NIC_DEL,
103 /* calls to overloaded operators */
104 NIC_OVERLOADED,
105 /* an assignment */
106 NIC_ASSIGNMENT,
107 /* a comma operator */
108 NIC_COMMA,
109 /* a call to a constructor */
110 NIC_CONSTRUCTOR,
111 /* a transaction expression */
112 NIC_TRANSACTION
113};
114
115/* The various kinds of errors about name-lookup failing. */
116enum name_lookup_error {
117 /* NULL */
118 NLE_NULL,
119 /* is not a type */
120 NLE_TYPE,
121 /* is not a class or namespace */
122 NLE_CXX98,
123 /* is not a class, namespace, or enumeration */
124 NLE_NOT_CXX98
125};
126
127/* The various kinds of required token */
128enum required_token {
129 RT_NONE,
130 RT_SEMICOLON, /* ';' */
131 RT_OPEN_PAREN, /* '(' */
132 RT_CLOSE_BRACE, /* '}' */
133 RT_OPEN_BRACE, /* '{' */
134 RT_CLOSE_SQUARE, /* ']' */
135 RT_OPEN_SQUARE, /* '[' */
136 RT_COMMA, /* ',' */
137 RT_SCOPE, /* '::' */
138 RT_LESS, /* '<' */
139 RT_GREATER, /* '>' */
140 RT_EQ, /* '=' */
141 RT_ELLIPSIS, /* '...' */
142 RT_MULT, /* '*' */
143 RT_COMPL, /* '~' */
144 RT_COLON, /* ':' */
145 RT_COLON_SCOPE, /* ':' or '::' */
146 RT_CLOSE_PAREN, /* ')' */
147 RT_COMMA_CLOSE_PAREN, /* ',' or ')' */
148 RT_PRAGMA_EOL, /* end of line */
149 RT_NAME, /* identifier */
150
151 /* The type is CPP_KEYWORD */
152 RT_NEW, /* new */
153 RT_DELETE, /* delete */
154 RT_RETURN, /* return */
155 RT_WHILE, /* while */
156 RT_EXTERN, /* extern */
157 RT_STATIC_ASSERT, /* static_assert */
158 RT_DECLTYPE, /* decltype */
159 RT_OPERATOR, /* operator */
160 RT_CLASS, /* class */
161 RT_TEMPLATE, /* template */
162 RT_NAMESPACE, /* namespace */
163 RT_USING, /* using */
164 RT_ASM, /* asm */
165 RT_TRY, /* try */
166 RT_CATCH, /* catch */
167 RT_THROW, /* throw */
168 RT_AUTO, /* auto */
169 RT_LABEL, /* __label__ */
170 RT_AT_TRY, /* @try */
171 RT_AT_SYNCHRONIZED, /* @synchronized */
172 RT_AT_THROW, /* @throw */
173
174 RT_SELECT, /* selection-statement */
175 RT_ITERATION, /* iteration-statement */
176 RT_JUMP, /* jump-statement */
177 RT_CLASS_KEY, /* class-key */
178 RT_CLASS_TYPENAME_TEMPLATE, /* class, typename, or template */
179 RT_TRANSACTION_ATOMIC, /* __transaction_atomic */
180 RT_TRANSACTION_RELAXED, /* __transaction_relaxed */
181 RT_TRANSACTION_CANCEL, /* __transaction_cancel */
182
183 RT_CO_YIELD /* co_yield */
184};
185
186/* RAII wrapper for parser->in_type_id_in_expr_p, setting it on creation and
187 reverting it on destruction. */
188
189class type_id_in_expr_sentinel
190{
191 cp_parser *parser;
192 bool saved;
193public:
194 type_id_in_expr_sentinel (cp_parser *parser, bool set = true)
195 : parser (parser),
196 saved (parser->in_type_id_in_expr_p)
197 { parser->in_type_id_in_expr_p = set; }
198 ~type_id_in_expr_sentinel ()
199 { parser->in_type_id_in_expr_p = saved; }
200};
201
202/* Prototypes. */
203
204static cp_lexer *cp_lexer_new_main
205 (void);
206static cp_lexer *cp_lexer_new_from_tokens
207 (cp_token_cache *tokens);
208static void cp_lexer_destroy
209 (cp_lexer *);
210static int cp_lexer_saving_tokens
211 (const cp_lexer *);
212static cp_token *cp_lexer_token_at
213 (cp_lexer *, cp_token_position);
214static void cp_lexer_get_preprocessor_token
215 (unsigned, cp_token *);
216static inline cp_token *cp_lexer_peek_token
217 (cp_lexer *);
218static cp_token *cp_lexer_peek_nth_token
219 (cp_lexer *, size_t);
220static inline bool cp_lexer_next_token_is
221 (cp_lexer *, enum cpp_ttype);
222static bool cp_lexer_next_token_is_not
223 (cp_lexer *, enum cpp_ttype);
224static bool cp_lexer_next_token_is_keyword
225 (cp_lexer *, enum rid);
226static cp_token *cp_lexer_consume_token
227 (cp_lexer *);
228static void cp_lexer_purge_token
229 (cp_lexer *);
230static void cp_lexer_purge_tokens_after
231 (cp_lexer *, cp_token_position);
232static void cp_lexer_save_tokens
233 (cp_lexer *);
234static void cp_lexer_commit_tokens
235 (cp_lexer *);
236static void cp_lexer_rollback_tokens
237 (cp_lexer *);
238static void cp_lexer_print_token
239 (FILE *, cp_token *);
240static inline bool cp_lexer_debugging_p
241 (cp_lexer *);
242static void cp_lexer_start_debugging
243 (cp_lexer *) ATTRIBUTE_UNUSED__attribute__ ((__unused__));
244static void cp_lexer_stop_debugging
245 (cp_lexer *) ATTRIBUTE_UNUSED__attribute__ ((__unused__));
246
247static cp_token_cache *cp_token_cache_new
248 (cp_token *, cp_token *);
249static tree cp_parser_late_noexcept_specifier
250 (cp_parser *, tree);
251static void noexcept_override_late_checks
252 (tree, tree);
253
254static void cp_parser_initial_pragma
255 (cp_token *);
256
257static bool cp_parser_omp_declare_reduction_exprs
258 (tree, cp_parser *);
259static void cp_finalize_oacc_routine
260 (cp_parser *, tree, bool);
261
262/* Manifest constants. */
263#define CP_LEXER_BUFFER_SIZE((256 * 1024) / sizeof (cp_token)) ((256 * 1024) / sizeof (cp_token))
264#define CP_SAVED_TOKEN_STACK5 5
265
266/* Variables. */
267
268/* The stream to which debugging output should be written. */
269static FILE *cp_lexer_debug_stream;
270
271/* Nonzero if we are parsing an unevaluated operand: an operand to
272 sizeof, typeof, or alignof. */
273int cp_unevaluated_operand;
274
275/* Dump up to NUM tokens in BUFFER to FILE starting with token
276 START_TOKEN. If START_TOKEN is NULL, the dump starts with the
277 first token in BUFFER. If NUM is 0, dump all the tokens. If
278 CURR_TOKEN is set and it is one of the tokens in BUFFER, it will be
279 highlighted by surrounding it in [[ ]]. */
280
281static void
282cp_lexer_dump_tokens (FILE *file, vec<cp_token, va_gc> *buffer,
283 cp_token *start_token, unsigned num,
284 cp_token *curr_token)
285{
286 unsigned i, nprinted;
287 cp_token *token;
288 bool do_print;
289
290 fprintf (file, "%u tokens\n", vec_safe_length (buffer));
291
292 if (buffer == NULL__null)
293 return;
294
295 if (num == 0)
296 num = buffer->length ();
297
298 if (start_token == NULL__null)
299 start_token = buffer->address ();
300
301 if (start_token > buffer->address ())
302 {
303 cp_lexer_print_token (file, &(*buffer)[0]);
304 fprintf (file, " ... ");
305 }
306
307 do_print = false;
308 nprinted = 0;
309 for (i = 0; buffer->iterate (i, &token) && nprinted < num; i++)
310 {
311 if (token == start_token)
312 do_print = true;
313
314 if (!do_print)
315 continue;
316
317 nprinted++;
318 if (token == curr_token)
319 fprintf (file, "[[");
320
321 cp_lexer_print_token (file, token);
322
323 if (token == curr_token)
324 fprintf (file, "]]");
325
326 switch (token->type)
327 {
328 case CPP_SEMICOLON:
329 case CPP_OPEN_BRACE:
330 case CPP_CLOSE_BRACE:
331 case CPP_EOF:
332 fputc ('\n', file);
333 break;
334
335 default:
336 fputc (' ', file);
337 }
338 }
339
340 if (i == num && i < buffer->length ())
341 {
342 fprintf (file, " ... ");
343 cp_lexer_print_token (file, &buffer->last ());
344 }
345
346 fprintf (file, "\n");
347}
348
349
350/* Dump all tokens in BUFFER to stderr. */
351
352void
353cp_lexer_debug_tokens (vec<cp_token, va_gc> *buffer)
354{
355 cp_lexer_dump_tokens (stderrstderr, buffer, NULL__null, 0, NULL__null);
356}
357
358DEBUG_FUNCTION__attribute__ ((__used__)) void
359debug (vec<cp_token, va_gc> &ref)
360{
361 cp_lexer_dump_tokens (stderrstderr, &ref, NULL__null, 0, NULL__null);
362}
363
364DEBUG_FUNCTION__attribute__ ((__used__)) void
365debug (vec<cp_token, va_gc> *ptr)
366{
367 if (ptr)
368 debug (*ptr);
369 else
370 fprintf (stderrstderr, "<nil>\n");
371}
372
373
374/* Dump the cp_parser tree field T to FILE if T is non-NULL. DESC is the
375 description for T. */
376
377static void
378cp_debug_print_tree_if_set (FILE *file, const char *desc, tree t)
379{
380 if (t)
381 {
382 fprintf (file, "%s: ", desc);
383 print_node_brief (file, "", t, 0);
384 }
385}
386
387
388/* Dump parser context C to FILE. */
389
390static void
391cp_debug_print_context (FILE *file, cp_parser_context *c)
392{
393 const char *status_s[] = { "OK", "ERROR", "COMMITTED" };
394 fprintf (file, "{ status = %s, scope = ", status_s[c->status]);
395 print_node_brief (file, "", c->object_type, 0);
396 fprintf (file, "}\n");
397}
398
399
400/* Print the stack of parsing contexts to FILE starting with FIRST. */
401
402static void
403cp_debug_print_context_stack (FILE *file, cp_parser_context *first)
404{
405 unsigned i;
406 cp_parser_context *c;
407
408 fprintf (file, "Parsing context stack:\n");
409 for (i = 0, c = first; c; c = c->next, i++)
410 {
411 fprintf (file, "\t#%u: ", i);
412 cp_debug_print_context (file, c);
413 }
414}
415
416
417/* Print the value of FLAG to FILE. DESC is a string describing the flag. */
418
419static void
420cp_debug_print_flag (FILE *file, const char *desc, bool flag)
421{
422 if (flag)
423 fprintf (file, "%s: true\n", desc);
424}
425
426
427/* Print an unparsed function entry UF to FILE. */
428
429static void
430cp_debug_print_unparsed_function (FILE *file, cp_unparsed_functions_entry *uf)
431{
432 unsigned i;
433 cp_default_arg_entry *default_arg_fn;
434 tree fn;
435
436 fprintf (file, "\tFunctions with default args:\n");
437 for (i = 0;
438 vec_safe_iterate (uf->funs_with_default_args, i, &default_arg_fn);
439 i++)
440 {
441 fprintf (file, "\t\tClass type: ");
442 print_node_brief (file, "", default_arg_fn->class_type, 0);
443 fprintf (file, "\t\tDeclaration: ");
444 print_node_brief (file, "", default_arg_fn->decl, 0);
445 fprintf (file, "\n");
446 }
447
448 fprintf (file, "\n\tFunctions with definitions that require "
449 "post-processing\n\t\t");
450 for (i = 0; vec_safe_iterate (uf->funs_with_definitions, i, &fn); i++)
451 {
452 print_node_brief (file, "", fn, 0);
453 fprintf (file, " ");
454 }
455 fprintf (file, "\n");
456
457 fprintf (file, "\n\tNon-static data members with initializers that require "
458 "post-processing\n\t\t");
459 for (i = 0; vec_safe_iterate (uf->nsdmis, i, &fn); i++)
460 {
461 print_node_brief (file, "", fn, 0);
462 fprintf (file, " ");
463 }
464 fprintf (file, "\n");
465}
466
467
468/* Print the stack of unparsed member functions S to FILE. */
469
470static void
471cp_debug_print_unparsed_queues (FILE *file,
472 vec<cp_unparsed_functions_entry, va_gc> *s)
473{
474 unsigned i;
475 cp_unparsed_functions_entry *uf;
476
477 fprintf (file, "Unparsed functions\n");
478 for (i = 0; vec_safe_iterate (s, i, &uf); i++)
479 {
480 fprintf (file, "#%u:\n", i);
481 cp_debug_print_unparsed_function (file, uf);
482 }
483}
484
485
486/* Dump the tokens in a window of size WINDOW_SIZE around the next_token for
487 the given PARSER. If FILE is NULL, the output is printed on stderr. */
488
489static void
490cp_debug_parser_tokens (FILE *file, cp_parser *parser, int window_size)
491{
492 cp_token *next_token, *first_token, *start_token;
493
494 if (file == NULL__null)
495 file = stderrstderr;
496
497 next_token = parser->lexer->next_token;
498 first_token = parser->lexer->buffer->address ();
499 start_token = (next_token > first_token + window_size / 2)
500 ? next_token - window_size / 2
501 : first_token;
502 cp_lexer_dump_tokens (file, parser->lexer->buffer, start_token, window_size,
503 next_token);
504}
505
506
507/* Dump debugging information for the given PARSER. If FILE is NULL,
508 the output is printed on stderr. */
509
510void
511cp_debug_parser (FILE *file, cp_parser *parser)
512{
513 const size_t window_size = 20;
514 cp_token *token;
515 expanded_location eloc;
516
517 if (file == NULL__null)
518 file = stderrstderr;
519
520 fprintf (file, "Parser state\n\n");
521 fprintf (file, "Number of tokens: %u\n",
522 vec_safe_length (parser->lexer->buffer));
523 cp_debug_print_tree_if_set (file, "Lookup scope", parser->scope);
524 cp_debug_print_tree_if_set (file, "Object scope",
525 parser->object_scope);
526 cp_debug_print_tree_if_set (file, "Qualifying scope",
527 parser->qualifying_scope);
528 cp_debug_print_context_stack (file, parser->context);
529 cp_debug_print_flag (file, "Allow GNU extensions",
530 parser->allow_gnu_extensions_p);
531 cp_debug_print_flag (file, "'>' token is greater-than",
532 parser->greater_than_is_operator_p);
533 cp_debug_print_flag (file, "Default args allowed in current "
534 "parameter list", parser->default_arg_ok_p);
535 cp_debug_print_flag (file, "Parsing integral constant-expression",
536 parser->integral_constant_expression_p);
537 cp_debug_print_flag (file, "Allow non-constant expression in current "
538 "constant-expression",
539 parser->allow_non_integral_constant_expression_p);
540 cp_debug_print_flag (file, "Seen non-constant expression",
541 parser->non_integral_constant_expression_p);
542 cp_debug_print_flag (file, "Local names forbidden in current context",
543 (parser->local_variables_forbidden_p
544 & LOCAL_VARS_FORBIDDEN(1 << 0)));
545 cp_debug_print_flag (file, "'this' forbidden in current context",
546 (parser->local_variables_forbidden_p
547 & THIS_FORBIDDEN(1 << 1)));
548 cp_debug_print_flag (file, "In unbraced linkage specification",
549 parser->in_unbraced_linkage_specification_p);
550 cp_debug_print_flag (file, "Parsing a declarator",
551 parser->in_declarator_p);
552 cp_debug_print_flag (file, "In template argument list",
553 parser->in_template_argument_list_p);
554 cp_debug_print_flag (file, "Parsing an iteration statement",
555 parser->in_statement & IN_ITERATION_STMT2);
556 cp_debug_print_flag (file, "Parsing a switch statement",
557 parser->in_statement & IN_SWITCH_STMT1);
558 cp_debug_print_flag (file, "Parsing a structured OpenMP block",
559 parser->in_statement & IN_OMP_BLOCK4);
560 cp_debug_print_flag (file, "Parsing an OpenMP loop",
561 parser->in_statement & IN_OMP_FOR8);
562 cp_debug_print_flag (file, "Parsing an if statement",
563 parser->in_statement & IN_IF_STMT16);
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, "String expressions should be translated "
567 "to execution character set",
568 parser->translate_strings_p);
569 cp_debug_print_flag (file, "Parsing function body outside of a "
570 "local class", parser->in_function_body);
571 cp_debug_print_flag (file, "Auto correct a colon to a scope operator",
572 parser->colon_corrects_to_scope_p);
573 cp_debug_print_flag (file, "Colon doesn't start a class definition",
574 parser->colon_doesnt_start_class_def_p);
575 cp_debug_print_flag (file, "Parsing an Objective-C++ message context",
576 parser->objective_c_message_context_p);
577 if (parser->type_definition_forbidden_message)
578 fprintf (file, "Error message for forbidden type definitions: %s %s\n",
579 parser->type_definition_forbidden_message,
580 parser->type_definition_forbidden_message_arg
581 ? parser->type_definition_forbidden_message_arg : "<none>");
582 cp_debug_print_unparsed_queues (file, parser->unparsed_queues);
583 fprintf (file, "Number of class definitions in progress: %u\n",
584 parser->num_classes_being_defined);
585 fprintf (file, "Number of template parameter lists for the current "
586 "declaration: %u\n", parser->num_template_parameter_lists);
587 cp_debug_parser_tokens (file, parser, window_size);
588 token = parser->lexer->next_token;
589 fprintf (file, "Next token to parse:\n");
590 fprintf (file, "\tToken: ");
591 cp_lexer_print_token (file, token);
592 eloc = expand_location (token->location);
593 fprintf (file, "\n\tFile: %s\n", eloc.file);
594 fprintf (file, "\tLine: %d\n", eloc.line);
595 fprintf (file, "\tColumn: %d\n", eloc.column);
596}
597
598DEBUG_FUNCTION__attribute__ ((__used__)) void
599debug (cp_parser &ref)
600{
601 cp_debug_parser (stderrstderr, &ref);
602}
603
604DEBUG_FUNCTION__attribute__ ((__used__)) void
605debug (cp_parser *ptr)
606{
607 if (ptr)
608 debug (*ptr);
609 else
610 fprintf (stderrstderr, "<nil>\n");
611}
612
613/* Allocate memory for a new lexer object and return it. */
614
615static cp_lexer *
616cp_lexer_alloc (void)
617{
618 /* Allocate the memory. */
619 cp_lexer *lexer = ggc_cleared_alloc<cp_lexer> ();
620
621 /* Initially we are not debugging. */
622 lexer->debugging_p = false;
623
624 lexer->saved_tokens.create (CP_SAVED_TOKEN_STACK5);
625
626 /* Create the buffer. */
627 vec_alloc (lexer->buffer, CP_LEXER_BUFFER_SIZE((256 * 1024) / sizeof (cp_token)));
628
629 return lexer;
630}
631
632/* Create a new main C++ lexer, the lexer that gets tokens from the
633 preprocessor. */
634
635static cp_lexer *
636cp_lexer_new_main (void)
637{
638 cp_token token;
639
640 /* It's possible that parsing the first pragma will load a PCH file,
641 which is a GC collection point. So we have to do that before
642 allocating any memory. */
643 cp_lexer_get_preprocessor_token (0, &token);
644 cp_parser_initial_pragma (&token);
645 c_common_no_more_pch ();
646
647 cp_lexer *lexer = cp_lexer_alloc ();
648 /* Put the first token in the buffer. */
649 cp_token *tok = lexer->buffer->quick_push (token);
650
651 uintptr_t filter = 0;
652 if (modules_p ())
653 filter = module_token_cdtor (parse_in, filter);
654
655 /* Get the remaining tokens from the preprocessor. */
656 while (tok->type != CPP_EOF)
657 {
658 if (filter)
659 /* Process the previous token. */
660 module_token_lang (tok->type, tok->keyword, tok->u.value,
661 tok->location, filter);
662 tok = vec_safe_push (lexer->buffer, cp_token ());
663 cp_lexer_get_preprocessor_token (C_LEX_STRING_NO_JOIN2, tok);
664 }
665
666 lexer->next_token = lexer->buffer->address ();
667 lexer->last_token = lexer->next_token
668 + lexer->buffer->length ()
669 - 1;
670
671 if (lexer->buffer->length () != 1)
672 {
673 /* Set the EOF token's location to be the just after the previous
674 token's range. That way 'at-eof' diagnostics point at something
675 meaninful. */
676 auto range = get_range_from_loc (line_table, tok[-1].location);
677 tok[0].location
678 = linemap_position_for_loc_and_offset (line_table, range.m_finish, 1);
679 }
680
681 if (filter)
682 module_token_cdtor (parse_in, filter);
683
684 /* Subsequent preprocessor diagnostics should use compiler
685 diagnostic functions to get the compiler source location. */
686 done_lexing = true;
687
688 maybe_check_all_macros (parse_in);
689
690 gcc_assert (!lexer->next_token->purged_p)((void)(!(!lexer->next_token->purged_p) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 690, __FUNCTION__), 0 : 0))
;
691 return lexer;
692}
693
694/* Create a new lexer whose token stream is primed with the tokens in
695 CACHE. When these tokens are exhausted, no new tokens will be read. */
696
697static cp_lexer *
698cp_lexer_new_from_tokens (cp_token_cache *cache)
699{
700 cp_token *first = cache->first;
701 cp_token *last = cache->last;
702 cp_lexer *lexer = ggc_cleared_alloc<cp_lexer> ();
703
704 /* We do not own the buffer. */
705 lexer->buffer = NULL__null;
706
707 /* Insert an EOF token. */
708 lexer->saved_type = last->type;
709 lexer->saved_keyword = last->keyword;
710 last->type = CPP_EOF;
711 last->keyword = RID_MAX;
712
713 lexer->next_token = first;
714 lexer->last_token = last;
715
716 lexer->saved_tokens.create (CP_SAVED_TOKEN_STACK5);
717
718 /* Initially we are not debugging. */
719 lexer->debugging_p = false;
720
721 gcc_assert (!lexer->next_token->purged_p((void)(!(!lexer->next_token->purged_p && !lexer
->last_token->purged_p) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 722, __FUNCTION__), 0 : 0))
722 && !lexer->last_token->purged_p)((void)(!(!lexer->next_token->purged_p && !lexer
->last_token->purged_p) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 722, __FUNCTION__), 0 : 0))
;
723 return lexer;
724}
725
726/* Frees all resources associated with LEXER. */
727
728static void
729cp_lexer_destroy (cp_lexer *lexer)
730{
731 if (lexer->buffer)
732 vec_free (lexer->buffer);
733 else
734 {
735 /* Restore the token we overwrite with EOF. */
736 lexer->last_token->type = lexer->saved_type;
737 lexer->last_token->keyword = lexer->saved_keyword;
738 }
739 lexer->saved_tokens.release ();
740 ggc_free (lexer);
741}
742
743/* This needs to be set to TRUE before the lexer-debugging infrastructure can
744 be used. The point of this flag is to help the compiler to fold away calls
745 to cp_lexer_debugging_p within this source file at compile time, when the
746 lexer is not being debugged. */
747
748#define LEXER_DEBUGGING_ENABLED_Pfalse false
749
750/* Returns nonzero if debugging information should be output. */
751
752static inline bool
753cp_lexer_debugging_p (cp_lexer *lexer)
754{
755 if (!LEXER_DEBUGGING_ENABLED_Pfalse)
756 return false;
757
758 return lexer->debugging_p;
759}
760
761
762static inline cp_token_position
763cp_lexer_token_position (cp_lexer *lexer, bool previous_p)
764{
765 return lexer->next_token - previous_p;
766}
767
768static inline cp_token *
769cp_lexer_token_at (cp_lexer * /*lexer*/, cp_token_position pos)
770{
771 return pos;
772}
773
774static inline void
775cp_lexer_set_token_position (cp_lexer *lexer, cp_token_position pos)
776{
777 lexer->next_token = cp_lexer_token_at (lexer, pos);
778}
779
780static inline cp_token_position
781cp_lexer_previous_token_position (cp_lexer *lexer)
782{
783 return cp_lexer_token_position (lexer, true);
784}
785
786static inline cp_token *
787cp_lexer_previous_token (cp_lexer *lexer)
788{
789 cp_token_position tp = cp_lexer_previous_token_position (lexer);
790
791 /* Skip past purged tokens. */
792 while (tp->purged_p)
793 {
794 gcc_assert (tp != vec_safe_address (lexer->buffer))((void)(!(tp != vec_safe_address (lexer->buffer)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 794, __FUNCTION__), 0 : 0))
;
795 tp--;
796 }
797
798 return cp_lexer_token_at (lexer, tp);
799}
800
801/* Same as above, but return NULL when the lexer doesn't own the token
802 buffer or if the next_token is at the start of the token
803 vector or if all previous tokens are purged. */
804
805static cp_token *
806cp_lexer_safe_previous_token (cp_lexer *lexer)
807{
808 if (lexer->buffer
809 && lexer->next_token != lexer->buffer->address ())
810 {
811 cp_token_position tp = cp_lexer_previous_token_position (lexer);
812
813 /* Skip past purged tokens. */
814 while (tp->purged_p)
815 {
816 if (tp == lexer->buffer->address ())
817 return NULL__null;
818 tp--;
819 }
820 return cp_lexer_token_at (lexer, tp);
821 }
822
823 return NULL__null;
824}
825
826/* Overload for make_location, taking the lexer to mean the location of the
827 previous token. */
828
829static inline location_t
830make_location (location_t caret, location_t start, cp_lexer *lexer)
831{
832 cp_token *t = cp_lexer_previous_token (lexer);
833 return make_location (caret, start, t->location);
834}
835
836/* Overload for make_location taking tokens instead of locations. */
837
838static inline location_t
839make_location (cp_token *caret, cp_token *start, cp_token *end)
840{
841 return make_location (caret->location, start->location, end->location);
842}
843
844/* nonzero if we are presently saving tokens. */
845
846static inline int
847cp_lexer_saving_tokens (const cp_lexer* lexer)
848{
849 return lexer->saved_tokens.length () != 0;
850}
851
852/* Store the next token from the preprocessor in *TOKEN. Return true
853 if we reach EOF. If LEXER is NULL, assume we are handling an
854 initial #pragma pch_preprocess, and thus want the lexer to return
855 processed strings. */
856
857static void
858cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token)
859{
860 static int is_extern_c = 0;
861
862 /* Get a new token from the preprocessor. */
863 token->type
864 = c_lex_with_flags (&token->u.value, &token->location, &token->flags,
865 flags);
866 token->keyword = RID_MAX;
867 token->purged_p = false;
868 token->error_reported = false;
869 token->tree_check_p = false;
870 /* Usually never see a zero, but just in case ... */
871 token->main_source_p = line_table->depth <= 1;
872
873 /* On some systems, some header files are surrounded by an
874 implicit extern "C" block. Set a flag in the token if it
875 comes from such a header. */
876 is_extern_c += pending_lang_change;
877 pending_lang_change = 0;
878 token->implicit_extern_c = is_extern_c > 0;
879
880 /* Check to see if this token is a keyword. */
881 if (token->type == CPP_NAME)
882 {
883 if (IDENTIFIER_KEYWORD_P (token->u.value)((!((tree_not_check2 (((tree_check ((token->u.value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 883, __FUNCTION__, (IDENTIFIER_NODE)))), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 883, __FUNCTION__, (TREE_VEC), (SSA_NAME)))->base.u.bits
.lang_flag_2)) & (!((tree_not_check2 (((tree_check ((token
->u.value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 883, __FUNCTION__, (IDENTIFIER_NODE)))), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 883, __FUNCTION__, (TREE_VEC), (SSA_NAME)))->base.u.bits
.lang_flag_1)) & ((tree_not_check2 (((tree_check ((token->
u.value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 883, __FUNCTION__, (IDENTIFIER_NODE)))), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 883, __FUNCTION__, (TREE_VEC), (SSA_NAME)))->base.u.bits
.lang_flag_0))
)
884 {
885 /* Mark this token as a keyword. */
886 token->type = CPP_KEYWORD;
887 /* Record which keyword. */
888 token->keyword = C_RID_CODE (token->u.value)((enum rid) (((struct c_common_identifier *) (token->u.value
))->node.rid_code))
;
889 }
890 else
891 {
892 if (warn_cxx11_compatglobal_options.x_warn_cxx11_compat
893 && C_RID_CODE (token->u.value)((enum rid) (((struct c_common_identifier *) (token->u.value
))->node.rid_code))
>= RID_FIRST_CXX11
894 && C_RID_CODE (token->u.value)((enum rid) (((struct c_common_identifier *) (token->u.value
))->node.rid_code))
<= RID_LAST_CXX11)
895 {
896 /* Warn about the C++0x keyword (but still treat it as
897 an identifier). */
898 warning_at (token->location, OPT_Wc__11_compat,
899 "identifier %qE is a keyword in C++11",
900 token->u.value);
901
902 /* Clear out the C_RID_CODE so we don't warn about this
903 particular identifier-turned-keyword again. */
904 C_SET_RID_CODE (token->u.value, RID_MAX)(((struct c_common_identifier *) (token->u.value))->node
.rid_code = (unsigned char) RID_MAX)
;
905 }
906 if (warn_cxx20_compatglobal_options.x_warn_cxx20_compat
907 && C_RID_CODE (token->u.value)((enum rid) (((struct c_common_identifier *) (token->u.value
))->node.rid_code))
>= RID_FIRST_CXX20
908 && C_RID_CODE (token->u.value)((enum rid) (((struct c_common_identifier *) (token->u.value
))->node.rid_code))
<= RID_LAST_CXX20)
909 {
910 /* Warn about the C++20 keyword (but still treat it as
911 an identifier). */
912 warning_at (token->location, OPT_Wc__20_compat,
913 "identifier %qE is a keyword in C++20",
914 token->u.value);
915
916 /* Clear out the C_RID_CODE so we don't warn about this
917 particular identifier-turned-keyword again. */
918 C_SET_RID_CODE (token->u.value, RID_MAX)(((struct c_common_identifier *) (token->u.value))->node
.rid_code = (unsigned char) RID_MAX)
;
919 }
920
921 token->keyword = RID_MAX;
922 }
923 }
924 else if (token->type == CPP_AT_NAME)
925 {
926 /* This only happens in Objective-C++; it must be a keyword. */
927 token->type = CPP_KEYWORD;
928 switch (C_RID_CODE (token->u.value)((enum rid) (((struct c_common_identifier *) (token->u.value
))->node.rid_code))
)
929 {
930 /* Replace 'class' with '@class', 'private' with '@private',
931 etc. This prevents confusion with the C++ keyword
932 'class', and makes the tokens consistent with other
933 Objective-C 'AT' keywords. For example '@class' is
934 reported as RID_AT_CLASS which is consistent with
935 '@synchronized', which is reported as
936 RID_AT_SYNCHRONIZED.
937 */
938 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
939 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
940 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
941 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
942 case RID_THROW: token->keyword = RID_AT_THROW; break;
943 case RID_TRY: token->keyword = RID_AT_TRY; break;
944 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
945 case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break;
946 default: token->keyword = C_RID_CODE (token->u.value)((enum rid) (((struct c_common_identifier *) (token->u.value
))->node.rid_code))
;
947 }
948 }
949}
950
951/* Update the globals input_location and the input file stack from TOKEN. */
952static inline void
953cp_lexer_set_source_position_from_token (cp_token *token)
954{
955 input_location = token->location;
956}
957
958/* Update the globals input_location and the input file stack from LEXER. */
959static inline void
960cp_lexer_set_source_position (cp_lexer *lexer)
961{
962 cp_token *token = cp_lexer_peek_token (lexer);
963 cp_lexer_set_source_position_from_token (token);
964}
965
966/* Return a pointer to the next token in the token stream, but do not
967 consume it. */
968
969static inline cp_token *
970cp_lexer_peek_token (cp_lexer *lexer)
971{
972 if (cp_lexer_debugging_p (lexer))
973 {
974 fputs ("cp_lexer: peeking at token: ", cp_lexer_debug_stream);
975 cp_lexer_print_token (cp_lexer_debug_stream, lexer->next_token);
976 putc ('\n', cp_lexer_debug_stream);
977 }
978 return lexer->next_token;
979}
980
981/* Return true if the next token has the indicated TYPE. */
982
983static inline bool
984cp_lexer_next_token_is (cp_lexer* lexer, enum cpp_ttype type)
985{
986 return cp_lexer_peek_token (lexer)->type == type;
987}
988
989/* Return true if the next token does not have the indicated TYPE. */
990
991static inline bool
992cp_lexer_next_token_is_not (cp_lexer* lexer, enum cpp_ttype type)
993{
994 return !cp_lexer_next_token_is (lexer, type);
995}
996
997/* Return true if the next token is the indicated KEYWORD. */
998
999static inline bool
1000cp_lexer_next_token_is_keyword (cp_lexer* lexer, enum rid keyword)
1001{
1002 return cp_lexer_peek_token (lexer)->keyword == keyword;
1003}
1004
1005static inline bool
1006cp_lexer_nth_token_is (cp_lexer* lexer, size_t n, enum cpp_ttype type)
1007{
1008 return cp_lexer_peek_nth_token (lexer, n)->type == type;
1009}
1010
1011static inline bool
1012cp_lexer_nth_token_is_keyword (cp_lexer* lexer, size_t n, enum rid keyword)
1013{
1014 return cp_lexer_peek_nth_token (lexer, n)->keyword == keyword;
1015}
1016
1017/* Return true if KEYWORD can start a decl-specifier. */
1018
1019bool
1020cp_keyword_starts_decl_specifier_p (enum rid keyword)
1021{
1022 switch (keyword)
1023 {
1024 /* auto specifier: storage-class-specifier in C++,
1025 simple-type-specifier in C++0x. */
1026 case RID_AUTO:
1027 /* Storage classes. */
1028 case RID_REGISTER:
1029 case RID_STATIC:
1030 case RID_EXTERN:
1031 case RID_MUTABLE:
1032 case RID_THREAD:
1033 /* Elaborated type specifiers. */
1034 case RID_ENUM:
1035 case RID_CLASS:
1036 case RID_STRUCT:
1037 case RID_UNION:
1038 case RID_TYPENAME:
1039 /* Simple type specifiers. */
1040 case RID_CHAR:
1041 case RID_CHAR8:
1042 case RID_CHAR16:
1043 case RID_CHAR32:
1044 case RID_WCHAR:
1045 case RID_BOOL:
1046 case RID_SHORT:
1047 case RID_INT:
1048 case RID_LONG:
1049 case RID_SIGNED:
1050 case RID_UNSIGNED:
1051 case RID_FLOAT:
1052 case RID_DOUBLE:
1053 case RID_VOID:
1054 /* CV qualifiers. */
1055 case RID_CONST:
1056 case RID_VOLATILE:
1057 /* Function specifiers. */
1058 case RID_EXPLICIT:
1059 case RID_VIRTUAL:
1060 /* friend/typdef/inline specifiers. */
1061 case RID_FRIEND:
1062 case RID_TYPEDEF:
1063 case RID_INLINE:
1064 /* GNU extensions. */
1065 case RID_TYPEOF:
1066 /* C++11 extensions. */
1067 case RID_DECLTYPE:
1068 case RID_UNDERLYING_TYPE:
1069 case RID_CONSTEXPR:
1070 /* C++20 extensions. */
1071 case RID_CONSTINIT:
1072 case RID_CONSTEVAL:
1073 return true;
1074
1075 default:
1076 if (keyword >= RID_FIRST_INT_N
1077 && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS1
1078 && int_n_enabled_p[keyword - RID_FIRST_INT_N])
1079 return true;
1080 return false;
1081 }
1082}
1083
1084/* Return true if the next token is a keyword for a decl-specifier. */
1085
1086static bool
1087cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer)
1088{
1089 cp_token *token;
1090
1091 token = cp_lexer_peek_token (lexer);
1092 return cp_keyword_starts_decl_specifier_p (token->keyword);
1093}
1094
1095/* Returns TRUE iff the token T begins a decltype type. */
1096
1097static bool
1098token_is_decltype (cp_token *t)
1099{
1100 return (t->keyword == RID_DECLTYPE
1101 || t->type == CPP_DECLTYPE((enum cpp_ttype) (((enum cpp_ttype) (((enum cpp_ttype) (CPP_KEYWORD
+ 1)) + 1)) + 1))
);
1102}
1103
1104/* Returns TRUE iff the next token begins a decltype type. */
1105
1106static bool
1107cp_lexer_next_token_is_decltype (cp_lexer *lexer)
1108{
1109 cp_token *t = cp_lexer_peek_token (lexer);
1110 return token_is_decltype (t);
1111}
1112
1113/* Called when processing a token with tree_check_value; perform or defer the
1114 associated checks and return the value. */
1115
1116static tree
1117saved_checks_value (struct tree_check *check_value)
1118{
1119 /* Perform any access checks that were deferred. */
1120 vec<deferred_access_check, va_gc> *checks;
1121 deferred_access_check *chk;
1122 checks = check_value->checks;
1123 if (checks)
1124 {
1125 int i;
1126 FOR_EACH_VEC_SAFE_ELT (checks, i, chk)for (i = 0; vec_safe_iterate ((checks), (i), &(chk)); ++(
i))
1127 perform_or_defer_access_check (chk->binfo,
1128 chk->decl,
1129 chk->diag_decl, tf_warning_or_error);
1130 }
1131 /* Return the stored value. */
1132 return check_value->value;
1133}
1134
1135/* Return a pointer to the Nth token in the token stream. If N is 1,
1136 then this is precisely equivalent to cp_lexer_peek_token (except
1137 that it is not inline). One would like to disallow that case, but
1138 there is one case (cp_parser_nth_token_starts_template_id) where
1139 the caller passes a variable for N and it might be 1. */
1140
1141static cp_token *
1142cp_lexer_peek_nth_token (cp_lexer* lexer, size_t n)
1143{
1144 cp_token *token;
1145
1146 /* N is 1-based, not zero-based. */
1147 gcc_assert (n > 0)((void)(!(n > 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1147, __FUNCTION__), 0 : 0))
;
1148
1149 if (cp_lexer_debugging_p (lexer))
1150 fprintf (cp_lexer_debug_stream,
1151 "cp_lexer: peeking ahead %ld at token: ", (long)n);
1152
1153 --n;
1154 token = lexer->next_token;
1155 while (n && token->type != CPP_EOF)
1156 {
1157 ++token;
1158 if (!token->purged_p)
1159 --n;
1160 }
1161
1162 if (cp_lexer_debugging_p (lexer))
1163 {
1164 cp_lexer_print_token (cp_lexer_debug_stream, token);
1165 putc ('\n', cp_lexer_debug_stream);
1166 }
1167
1168 return token;
1169}
1170
1171/* Return the next token, and advance the lexer's next_token pointer
1172 to point to the next non-purged token. */
1173
1174static cp_token *
1175cp_lexer_consume_token (cp_lexer* lexer)
1176{
1177 cp_token *token = lexer->next_token;
1178
1179 do
1180 {
1181 gcc_assert (token->type != CPP_EOF)((void)(!(token->type != CPP_EOF) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1181, __FUNCTION__), 0 : 0))
;
1182 lexer->next_token++;
1183 }
1184 while (lexer->next_token->purged_p);
1185
1186 cp_lexer_set_source_position_from_token (token);
1187
1188 /* Provide debugging output. */
1189 if (cp_lexer_debugging_p (lexer))
1190 {
1191 fputs ("cp_lexer: consuming token: ", cp_lexer_debug_stream);
1192 cp_lexer_print_token (cp_lexer_debug_stream, token);
1193 putc ('\n', cp_lexer_debug_stream);
1194 }
1195
1196 return token;
1197}
1198
1199/* Permanently remove the next token from the token stream, and
1200 advance the next_token pointer to refer to the next non-purged
1201 token. */
1202
1203static void
1204cp_lexer_purge_token (cp_lexer *lexer)
1205{
1206 cp_token *tok = lexer->next_token;
1207
1208 gcc_assert (tok->type != CPP_EOF)((void)(!(tok->type != CPP_EOF) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1208, __FUNCTION__), 0 : 0))
;
1209 tok->purged_p = true;
1210 tok->location = UNKNOWN_LOCATION((location_t) 0);
1211 tok->u.value = NULL_TREE(tree) __null;
1212 tok->keyword = RID_MAX;
1213
1214 do
1215 tok++;
1216 while (tok->purged_p);
1217 lexer->next_token = tok;
1218}
1219
1220/* Permanently remove all tokens after TOK, up to, but not
1221 including, the token that will be returned next by
1222 cp_lexer_peek_token. */
1223
1224static void
1225cp_lexer_purge_tokens_after (cp_lexer *lexer, cp_token *tok)
1226{
1227 cp_token *peek = lexer->next_token;
1228
1229 gcc_assert (tok < peek)((void)(!(tok < peek) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1229, __FUNCTION__), 0 : 0))
;
1230
1231 for (tok++; tok != peek; tok++)
1232 {
1233 tok->purged_p = true;
1234 tok->location = UNKNOWN_LOCATION((location_t) 0);
1235 tok->u.value = NULL_TREE(tree) __null;
1236 tok->keyword = RID_MAX;
1237 }
1238}
1239
1240/* Begin saving tokens. All tokens consumed after this point will be
1241 preserved. */
1242
1243static void
1244cp_lexer_save_tokens (cp_lexer* lexer)
1245{
1246 /* Provide debugging output. */
1247 if (cp_lexer_debugging_p (lexer))
1248 fprintf (cp_lexer_debug_stream, "cp_lexer: saving tokens\n");
1249
1250 lexer->saved_tokens.safe_push (lexer->next_token);
1251}
1252
1253/* Commit to the portion of the token stream most recently saved. */
1254
1255static void
1256cp_lexer_commit_tokens (cp_lexer* lexer)
1257{
1258 /* Provide debugging output. */
1259 if (cp_lexer_debugging_p (lexer))
1260 fprintf (cp_lexer_debug_stream, "cp_lexer: committing tokens\n");
1261
1262 lexer->saved_tokens.pop ();
1263}
1264
1265/* Return all tokens saved since the last call to cp_lexer_save_tokens
1266 to the token stream. Stop saving tokens. */
1267
1268static void
1269cp_lexer_rollback_tokens (cp_lexer* lexer)
1270{
1271 /* Provide debugging output. */
1272 if (cp_lexer_debugging_p (lexer))
1273 fprintf (cp_lexer_debug_stream, "cp_lexer: restoring tokens\n");
1274
1275 lexer->next_token = lexer->saved_tokens.pop ();
1276}
1277
1278/* RAII wrapper around the above functions, with sanity checking. Creating
1279 a variable saves tokens, which are committed when the variable is
1280 destroyed unless they are explicitly rolled back by calling the rollback
1281 member function. */
1282
1283struct saved_token_sentinel
1284{
1285 cp_lexer *lexer;
1286 unsigned len;
1287 bool commit;
1288 saved_token_sentinel(cp_lexer *lexer): lexer(lexer), commit(true)
1289 {
1290 len = lexer->saved_tokens.length ();
1291 cp_lexer_save_tokens (lexer);
1292 }
1293 void rollback ()
1294 {
1295 cp_lexer_rollback_tokens (lexer);
1296 commit = false;
1297 }
1298 ~saved_token_sentinel()
1299 {
1300 if (commit)
1301 cp_lexer_commit_tokens (lexer);
1302 gcc_assert (lexer->saved_tokens.length () == len)((void)(!(lexer->saved_tokens.length () == len) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1302, __FUNCTION__), 0 : 0))
;
1303 }
1304};
1305
1306/* Print a representation of the TOKEN on the STREAM. */
1307
1308static void
1309cp_lexer_print_token (FILE * stream, cp_token *token)
1310{
1311 /* We don't use cpp_type2name here because the parser defines
1312 a few tokens of its own. */
1313 static const char *const token_names[] = {
1314 /* cpplib-defined token types */
1315#define OP(e, s) #e,
1316#define TK(e, s) #e,
1317 TTYPE_TABLEOP(EQ, "=") OP(NOT, "!") OP(GREATER, ">") OP(LESS, "<")
OP(PLUS, "+") OP(MINUS, "-") OP(MULT, "*") OP(DIV, "/") OP(MOD
, "%") OP(AND, "&") OP(OR, "|") OP(XOR, "^") OP(RSHIFT, ">>"
) OP(LSHIFT, "<<") OP(COMPL, "~") OP(AND_AND, "&&"
) OP(OR_OR, "||") OP(QUERY, "?") OP(COLON, ":") OP(COMMA, ","
) OP(OPEN_PAREN, "(") OP(CLOSE_PAREN, ")") TK((-1), NONE) OP(
EQ_EQ, "==") OP(NOT_EQ, "!=") OP(GREATER_EQ, ">=") OP(LESS_EQ
, "<=") OP(SPACESHIP, "<=>") OP(PLUS_EQ, "+=") OP(MINUS_EQ
, "-=") OP(MULT_EQ, "*=") OP(DIV_EQ, "/=") OP(MOD_EQ, "%=") OP
(AND_EQ, "&=") OP(OR_EQ, "|=") OP(XOR_EQ, "^=") OP(RSHIFT_EQ
, ">>=") OP(LSHIFT_EQ, "<<=") OP(HASH, "#") OP(PASTE
, "##") OP(OPEN_SQUARE, "[") OP(CLOSE_SQUARE, "]") OP(OPEN_BRACE
, "{") OP(CLOSE_BRACE, "}") OP(SEMICOLON, ";") OP(ELLIPSIS, "..."
) OP(PLUS_PLUS, "++") OP(MINUS_MINUS, "--") OP(DEREF, "->"
) OP(DOT, ".") OP(SCOPE, "::") OP(DEREF_STAR, "->*") OP(DOT_STAR
, ".*") OP(ATSIGN, "@") TK(NAME, IDENT) TK(AT_NAME, IDENT) TK
(NUMBER, LITERAL) TK(CHAR, LITERAL) TK(WCHAR, LITERAL) TK(CHAR16
, LITERAL) TK(CHAR32, LITERAL) TK(UTF8CHAR, LITERAL) TK(OTHER
, LITERAL) TK(STRING, LITERAL) TK(WSTRING, LITERAL) TK(STRING16
, LITERAL) TK(STRING32, LITERAL) TK(UTF8STRING, LITERAL) TK(OBJC_STRING
, LITERAL) TK(HEADER_NAME, LITERAL) TK(CHAR_USERDEF, LITERAL)
TK(WCHAR_USERDEF, LITERAL) TK(CHAR16_USERDEF, LITERAL) TK(CHAR32_USERDEF
, LITERAL) TK(UTF8CHAR_USERDEF, LITERAL) TK(STRING_USERDEF, LITERAL
) TK(WSTRING_USERDEF, LITERAL) TK(STRING16_USERDEF, LITERAL) TK
(STRING32_USERDEF, LITERAL) TK(UTF8STRING_USERDEF,LITERAL) TK
(COMMENT, LITERAL) TK(MACRO_ARG, NONE) TK(PRAGMA, NONE) TK(PRAGMA_EOL
, NONE) TK(PADDING, NONE)
1318#undef OP
1319#undef TK
1320 /* C++ parser token types - see "Manifest constants", above. */
1321 "KEYWORD",
1322 "TEMPLATE_ID",
1323 "NESTED_NAME_SPECIFIER",
1324 };
1325
1326 /* For some tokens, print the associated data. */
1327 switch (token->type)
1328 {
1329 case CPP_KEYWORD:
1330 /* Some keywords have a value that is not an IDENTIFIER_NODE.
1331 For example, `struct' is mapped to an INTEGER_CST. */
1332 if (!identifier_p (token->u.value))
1333 break;
1334 /* fall through */
1335 case CPP_NAME:
1336 fputs (IDENTIFIER_POINTER (token->u.value)((const char *) (tree_check ((token->u.value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1336, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
, stream);
1337 break;
1338
1339 case CPP_STRING:
1340 case CPP_STRING16:
1341 case CPP_STRING32:
1342 case CPP_WSTRING:
1343 case CPP_UTF8STRING:
1344 fprintf (stream, " \"%s\"", TREE_STRING_POINTER (token->u.value)((const char *)((tree_check ((token->u.value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1344, __FUNCTION__, (STRING_CST)))->string.str))
);
1345 break;
1346
1347 case CPP_NUMBER:
1348 print_generic_expr (stream, token->u.value);
1349 break;
1350
1351 default:
1352 /* If we have a name for the token, print it out. Otherwise, we
1353 simply give the numeric code. */
1354 if (token->type < ARRAY_SIZE(token_names)(sizeof (token_names) / sizeof ((token_names)[0])))
1355 fputs (token_names[token->type], stream);
1356 else
1357 fprintf (stream, "[%d]", token->type);
1358 break;
1359 }
1360}
1361
1362DEBUG_FUNCTION__attribute__ ((__used__)) void
1363debug (cp_token &ref)
1364{
1365 cp_lexer_print_token (stderrstderr, &ref);
1366 fprintf (stderrstderr, "\n");
1367}
1368
1369DEBUG_FUNCTION__attribute__ ((__used__)) void
1370debug (cp_token *ptr)
1371{
1372 if (ptr)
1373 debug (*ptr);
1374 else
1375 fprintf (stderrstderr, "<nil>\n");
1376}
1377
1378
1379/* Start emitting debugging information. */
1380
1381static void
1382cp_lexer_start_debugging (cp_lexer* lexer)
1383{
1384 if (!LEXER_DEBUGGING_ENABLED_Pfalse)
1385 fatal_error (input_location,
1386 "%<LEXER_DEBUGGING_ENABLED_P%> is not set to true");
1387
1388 lexer->debugging_p = true;
1389 cp_lexer_debug_stream = stderrstderr;
1390}
1391
1392/* Stop emitting debugging information. */
1393
1394static void
1395cp_lexer_stop_debugging (cp_lexer* lexer)
1396{
1397 if (!LEXER_DEBUGGING_ENABLED_Pfalse)
1398 fatal_error (input_location,
1399 "%<LEXER_DEBUGGING_ENABLED_P%> is not set to true");
1400
1401 lexer->debugging_p = false;
1402 cp_lexer_debug_stream = NULL__null;
1403}
1404
1405/* Create a new cp_token_cache, representing a range of tokens. */
1406
1407static cp_token_cache *
1408cp_token_cache_new (cp_token *first, cp_token *last)
1409{
1410 cp_token_cache *cache = ggc_alloc<cp_token_cache> ();
1411 cache->first = first;
1412 cache->last = last;
1413 return cache;
1414}
1415
1416/* Diagnose if #pragma omp declare simd isn't followed immediately
1417 by function declaration or definition. */
1418
1419static inline void
1420cp_ensure_no_omp_declare_simd (cp_parser *parser)
1421{
1422 if (parser->omp_declare_simd && !parser->omp_declare_simd->error_seen)
1423 {
1424 error ("%<#pragma omp declare %s%> not immediately followed by "
1425 "function declaration or definition",
1426 parser->omp_declare_simd->variant_p ? "variant" : "simd");
1427 parser->omp_declare_simd = NULL__null;
1428 }
1429}
1430
1431/* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
1432 and put that into "omp declare simd" attribute. */
1433
1434static inline void
1435cp_finalize_omp_declare_simd (cp_parser *parser, tree fndecl)
1436{
1437 if (__builtin_expect (parser->omp_declare_simd != NULL__null, 0))
1438 {
1439 if (fndecl == error_mark_nodeglobal_trees[TI_ERROR_MARK])
1440 {
1441 parser->omp_declare_simd = NULL__null;
1442 return;
1443 }
1444 if (TREE_CODE (fndecl)((enum tree_code) (fndecl)->base.code) != FUNCTION_DECL)
1445 {
1446 cp_ensure_no_omp_declare_simd (parser);
1447 return;
1448 }
1449 }
1450}
1451
1452/* Similarly, but for use in declaration parsing functions
1453 which call cp_parser_handle_directive_omp_attributes. */
1454
1455static inline void
1456cp_finalize_omp_declare_simd (cp_parser *parser, cp_omp_declare_simd_data *data)
1457{
1458 if (parser->omp_declare_simd != data)
1459 return;
1460
1461 if (!parser->omp_declare_simd->error_seen
1462 && !parser->omp_declare_simd->fndecl_seen)
1463 error_at (parser->omp_declare_simd->loc,
1464 "%<declare %s%> directive not immediately followed by "
1465 "function declaration or definition",
1466 parser->omp_declare_simd->variant_p ? "variant" : "simd");
1467 parser->omp_declare_simd = NULL__null;
1468}
1469
1470/* Diagnose if #pragma acc routine isn't followed immediately by function
1471 declaration or definition. */
1472
1473static inline void
1474cp_ensure_no_oacc_routine (cp_parser *parser)
1475{
1476 if (parser->oacc_routine && !parser->oacc_routine->error_seen)
1477 {
1478 error_at (parser->oacc_routine->loc,
1479 "%<#pragma acc routine%> not immediately followed by "
1480 "function declaration or definition");
1481 parser->oacc_routine = NULL__null;
1482 }
1483}
1484
1485/* Decl-specifiers. */
1486
1487/* Set *DECL_SPECS to represent an empty decl-specifier-seq. */
1488
1489static void
1490clear_decl_specs (cp_decl_specifier_seq *decl_specs)
1491{
1492 memset (decl_specs, 0, sizeof (cp_decl_specifier_seq));
1493}
1494
1495/* Declarators. */
1496
1497/* Nothing other than the parser should be creating declarators;
1498 declarators are a semi-syntactic representation of C++ entities.
1499 Other parts of the front end that need to create entities (like
1500 VAR_DECLs or FUNCTION_DECLs) should do that directly. */
1501
1502static cp_declarator *make_call_declarator
1503 (cp_declarator *, tree, cp_cv_quals, cp_virt_specifiers, cp_ref_qualifier,
1504 tree, tree, tree, tree, location_t);
1505static cp_declarator *make_array_declarator
1506 (cp_declarator *, tree);
1507static cp_declarator *make_pointer_declarator
1508 (cp_cv_quals, cp_declarator *, tree);
1509static cp_declarator *make_reference_declarator
1510 (cp_cv_quals, cp_declarator *, bool, tree);
1511static cp_declarator *make_ptrmem_declarator
1512 (cp_cv_quals, tree, cp_declarator *, tree);
1513
1514/* An erroneous declarator. */
1515static cp_declarator *cp_error_declarator;
1516
1517/* The obstack on which declarators and related data structures are
1518 allocated. */
1519static struct obstack declarator_obstack;
1520
1521/* Alloc BYTES from the declarator memory pool. */
1522
1523static inline void *
1524alloc_declarator (size_t bytes)
1525{
1526 return obstack_alloc (&declarator_obstack, bytes)__extension__ ({ struct obstack *__h = (&declarator_obstack
); __extension__ ({ struct obstack *__o = (__h); size_t __len
= ((bytes)); if (__extension__ ({ struct obstack const *__o1
= (__o); (size_t) (__o1->chunk_limit - __o1->next_free
); }) < __len) _obstack_newchunk (__o, __len); ((void) ((__o
)->next_free += (__len))); }); __extension__ ({ struct obstack
*__o1 = (__h); void *__value = (void *) __o1->object_base
; if (__o1->next_free == __value) __o1->maybe_empty_object
= 1; __o1->next_free = (sizeof (ptrdiff_t) < sizeof (void
*) ? ((__o1->object_base) + (((__o1->next_free) - (__o1
->object_base) + (__o1->alignment_mask)) & ~(__o1->
alignment_mask))) : (char *) (((ptrdiff_t) (__o1->next_free
) + (__o1->alignment_mask)) & ~(__o1->alignment_mask
))); if ((size_t) (__o1->next_free - (char *) __o1->chunk
) > (size_t) (__o1->chunk_limit - (char *) __o1->chunk
)) __o1->next_free = __o1->chunk_limit; __o1->object_base
= __o1->next_free; __value; }); })
;
1527}
1528
1529/* Allocate a declarator of the indicated KIND. Clear fields that are
1530 common to all declarators. */
1531
1532static cp_declarator *
1533make_declarator (cp_declarator_kind kind)
1534{
1535 cp_declarator *declarator;
1536
1537 declarator = (cp_declarator *) alloc_declarator (sizeof (cp_declarator));
1538 declarator->kind = kind;
1539 declarator->parenthesized = UNKNOWN_LOCATION((location_t) 0);
1540 declarator->attributes = NULL_TREE(tree) __null;
1541 declarator->std_attributes = NULL_TREE(tree) __null;
1542 declarator->declarator = NULL__null;
1543 declarator->parameter_pack_p = false;
1544 declarator->id_loc = UNKNOWN_LOCATION((location_t) 0);
1545
1546 return declarator;
1547}
1548
1549/* Make a declarator for a generalized identifier. If
1550 QUALIFYING_SCOPE is non-NULL, the identifier is
1551 QUALIFYING_SCOPE::UNQUALIFIED_NAME; otherwise, it is just
1552 UNQUALIFIED_NAME. SFK indicates the kind of special function this
1553 is, if any. */
1554
1555static cp_declarator *
1556make_id_declarator (tree qualifying_scope, tree unqualified_name,
1557 special_function_kind sfk, location_t id_location)
1558{
1559 cp_declarator *declarator;
1560
1561 /* It is valid to write:
1562
1563 class C { void f(); };
1564 typedef C D;
1565 void D::f();
1566
1567 The standard is not clear about whether `typedef const C D' is
1568 legal; as of 2002-09-15 the committee is considering that
1569 question. EDG 3.0 allows that syntax. Therefore, we do as
1570 well. */
1571 if (qualifying_scope && TYPE_P (qualifying_scope)(tree_code_type[(int) (((enum tree_code) (qualifying_scope)->
base.code))] == tcc_type)
)
1572 qualifying_scope = TYPE_MAIN_VARIANT (qualifying_scope)((tree_class_check ((qualifying_scope), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1572, __FUNCTION__))->type_common.main_variant)
;
1573
1574 gcc_assert (identifier_p (unqualified_name)((void)(!(identifier_p (unqualified_name) || ((enum tree_code
) (unqualified_name)->base.code) == BIT_NOT_EXPR || ((enum
tree_code) (unqualified_name)->base.code) == TEMPLATE_ID_EXPR
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1576, __FUNCTION__), 0 : 0))
1575 || TREE_CODE (unqualified_name) == BIT_NOT_EXPR((void)(!(identifier_p (unqualified_name) || ((enum tree_code
) (unqualified_name)->base.code) == BIT_NOT_EXPR || ((enum
tree_code) (unqualified_name)->base.code) == TEMPLATE_ID_EXPR
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1576, __FUNCTION__), 0 : 0))
1576 || TREE_CODE (unqualified_name) == TEMPLATE_ID_EXPR)((void)(!(identifier_p (unqualified_name) || ((enum tree_code
) (unqualified_name)->base.code) == BIT_NOT_EXPR || ((enum
tree_code) (unqualified_name)->base.code) == TEMPLATE_ID_EXPR
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 1576, __FUNCTION__), 0 : 0))
;
1577
1578 declarator = make_declarator (cdk_id);
1579 declarator->u.id.qualifying_scope = qualifying_scope;
1580 declarator->u.id.unqualified_name = unqualified_name;
1581 declarator->u.id.sfk = sfk;
1582 declarator->id_loc = id_location;
1583
1584 return declarator;
1585}
1586
1587/* Make a declarator for a pointer to TARGET. CV_QUALIFIERS is a list
1588 of modifiers such as const or volatile to apply to the pointer
1589 type, represented as identifiers. ATTRIBUTES represent the attributes that
1590 appertain to the pointer or reference. */
1591
1592cp_declarator *
1593make_pointer_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target,
1594 tree attributes)
1595{
1596 cp_declarator *declarator;
1597
1598 declarator = make_declarator (cdk_pointer);
1599 declarator->declarator = target;
1600 declarator->u.pointer.qualifiers = cv_qualifiers;
1601 declarator->u.pointer.class_type = NULL_TREE(tree) __null;
1602 if (target)
1603 {
1604 declarator->id_loc = target->id_loc;
1605 declarator->parameter_pack_p = target->parameter_pack_p;
1606 target->parameter_pack_p = false;
1607 }
1608 else
1609 declarator->parameter_pack_p = false;
1610
1611 declarator->std_attributes = attributes;
1612
1613 return declarator;
1614}
1615
1616/* Like make_pointer_declarator -- but for references. ATTRIBUTES
1617 represent the attributes that appertain to the pointer or
1618 reference. */
1619
1620cp_declarator *
1621make_reference_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target,
1622 bool rvalue_ref, tree attributes)
1623{
1624 cp_declarator *declarator;
1625
1626 declarator = make_declarator (cdk_reference);
1627 declarator->declarator = target;
1628 declarator->u.reference.qualifiers = cv_qualifiers;
1629 declarator->u.reference.rvalue_ref = rvalue_ref;
1630 if (target)
1631 {
1632 declarator->id_loc = target->id_loc;
1633 declarator->parameter_pack_p = target->parameter_pack_p;
1634 target->parameter_pack_p = false;
1635 }
1636 else
1637 declarator->parameter_pack_p = false;
1638
1639 declarator->std_attributes = attributes;
1640
1641 return declarator;
1642}
1643
1644/* Like make_pointer_declarator -- but for a pointer to a non-static
1645 member of CLASS_TYPE. ATTRIBUTES represent the attributes that
1646 appertain to the pointer or reference. */
1647
1648cp_declarator *
1649make_ptrmem_declarator (cp_cv_quals cv_qualifiers, tree class_type,
1650 cp_declarator *pointee,
1651 tree attributes)
1652{
1653 cp_declarator *declarator;
1654
1655 declarator = make_declarator (cdk_ptrmem);
1656 declarator->declarator = pointee;
1657 declarator->u.pointer.qualifiers = cv_qualifiers;
1658 declarator->u.pointer.class_type = class_type;
1659
1660 if (pointee)
1661 {
1662 declarator->parameter_pack_p = pointee->parameter_pack_p;
1663 pointee->parameter_pack_p = false;
1664 }
1665 else
1666 declarator->parameter_pack_p = false;
1667
1668 declarator->std_attributes = attributes;
1669
1670 return declarator;
1671}
1672
1673/* Make a declarator for the function given by TARGET, with the
1674 indicated PARMS. The CV_QUALIFIERS apply to the function, as in
1675 "const"-qualified member function. The EXCEPTION_SPECIFICATION
1676 indicates what exceptions can be thrown. */
1677
1678cp_declarator *
1679make_call_declarator (cp_declarator *target,
1680 tree parms,
1681 cp_cv_quals cv_qualifiers,
1682 cp_virt_specifiers virt_specifiers,
1683 cp_ref_qualifier ref_qualifier,
1684 tree tx_qualifier,
1685 tree exception_specification,
1686 tree late_return_type,
1687 tree requires_clause,
1688 location_t parens_loc)
1689{
1690 cp_declarator *declarator;
1691
1692 declarator = make_declarator (cdk_function);
1693 declarator->declarator = target;
1694 declarator->u.function.parameters = parms;
1695 declarator->u.function.qualifiers = cv_qualifiers;
1696 declarator->u.function.virt_specifiers = virt_specifiers;
1697 declarator->u.function.ref_qualifier = ref_qualifier;
1698 declarator->u.function.tx_qualifier = tx_qualifier;
1699 declarator->u.function.exception_specification = exception_specification;
1700 declarator->u.function.late_return_type = late_return_type;
1701 declarator->u.function.requires_clause = requires_clause;
1702 declarator->u.function.parens_loc = parens_loc;
1703 if (target)
1704 {
1705 declarator->id_loc = target->id_loc;
1706 declarator->parameter_pack_p = target->parameter_pack_p;
1707 target->parameter_pack_p = false;
1708 }
1709 else
1710 declarator->parameter_pack_p = false;
1711
1712 return declarator;
1713}
1714
1715/* Make a declarator for an array of BOUNDS elements, each of which is
1716 defined by ELEMENT. */
1717
1718cp_declarator *
1719make_array_declarator (cp_declarator *element, tree bounds)
1720{
1721 cp_declarator *declarator;
1722
1723 declarator = make_declarator (cdk_array);
1724 declarator->declarator = element;
1725 declarator->u.array.bounds = bounds;
1726 if (element)
1727 {
1728 declarator->id_loc = element->id_loc;
1729 declarator->parameter_pack_p = element->parameter_pack_p;
1730 element->parameter_pack_p = false;
1731 }
1732 else
1733 declarator->parameter_pack_p = false;
1734
1735 return declarator;
1736}
1737
1738/* Determine whether the declarator we've seen so far can be a
1739 parameter pack, when followed by an ellipsis. */
1740static bool
1741declarator_can_be_parameter_pack (cp_declarator *declarator)
1742{
1743 if (declarator && declarator->parameter_pack_p)
1744 /* We already saw an ellipsis. */
1745 return false;
1746
1747 /* Search for a declarator name, or any other declarator that goes
1748 after the point where the ellipsis could appear in a parameter
1749 pack. If we find any of these, then this declarator cannot be
1750 made into a parameter pack. */
1751 bool found = false;
1752 while (declarator && !found)
1753 {
1754 switch ((int)declarator->kind)
1755 {
1756 case cdk_id:
1757 case cdk_array:
1758 case cdk_decomp:
1759 found = true;
1760 break;
1761
1762 case cdk_error:
1763 return true;
1764
1765 default:
1766 declarator = declarator->declarator;
1767 break;
1768 }
1769 }
1770
1771 return !found;
1772}
1773
1774cp_parameter_declarator *no_parameters;
1775
1776/* Create a parameter declarator with the indicated DECL_SPECIFIERS,
1777 DECLARATOR and DEFAULT_ARGUMENT. */
1778
1779cp_parameter_declarator *
1780make_parameter_declarator (cp_decl_specifier_seq *decl_specifiers,
1781 cp_declarator *declarator,
1782 tree default_argument,
1783 location_t loc,
1784 bool template_parameter_pack_p = false)
1785{
1786 cp_parameter_declarator *parameter;
1787
1788 parameter = ((cp_parameter_declarator *)
1789 alloc_declarator (sizeof (cp_parameter_declarator)));
1790 parameter->next = NULL__null;
1791 if (decl_specifiers)
1792 parameter->decl_specifiers = *decl_specifiers;
1793 else
1794 clear_decl_specs (&parameter->decl_specifiers);
1795 parameter->declarator = declarator;
1796 parameter->default_argument = default_argument;
1797 parameter->template_parameter_pack_p = template_parameter_pack_p;
1798 parameter->loc = loc;
1799
1800 return parameter;
1801}
1802
1803/* Returns true iff DECLARATOR is a declaration for a function. */
1804
1805static bool
1806function_declarator_p (const cp_declarator *declarator)
1807{
1808 while (declarator)
1809 {
1810 if (declarator->kind == cdk_function
1811 && declarator->declarator->kind == cdk_id)
1812 return true;
1813 if (declarator->kind == cdk_id
1814 || declarator->kind == cdk_decomp
1815 || declarator->kind == cdk_error)
1816 return false;
1817 declarator = declarator->declarator;
1818 }
1819 return false;
1820}
1821
1822/* The parser. */
1823
1824/* Overview
1825 --------
1826
1827 A cp_parser parses the token stream as specified by the C++
1828 grammar. Its job is purely parsing, not semantic analysis. For
1829 example, the parser breaks the token stream into declarators,
1830 expressions, statements, and other similar syntactic constructs.
1831 It does not check that the types of the expressions on either side
1832 of an assignment-statement are compatible, or that a function is
1833 not declared with a parameter of type `void'.
1834
1835 The parser invokes routines elsewhere in the compiler to perform
1836 semantic analysis and to build up the abstract syntax tree for the
1837 code processed.
1838
1839 The parser (and the template instantiation code, which is, in a
1840 way, a close relative of parsing) are the only parts of the
1841 compiler that should be calling push_scope and pop_scope, or
1842 related functions. The parser (and template instantiation code)
1843 keeps track of what scope is presently active; everything else
1844 should simply honor that. (The code that generates static
1845 initializers may also need to set the scope, in order to check
1846 access control correctly when emitting the initializers.)
1847
1848 Methodology
1849 -----------
1850
1851 The parser is of the standard recursive-descent variety. Upcoming
1852 tokens in the token stream are examined in order to determine which
1853 production to use when parsing a non-terminal. Some C++ constructs
1854 require arbitrary look ahead to disambiguate. For example, it is
1855 impossible, in the general case, to tell whether a statement is an
1856 expression or declaration without scanning the entire statement.
1857 Therefore, the parser is capable of "parsing tentatively." When the
1858 parser is not sure what construct comes next, it enters this mode.
1859 Then, while we attempt to parse the construct, the parser queues up
1860 error messages, rather than issuing them immediately, and saves the
1861 tokens it consumes. If the construct is parsed successfully, the
1862 parser "commits", i.e., it issues any queued error messages and
1863 the tokens that were being preserved are permanently discarded.
1864 If, however, the construct is not parsed successfully, the parser
1865 rolls back its state completely so that it can resume parsing using
1866 a different alternative.
1867
1868 Future Improvements
1869 -------------------
1870
1871 The performance of the parser could probably be improved substantially.
1872 We could often eliminate the need to parse tentatively by looking ahead
1873 a little bit. In some places, this approach might not entirely eliminate
1874 the need to parse tentatively, but it might still speed up the average
1875 case. */
1876
1877/* Flags that are passed to some parsing functions. These values can
1878 be bitwise-ored together. */
1879
1880enum
1881{
1882 /* No flags. */
1883 CP_PARSER_FLAGS_NONE = 0x0,
1884 /* The construct is optional. If it is not present, then no error
1885 should be issued. */
1886 CP_PARSER_FLAGS_OPTIONAL = 0x1,
1887 /* When parsing a type-specifier, treat user-defined type-names
1888 as non-type identifiers. */
1889 CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES = 0x2,
1890 /* When parsing a type-specifier, do not try to parse a class-specifier
1891 or enum-specifier. */
1892 CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS = 0x4,
1893 /* When parsing a decl-specifier-seq, only allow type-specifier or
1894 constexpr. */
1895 CP_PARSER_FLAGS_ONLY_TYPE_OR_CONSTEXPR = 0x8,
1896 /* When parsing a decl-specifier-seq, only allow mutable, constexpr or
1897 for C++20 consteval. */
1898 CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR = 0x10,
1899 /* When parsing a decl-specifier-seq, allow missing typename. */
1900 CP_PARSER_FLAGS_TYPENAME_OPTIONAL = 0x20,
1901 /* When parsing of the noexcept-specifier should be delayed. */
1902 CP_PARSER_FLAGS_DELAY_NOEXCEPT = 0x40,
1903 /* When parsing a consteval declarator. */
1904 CP_PARSER_FLAGS_CONSTEVAL = 0x80
1905};
1906
1907/* This type is used for parameters and variables which hold
1908 combinations of the above flags. */
1909typedef int cp_parser_flags;
1910
1911/* The different kinds of declarators we want to parse. */
1912
1913enum cp_parser_declarator_kind
1914{
1915 /* We want an abstract declarator. */
1916 CP_PARSER_DECLARATOR_ABSTRACT,
1917 /* We want a named declarator. */
1918 CP_PARSER_DECLARATOR_NAMED,
1919 /* We don't mind, but the name must be an unqualified-id. */
1920 CP_PARSER_DECLARATOR_EITHER
1921};
1922
1923/* The precedence values used to parse binary expressions. The minimum value
1924 of PREC must be 1, because zero is reserved to quickly discriminate
1925 binary operators from other tokens. */
1926
1927enum cp_parser_prec
1928{
1929 PREC_NOT_OPERATOR,
1930 PREC_LOGICAL_OR_EXPRESSION,
1931 PREC_LOGICAL_AND_EXPRESSION,
1932 PREC_INCLUSIVE_OR_EXPRESSION,
1933 PREC_EXCLUSIVE_OR_EXPRESSION,
1934 PREC_AND_EXPRESSION,
1935 PREC_EQUALITY_EXPRESSION,
1936 PREC_RELATIONAL_EXPRESSION,
1937 PREC_SPACESHIP_EXPRESSION,
1938 PREC_SHIFT_EXPRESSION,
1939 PREC_ADDITIVE_EXPRESSION,
1940 PREC_MULTIPLICATIVE_EXPRESSION,
1941 PREC_PM_EXPRESSION,
1942 NUM_PREC_VALUES = PREC_PM_EXPRESSION
1943};
1944
1945/* A mapping from a token type to a corresponding tree node type, with a
1946 precedence value. */
1947
1948struct cp_parser_binary_operations_map_node
1949{
1950 /* The token type. */
1951 enum cpp_ttype token_type;
1952 /* The corresponding tree code. */
1953 enum tree_code tree_type;
1954 /* The precedence of this operator. */
1955 enum cp_parser_prec prec;
1956};
1957
1958struct cp_parser_expression_stack_entry
1959{
1960 /* Left hand side of the binary operation we are currently
1961 parsing. */
1962 cp_expr lhs;
1963 /* Original tree code for left hand side, if it was a binary
1964 expression itself (used for -Wparentheses). */
1965 enum tree_code lhs_type;
1966 /* Tree code for the binary operation we are parsing. */
1967 enum tree_code tree_type;
1968 /* Precedence of the binary operation we are parsing. */
1969 enum cp_parser_prec prec;
1970 /* Location of the binary operation we are parsing. */
1971 location_t loc;
1972};
1973
1974/* The stack for storing partial expressions. We only need NUM_PREC_VALUES
1975 entries because precedence levels on the stack are monotonically
1976 increasing. */
1977typedef struct cp_parser_expression_stack_entry
1978 cp_parser_expression_stack[NUM_PREC_VALUES];
1979
1980/* Prototypes. */
1981
1982/* Constructors and destructors. */
1983
1984static cp_parser_context *cp_parser_context_new
1985 (cp_parser_context *);
1986
1987/* Class variables. */
1988
1989static GTY((deletable)) cp_parser_context* cp_parser_context_free_list;
1990
1991/* The operator-precedence table used by cp_parser_binary_expression.
1992 Transformed into an associative array (binops_by_token) by
1993 cp_parser_new. */
1994
1995static const cp_parser_binary_operations_map_node binops[] = {
1996 { CPP_DEREF_STAR, MEMBER_REF, PREC_PM_EXPRESSION },
1997 { CPP_DOT_STAR, DOTSTAR_EXPR, PREC_PM_EXPRESSION },
1998
1999 { CPP_MULT, MULT_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
2000 { CPP_DIV, TRUNC_DIV_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
2001 { CPP_MOD, TRUNC_MOD_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
2002
2003 { CPP_PLUS, PLUS_EXPR, PREC_ADDITIVE_EXPRESSION },
2004 { CPP_MINUS, MINUS_EXPR, PREC_ADDITIVE_EXPRESSION },
2005
2006 { CPP_LSHIFT, LSHIFT_EXPR, PREC_SHIFT_EXPRESSION },
2007 { CPP_RSHIFT, RSHIFT_EXPR, PREC_SHIFT_EXPRESSION },
2008
2009 { CPP_SPACESHIP, SPACESHIP_EXPR, PREC_SPACESHIP_EXPRESSION },
2010
2011 { CPP_LESS, LT_EXPR, PREC_RELATIONAL_EXPRESSION },
2012 { CPP_GREATER, GT_EXPR, PREC_RELATIONAL_EXPRESSION },
2013 { CPP_LESS_EQ, LE_EXPR, PREC_RELATIONAL_EXPRESSION },
2014 { CPP_GREATER_EQ, GE_EXPR, PREC_RELATIONAL_EXPRESSION },
2015
2016 { CPP_EQ_EQ, EQ_EXPR, PREC_EQUALITY_EXPRESSION },
2017 { CPP_NOT_EQ, NE_EXPR, PREC_EQUALITY_EXPRESSION },
2018
2019 { CPP_AND, BIT_AND_EXPR, PREC_AND_EXPRESSION },
2020
2021 { CPP_XOR, BIT_XOR_EXPR, PREC_EXCLUSIVE_OR_EXPRESSION },
2022
2023 { CPP_OR, BIT_IOR_EXPR, PREC_INCLUSIVE_OR_EXPRESSION },
2024
2025 { CPP_AND_AND, TRUTH_ANDIF_EXPR, PREC_LOGICAL_AND_EXPRESSION },
2026
2027 { CPP_OR_OR, TRUTH_ORIF_EXPR, PREC_LOGICAL_OR_EXPRESSION }
2028};
2029
2030/* The same as binops, but initialized by cp_parser_new so that
2031 binops_by_token[N].token_type == N. Used in cp_parser_binary_expression
2032 for speed. */
2033static cp_parser_binary_operations_map_node binops_by_token[N_CP_TTYPES((int) (((enum cpp_ttype) (((enum cpp_ttype) (((enum cpp_ttype
) (((enum cpp_ttype) (CPP_KEYWORD + 1)) + 1)) + 1)) + 1)) + 1
))
];
2034
2035/* Constructors and destructors. */
2036
2037/* Construct a new context. The context below this one on the stack
2038 is given by NEXT. */
2039
2040static cp_parser_context *
2041cp_parser_context_new (cp_parser_context* next)
2042{
2043 cp_parser_context *context;
2044
2045 /* Allocate the storage. */
2046 if (cp_parser_context_free_list != NULL__null)
2047 {
2048 /* Pull the first entry from the free list. */
2049 context = cp_parser_context_free_list;
2050 cp_parser_context_free_list = context->next;
2051 memset (context, 0, sizeof (*context));
2052 }
2053 else
2054 context = ggc_cleared_alloc<cp_parser_context> ();
2055
2056 /* No errors have occurred yet in this context. */
2057 context->status = CP_PARSER_STATUS_KIND_NO_ERROR;
2058 /* If this is not the bottommost context, copy information that we
2059 need from the previous context. */
2060 if (next)
2061 {
2062 /* If, in the NEXT context, we are parsing an `x->' or `x.'
2063 expression, then we are parsing one in this context, too. */
2064 context->object_type = next->object_type;
2065 /* Thread the stack. */
2066 context->next = next;
2067 }
2068
2069 return context;
2070}
2071
2072/* Managing the unparsed function queues. */
2073
2074#define unparsed_funs_with_default_argsparser->unparsed_queues->last ().funs_with_default_args \
2075 parser->unparsed_queues->last ().funs_with_default_args
2076#define unparsed_funs_with_definitionsparser->unparsed_queues->last ().funs_with_definitions \
2077 parser->unparsed_queues->last ().funs_with_definitions
2078#define unparsed_nsdmisparser->unparsed_queues->last ().nsdmis \
2079 parser->unparsed_queues->last ().nsdmis
2080#define unparsed_noexceptsparser->unparsed_queues->last ().noexcepts \
2081 parser->unparsed_queues->last ().noexcepts
2082
2083static void
2084push_unparsed_function_queues (cp_parser *parser)
2085{
2086 cp_unparsed_functions_entry e = { NULL__null, make_tree_vector (), NULL__null, NULL__null };
2087 vec_safe_push (parser->unparsed_queues, e);
2088}
2089
2090static void
2091pop_unparsed_function_queues (cp_parser *parser)
2092{
2093 release_tree_vector (unparsed_funs_with_definitionsparser->unparsed_queues->last ().funs_with_definitions);
2094 parser->unparsed_queues->pop ();
2095}
2096
2097/* Prototypes. */
2098
2099/* Constructors and destructors. */
2100
2101static cp_parser *cp_parser_new
2102 (cp_lexer *);
2103
2104/* Routines to parse various constructs.
2105
2106 Those that return `tree' will return the error_mark_node (rather
2107 than NULL_TREE) if a parse error occurs, unless otherwise noted.
2108 Sometimes, they will return an ordinary node if error-recovery was
2109 attempted, even though a parse error occurred. So, to check
2110 whether or not a parse error occurred, you should always use
2111 cp_parser_error_occurred. If the construct is optional (indicated
2112 either by an `_opt' in the name of the function that does the
2113 parsing or via a FLAGS parameter), then NULL_TREE is returned if
2114 the construct is not present. */
2115
2116/* Lexical conventions [gram.lex] */
2117
2118static cp_expr cp_parser_identifier
2119 (cp_parser *);
2120static cp_expr cp_parser_string_literal
2121 (cp_parser *, bool, bool, bool);
2122static cp_expr cp_parser_userdef_char_literal
2123 (cp_parser *);
2124static tree cp_parser_userdef_string_literal
2125 (tree);
2126static cp_expr cp_parser_userdef_numeric_literal
2127 (cp_parser *);
2128
2129/* Basic concepts [gram.basic] */
2130
2131static void cp_parser_translation_unit (cp_parser *);
2132
2133/* Expressions [gram.expr] */
2134
2135static cp_expr cp_parser_primary_expression
2136 (cp_parser *, bool, bool, bool, cp_id_kind *);
2137static cp_expr cp_parser_id_expression
2138 (cp_parser *, bool, bool, bool *, bool, bool);
2139static cp_expr cp_parser_unqualified_id
2140 (cp_parser *, bool, bool, bool, bool);
2141static tree cp_parser_nested_name_specifier_opt
2142 (cp_parser *, bool, bool, bool, bool, bool = false);
2143static tree cp_parser_nested_name_specifier
2144 (cp_parser *, bool, bool, bool, bool);
2145static tree cp_parser_qualifying_entity
2146 (cp_parser *, bool, bool, bool, bool, bool);
2147static cp_expr cp_parser_postfix_expression
2148 (cp_parser *, bool, bool, bool, bool, cp_id_kind *);
2149static tree cp_parser_postfix_open_square_expression
2150 (cp_parser *, tree, bool, bool);
2151static tree cp_parser_postfix_dot_deref_expression
2152 (cp_parser *, enum cpp_ttype, cp_expr, bool, cp_id_kind *, location_t);
2153static vec<tree, va_gc> *cp_parser_parenthesized_expression_list
2154 (cp_parser *, int, bool, bool, bool *, location_t * = NULL__null,
2155 bool = false);
2156/* Values for the second parameter of cp_parser_parenthesized_expression_list. */
2157enum { non_attr = 0, normal_attr = 1, id_attr = 2 };
2158static void cp_parser_pseudo_destructor_name
2159 (cp_parser *, tree, tree *, tree *);
2160static cp_expr cp_parser_unary_expression
2161 (cp_parser *, cp_id_kind * = NULL__null, bool = false, bool = false, bool = false);
2162static enum tree_code cp_parser_unary_operator
2163 (cp_token *);
2164static tree cp_parser_has_attribute_expression
2165 (cp_parser *);
2166static tree cp_parser_new_expression
2167 (cp_parser *);
2168static vec<tree, va_gc> *cp_parser_new_placement
2169 (cp_parser *);
2170static tree cp_parser_new_type_id
2171 (cp_parser *, tree *);
2172static cp_declarator *cp_parser_new_declarator_opt
2173 (cp_parser *);
2174static cp_declarator *cp_parser_direct_new_declarator
2175 (cp_parser *);
2176static vec<tree, va_gc> *cp_parser_new_initializer
2177 (cp_parser *);
2178static tree cp_parser_delete_expression
2179 (cp_parser *);
2180static cp_expr cp_parser_cast_expression
2181 (cp_parser *, bool, bool, bool, cp_id_kind *);
2182static cp_expr cp_parser_binary_expression
2183 (cp_parser *, bool, bool, enum cp_parser_prec, cp_id_kind *);
2184static tree cp_parser_question_colon_clause
2185 (cp_parser *, cp_expr);
2186static cp_expr cp_parser_assignment_expression
2187 (cp_parser *, cp_id_kind * = NULL__null, bool = false, bool = false);
2188static enum tree_code cp_parser_assignment_operator_opt
2189 (cp_parser *);
2190static cp_expr cp_parser_expression
2191 (cp_parser *, cp_id_kind * = NULL__null, bool = false, bool = false, bool = false);
2192static cp_expr cp_parser_constant_expression
2193 (cp_parser *, int = 0, bool * = NULL__null, bool = false);
2194static cp_expr cp_parser_builtin_offsetof
2195 (cp_parser *);
2196static cp_expr cp_parser_lambda_expression
2197 (cp_parser *);
2198static void cp_parser_lambda_introducer
2199 (cp_parser *, tree);
2200static bool cp_parser_lambda_declarator_opt
2201 (cp_parser *, tree);
2202static void cp_parser_lambda_body
2203 (cp_parser *, tree);
2204
2205/* Statements [gram.stmt.stmt] */
2206
2207static void cp_parser_statement
2208 (cp_parser *, tree, bool, bool *, vec<tree> * = NULL__null, location_t * = NULL__null);
2209static void cp_parser_label_for_labeled_statement
2210(cp_parser *, tree);
2211static tree cp_parser_expression_statement
2212 (cp_parser *, tree);
2213static tree cp_parser_compound_statement
2214 (cp_parser *, tree, int, bool);
2215static void cp_parser_statement_seq_opt
2216 (cp_parser *, tree);
2217static tree cp_parser_selection_statement
2218 (cp_parser *, bool *, vec<tree> *);
2219static tree cp_parser_condition
2220 (cp_parser *);
2221static tree cp_parser_iteration_statement
2222 (cp_parser *, bool *, bool, unsigned short);
2223static bool cp_parser_init_statement
2224 (cp_parser *, tree *decl);
2225static tree cp_parser_for
2226 (cp_parser *, bool, unsigned short);
2227static tree cp_parser_c_for
2228 (cp_parser *, tree, tree, bool, unsigned short);
2229static tree cp_parser_range_for
2230 (cp_parser *, tree, tree, tree, bool, unsigned short, bool);
2231static void do_range_for_auto_deduction
2232 (tree, tree);
2233static tree cp_parser_perform_range_for_lookup
2234 (tree, tree *, tree *);
2235static tree cp_parser_range_for_member_function
2236 (tree, tree);
2237static tree cp_parser_jump_statement
2238 (cp_parser *);
2239static void cp_parser_declaration_statement
2240 (cp_parser *);
2241
2242static tree cp_parser_implicitly_scoped_statement
2243 (cp_parser *, bool *, const token_indent_info &, vec<tree> * = NULL__null);
2244static void cp_parser_already_scoped_statement
2245 (cp_parser *, bool *, const token_indent_info &);
2246
2247/* State of module-declaration parsing. */
2248enum module_parse
2249{
2250 MP_NOT_MODULE, /* Not a module. */
2251
2252 _MP_UNUSED,
2253
2254 MP_FIRST, /* First declaration of TU. */
2255 MP_GLOBAL, /* Global Module Fragment. */
2256
2257 MP_PURVIEW_IMPORTS, /* Imports of a module. */
2258 MP_PURVIEW, /* Purview of a named module. */
2259
2260 MP_PRIVATE_IMPORTS, /* Imports of a Private Module Fragment. */
2261 MP_PRIVATE, /* Private Module Fragment. */
2262};
2263
2264static module_parse cp_parser_module_declaration
2265 (cp_parser *parser, module_parse, bool exporting);
2266static void cp_parser_import_declaration
2267 (cp_parser *parser, module_parse, bool exporting);
2268
2269/* Declarations [gram.dcl.dcl] */
2270
2271static void cp_parser_declaration_seq_opt
2272 (cp_parser *);
2273static void cp_parser_declaration
2274 (cp_parser *, tree);
2275static void cp_parser_toplevel_declaration
2276 (cp_parser *);
2277static void cp_parser_block_declaration
2278 (cp_parser *, bool);
2279static void cp_parser_simple_declaration
2280 (cp_parser *, bool, tree *);
2281static void cp_parser_decl_specifier_seq
2282 (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *, int *);
2283static tree cp_parser_storage_class_specifier_opt
2284 (cp_parser *);
2285static tree cp_parser_function_specifier_opt
2286 (cp_parser *, cp_decl_specifier_seq *);
2287static tree cp_parser_type_specifier
2288 (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *, bool,
2289 int *, bool *);
2290static tree cp_parser_simple_type_specifier
2291 (cp_parser *, cp_decl_specifier_seq *, cp_parser_flags);
2292static tree cp_parser_placeholder_type_specifier
2293 (cp_parser *, location_t, tree, bool);
2294static tree cp_parser_type_name
2295 (cp_parser *, bool);
2296static tree cp_parser_nonclass_name
2297 (cp_parser* parser);
2298static tree cp_parser_elaborated_type_specifier
2299 (cp_parser *, bool, bool);
2300static tree cp_parser_enum_specifier
2301 (cp_parser *);
2302static void cp_parser_enumerator_list
2303 (cp_parser *, tree);
2304static void cp_parser_enumerator_definition
2305 (cp_parser *, tree);
2306static tree cp_parser_namespace_name
2307 (cp_parser *);
2308static void cp_parser_namespace_definition
2309 (cp_parser *);
2310static void cp_parser_namespace_body
2311 (cp_parser *);
2312static tree cp_parser_qualified_namespace_specifier
2313 (cp_parser *);
2314static void cp_parser_namespace_alias_definition
2315 (cp_parser *);
2316static bool cp_parser_using_declaration
2317 (cp_parser *, bool);
2318static void cp_parser_using_directive
2319 (cp_parser *);
2320static void cp_parser_using_enum
2321 (cp_parser *);
2322static tree cp_parser_alias_declaration
2323 (cp_parser *);
2324static void cp_parser_asm_definition
2325 (cp_parser *);
2326static void cp_parser_linkage_specification
2327 (cp_parser *, tree);
2328static void cp_parser_static_assert
2329 (cp_parser *, bool);
2330static tree cp_parser_decltype
2331 (cp_parser *);
2332static tree cp_parser_decomposition_declaration
2333 (cp_parser *, cp_decl_specifier_seq *, tree *, location_t *);
2334
2335/* Declarators [gram.dcl.decl] */
2336
2337static tree cp_parser_init_declarator
2338 (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *,
2339 vec<deferred_access_check, va_gc> *, bool, bool, int, bool *, tree *,
2340 location_t *, tree *);
2341static cp_declarator *cp_parser_declarator
2342 (cp_parser *, cp_parser_declarator_kind, cp_parser_flags, int *, bool *,
2343 bool, bool, bool);
2344static cp_declarator *cp_parser_direct_declarator
2345 (cp_parser *, cp_parser_declarator_kind, cp_parser_flags, int *, bool, bool,
2346 bool);
2347static enum tree_code cp_parser_ptr_operator
2348 (cp_parser *, tree *, cp_cv_quals *, tree *);
2349static cp_cv_quals cp_parser_cv_qualifier_seq_opt
2350 (cp_parser *);
2351static cp_virt_specifiers cp_parser_virt_specifier_seq_opt
2352 (cp_parser *);
2353static cp_ref_qualifier cp_parser_ref_qualifier_opt
2354 (cp_parser *);
2355static tree cp_parser_tx_qualifier_opt
2356 (cp_parser *);
2357static tree cp_parser_late_return_type_opt
2358 (cp_parser *, cp_declarator *, tree &);
2359static tree cp_parser_declarator_id
2360 (cp_parser *, bool);
2361static tree cp_parser_type_id
2362 (cp_parser *, cp_parser_flags = CP_PARSER_FLAGS_NONE, location_t * = NULL__null);
2363static tree cp_parser_template_type_arg
2364 (cp_parser *);
2365static tree cp_parser_trailing_type_id (cp_parser *);
2366static tree cp_parser_type_id_1
2367 (cp_parser *, cp_parser_flags, bool, bool, location_t *);
2368static void cp_parser_type_specifier_seq
2369 (cp_parser *, cp_parser_flags, bool, bool, cp_decl_specifier_seq *);
2370static tree cp_parser_parameter_declaration_clause
2371 (cp_parser *, cp_parser_flags);
2372static tree cp_parser_parameter_declaration_list
2373 (cp_parser *, cp_parser_flags);
2374static cp_parameter_declarator *cp_parser_parameter_declaration
2375 (cp_parser *, cp_parser_flags, bool, bool *);
2376static tree cp_parser_default_argument
2377 (cp_parser *, bool);
2378static void cp_parser_function_body
2379 (cp_parser *, bool);
2380static tree cp_parser_initializer
2381 (cp_parser *, bool *, bool *, bool = false);
2382static cp_expr cp_parser_initializer_clause
2383 (cp_parser *, bool *);
2384static cp_expr cp_parser_braced_list
2385 (cp_parser*, bool*);
2386static vec<constructor_elt, va_gc> *cp_parser_initializer_list
2387 (cp_parser *, bool *, bool *);
2388
2389static void cp_parser_ctor_initializer_opt_and_function_body
2390 (cp_parser *, bool);
2391
2392static tree cp_parser_late_parsing_omp_declare_simd
2393 (cp_parser *, tree);
2394
2395static tree cp_parser_late_parsing_oacc_routine
2396 (cp_parser *, tree);
2397
2398static tree synthesize_implicit_template_parm
2399 (cp_parser *, tree);
2400static tree finish_fully_implicit_template
2401 (cp_parser *, tree);
2402static void abort_fully_implicit_template
2403 (cp_parser *);
2404
2405/* Classes [gram.class] */
2406
2407static tree cp_parser_class_name
2408 (cp_parser *, bool, bool, enum tag_types, bool, bool, bool, bool = false);
2409static tree cp_parser_class_specifier
2410 (cp_parser *);
2411static tree cp_parser_class_head
2412 (cp_parser *, bool *);
2413static enum tag_types cp_parser_class_key
2414 (cp_parser *);
2415static void cp_parser_type_parameter_key
2416 (cp_parser* parser);
2417static void cp_parser_member_specification_opt
2418 (cp_parser *);
2419static void cp_parser_member_declaration
2420 (cp_parser *);
2421static tree cp_parser_pure_specifier
2422 (cp_parser *);
2423static tree cp_parser_constant_initializer
2424 (cp_parser *);
2425
2426/* Derived classes [gram.class.derived] */
2427
2428static tree cp_parser_base_clause
2429 (cp_parser *);
2430static tree cp_parser_base_specifier
2431 (cp_parser *);
2432
2433/* Special member functions [gram.special] */
2434
2435static tree cp_parser_conversion_function_id
2436 (cp_parser *);
2437static tree cp_parser_conversion_type_id
2438 (cp_parser *);
2439static cp_declarator *cp_parser_conversion_declarator_opt
2440 (cp_parser *);
2441static void cp_parser_ctor_initializer_opt
2442 (cp_parser *);
2443static void cp_parser_mem_initializer_list
2444 (cp_parser *);
2445static tree cp_parser_mem_initializer
2446 (cp_parser *);
2447static tree cp_parser_mem_initializer_id
2448 (cp_parser *);
2449
2450/* Overloading [gram.over] */
2451
2452static cp_expr cp_parser_operator_function_id
2453 (cp_parser *);
2454static cp_expr cp_parser_operator
2455 (cp_parser *, location_t);
2456
2457/* Templates [gram.temp] */
2458
2459static void cp_parser_template_declaration
2460 (cp_parser *, bool);
2461static tree cp_parser_template_parameter_list
2462 (cp_parser *);
2463static tree cp_parser_template_parameter
2464 (cp_parser *, bool *, bool *);
2465static tree cp_parser_type_parameter
2466 (cp_parser *, bool *);
2467static tree cp_parser_template_id
2468 (cp_parser *, bool, bool, enum tag_types, bool);
2469static tree cp_parser_template_id_expr
2470 (cp_parser *, bool, bool, bool);
2471static tree cp_parser_template_name
2472 (cp_parser *, bool, bool, bool, enum tag_types, bool *);
2473static tree cp_parser_template_argument_list
2474 (cp_parser *);
2475static tree cp_parser_template_argument
2476 (cp_parser *);
2477static void cp_parser_explicit_instantiation
2478 (cp_parser *);
2479static void cp_parser_explicit_specialization
2480 (cp_parser *);
2481
2482/* Exception handling [gram.except] */
2483
2484static tree cp_parser_try_block
2485 (cp_parser *);
2486static void cp_parser_function_try_block
2487 (cp_parser *);
2488static void cp_parser_handler_seq
2489 (cp_parser *);
2490static void cp_parser_handler
2491 (cp_parser *);
2492static tree cp_parser_exception_declaration
2493 (cp_parser *);
2494static tree cp_parser_throw_expression
2495 (cp_parser *);
2496static tree cp_parser_exception_specification_opt
2497 (cp_parser *, cp_parser_flags);
2498static tree cp_parser_type_id_list
2499 (cp_parser *);
2500static tree cp_parser_noexcept_specification_opt
2501 (cp_parser *, cp_parser_flags, bool, bool *, bool);
2502
2503/* GNU Extensions */
2504
2505static tree cp_parser_asm_specification_opt
2506 (cp_parser *);
2507static tree cp_parser_asm_operand_list
2508 (cp_parser *);
2509static tree cp_parser_asm_clobber_list
2510 (cp_parser *);
2511static tree cp_parser_asm_label_list
2512 (cp_parser *);
2513static bool cp_next_tokens_can_be_attribute_p
2514 (cp_parser *);
2515static bool cp_next_tokens_can_be_gnu_attribute_p
2516 (cp_parser *);
2517static bool cp_next_tokens_can_be_std_attribute_p
2518 (cp_parser *);
2519static bool cp_nth_tokens_can_be_std_attribute_p
2520 (cp_parser *, size_t);
2521static bool cp_nth_tokens_can_be_gnu_attribute_p
2522 (cp_parser *, size_t);
2523static bool cp_nth_tokens_can_be_attribute_p
2524 (cp_parser *, size_t);
2525static tree cp_parser_attributes_opt
2526 (cp_parser *);
2527static tree cp_parser_gnu_attributes_opt
2528 (cp_parser *);
2529static tree cp_parser_gnu_attribute_list
2530 (cp_parser *, bool = false);
2531static tree cp_parser_std_attribute
2532 (cp_parser *, tree);
2533static tree cp_parser_std_attribute_spec
2534 (cp_parser *);
2535static tree cp_parser_std_attribute_spec_seq
2536 (cp_parser *);
2537static size_t cp_parser_skip_std_attribute_spec_seq
2538 (cp_parser *, size_t);
2539static size_t cp_parser_skip_attributes_opt
2540 (cp_parser *, size_t);
2541static bool cp_parser_extension_opt
2542 (cp_parser *, int *);
2543static void cp_parser_label_declaration
2544 (cp_parser *);
2545
2546/* Concept Extensions */
2547
2548static tree cp_parser_concept_definition
2549 (cp_parser *);
2550static tree cp_parser_constraint_expression
2551 (cp_parser *);
2552static tree cp_parser_requires_clause_opt
2553 (cp_parser *, bool);
2554static tree cp_parser_requires_expression
2555 (cp_parser *);
2556static tree cp_parser_requirement_parameter_list
2557 (cp_parser *);
2558static tree cp_parser_requirement_body
2559 (cp_parser *);
2560static tree cp_parser_requirement_seq
2561 (cp_parser *);
2562static tree cp_parser_requirement
2563 (cp_parser *);
2564static tree cp_parser_simple_requirement
2565 (cp_parser *);
2566static tree cp_parser_compound_requirement
2567 (cp_parser *);
2568static tree cp_parser_type_requirement
2569 (cp_parser *);
2570static tree cp_parser_nested_requirement
2571 (cp_parser *);
2572
2573/* Transactional Memory Extensions */
2574
2575static tree cp_parser_transaction
2576 (cp_parser *, cp_token *);
2577static tree cp_parser_transaction_expression
2578 (cp_parser *, enum rid);
2579static void cp_parser_function_transaction
2580 (cp_parser *, enum rid);
2581static tree cp_parser_transaction_cancel
2582 (cp_parser *);
2583
2584/* Coroutine extensions. */
2585
2586static tree cp_parser_yield_expression
2587 (cp_parser *);
2588
2589
2590enum pragma_context {
2591 pragma_external,
2592 pragma_member,
2593 pragma_objc_icode,
2594 pragma_stmt,
2595 pragma_compound
2596};
2597static bool cp_parser_pragma
2598 (cp_parser *, enum pragma_context, bool *);
2599
2600/* Objective-C++ Productions */
2601
2602static tree cp_parser_objc_message_receiver
2603 (cp_parser *);
2604static tree cp_parser_objc_message_args
2605 (cp_parser *);
2606static tree cp_parser_objc_message_expression
2607 (cp_parser *);
2608static cp_expr cp_parser_objc_encode_expression
2609 (cp_parser *);
2610static tree cp_parser_objc_defs_expression
2611 (cp_parser *);
2612static tree cp_parser_objc_protocol_expression
2613 (cp_parser *);
2614static tree cp_parser_objc_selector_expression
2615 (cp_parser *);
2616static cp_expr cp_parser_objc_expression
2617 (cp_parser *);
2618static bool cp_parser_objc_selector_p
2619 (enum cpp_ttype);
2620static tree cp_parser_objc_selector
2621 (cp_parser *);
2622static tree cp_parser_objc_protocol_refs_opt
2623 (cp_parser *);
2624static void cp_parser_objc_declaration
2625 (cp_parser *, tree);
2626static tree cp_parser_objc_statement
2627 (cp_parser *);
2628static bool cp_parser_objc_valid_prefix_attributes
2629 (cp_parser *, tree *);
2630static void cp_parser_objc_at_property_declaration
2631 (cp_parser *) ;
2632static void cp_parser_objc_at_synthesize_declaration
2633 (cp_parser *) ;
2634static void cp_parser_objc_at_dynamic_declaration
2635 (cp_parser *) ;
2636static tree cp_parser_objc_struct_declaration
2637 (cp_parser *) ;
2638
2639/* Utility Routines */
2640
2641static cp_expr cp_parser_lookup_name
2642 (cp_parser *, tree, enum tag_types, bool, bool, bool, tree *, location_t);
2643static tree cp_parser_lookup_name_simple
2644 (cp_parser *, tree, location_t);
2645static tree cp_parser_maybe_treat_template_as_class
2646 (tree, bool);
2647static bool cp_parser_check_declarator_template_parameters
2648 (cp_parser *, cp_declarator *, location_t);
2649static bool cp_parser_check_template_parameters
2650 (cp_parser *, unsigned, bool, location_t, cp_declarator *);
2651static cp_expr cp_parser_simple_cast_expression
2652 (cp_parser *);
2653static tree cp_parser_global_scope_opt
2654 (cp_parser *, bool);
2655static bool cp_parser_constructor_declarator_p
2656 (cp_parser *, cp_parser_flags, bool);
2657static tree cp_parser_function_definition_from_specifiers_and_declarator
2658 (cp_parser *, cp_decl_specifier_seq *, tree, const cp_declarator *);
2659static tree cp_parser_function_definition_after_declarator
2660 (cp_parser *, bool);
2661static bool cp_parser_template_declaration_after_export
2662 (cp_parser *, bool);
2663static void cp_parser_perform_template_parameter_access_checks
2664 (vec<deferred_access_check, va_gc> *);
2665static tree cp_parser_single_declaration
2666 (cp_parser *, vec<deferred_access_check, va_gc> *, bool, bool, bool *);
2667static cp_expr cp_parser_functional_cast
2668 (cp_parser *, tree);
2669static tree cp_parser_save_member_function_body
2670 (cp_parser *, cp_decl_specifier_seq *, cp_declarator *, tree);
2671static tree cp_parser_save_nsdmi
2672 (cp_parser *);
2673static tree cp_parser_enclosed_template_argument_list
2674 (cp_parser *);
2675static void cp_parser_save_default_args
2676 (cp_parser *, tree);
2677static void cp_parser_late_parsing_for_member
2678 (cp_parser *, tree);
2679static tree cp_parser_late_parse_one_default_arg
2680 (cp_parser *, tree, tree, tree);
2681static void cp_parser_late_parsing_nsdmi
2682 (cp_parser *, tree);
2683static void cp_parser_late_parsing_default_args
2684 (cp_parser *, tree);
2685static tree cp_parser_sizeof_operand
2686 (cp_parser *, enum rid);
2687static cp_expr cp_parser_trait_expr
2688 (cp_parser *, enum rid);
2689static bool cp_parser_declares_only_class_p
2690 (cp_parser *);
2691static void cp_parser_set_storage_class
2692 (cp_parser *, cp_decl_specifier_seq *, enum rid, cp_token *);
2693static void cp_parser_set_decl_spec_type
2694 (cp_decl_specifier_seq *, tree, cp_token *, bool);
2695static void set_and_check_decl_spec_loc
2696 (cp_decl_specifier_seq *decl_specs,
2697 cp_decl_spec ds, cp_token *);
2698static bool cp_parser_friend_p
2699 (const cp_decl_specifier_seq *);
2700static void cp_parser_required_error
2701 (cp_parser *, required_token, bool, location_t);
2702static cp_token *cp_parser_require
2703 (cp_parser *, enum cpp_ttype, required_token, location_t = UNKNOWN_LOCATION((location_t) 0));
2704static cp_token *cp_parser_require_keyword
2705 (cp_parser *, enum rid, required_token);
2706static bool cp_parser_token_starts_function_definition_p
2707 (cp_token *);
2708static bool cp_parser_next_token_starts_class_definition_p
2709 (cp_parser *);
2710static bool cp_parser_next_token_ends_template_argument_p
2711 (cp_parser *);
2712static bool cp_parser_nth_token_starts_template_argument_list_p
2713 (cp_parser *, size_t);
2714static enum tag_types cp_parser_token_is_class_key
2715 (cp_token *);
2716static enum tag_types cp_parser_token_is_type_parameter_key
2717 (cp_token *);
2718static void cp_parser_maybe_warn_enum_key (cp_parser *, location_t, tree, rid);
2719static void cp_parser_check_class_key
2720(cp_parser *, location_t, enum tag_types, tree type, bool, bool);
2721static void cp_parser_check_access_in_redeclaration
2722 (tree type, location_t location);
2723static bool cp_parser_optional_template_keyword
2724 (cp_parser *);
2725static void cp_parser_pre_parsed_nested_name_specifier
2726 (cp_parser *);
2727static bool cp_parser_cache_group
2728 (cp_parser *, enum cpp_ttype, unsigned);
2729static tree cp_parser_cache_defarg
2730 (cp_parser *parser, bool nsdmi);
2731static void cp_parser_parse_tentatively
2732 (cp_parser *);
2733static void cp_parser_commit_to_tentative_parse
2734 (cp_parser *);
2735static void cp_parser_commit_to_topmost_tentative_parse
2736 (cp_parser *);
2737static void cp_parser_abort_tentative_parse
2738 (cp_parser *);
2739static bool cp_parser_parse_definitely
2740 (cp_parser *);
2741static inline bool cp_parser_parsing_tentatively
2742 (cp_parser *);
2743static bool cp_parser_uncommitted_to_tentative_parse_p
2744 (cp_parser *);
2745static void cp_parser_error
2746 (cp_parser *, const char *);
2747static void cp_parser_name_lookup_error
2748 (cp_parser *, tree, tree, name_lookup_error, location_t);
2749static bool cp_parser_simulate_error
2750 (cp_parser *);
2751static bool cp_parser_check_type_definition
2752 (cp_parser *);
2753static void cp_parser_check_for_definition_in_return_type
2754 (cp_declarator *, tree, location_t type_location);
2755static void cp_parser_check_for_invalid_template_id
2756 (cp_parser *, tree, enum tag_types, location_t location);
2757static bool cp_parser_non_integral_constant_expression
2758 (cp_parser *, non_integral_constant);
2759static void cp_parser_diagnose_invalid_type_name
2760 (cp_parser *, tree, location_t);
2761static bool cp_parser_parse_and_diagnose_invalid_type_name
2762 (cp_parser *);
2763static int cp_parser_skip_to_closing_parenthesis
2764 (cp_parser *, bool, bool, bool);
2765static void cp_parser_skip_to_end_of_statement
2766 (cp_parser *);
2767static void cp_parser_consume_semicolon_at_end_of_statement
2768 (cp_parser *);
2769static void cp_parser_skip_to_end_of_block_or_statement
2770 (cp_parser *);
2771static bool cp_parser_skip_to_closing_brace
2772 (cp_parser *);
2773static void cp_parser_skip_to_end_of_template_parameter_list
2774 (cp_parser *);
2775static void cp_parser_skip_to_pragma_eol
2776 (cp_parser*, cp_token *);
2777static bool cp_parser_error_occurred
2778 (cp_parser *);
2779static bool cp_parser_allow_gnu_extensions_p
2780 (cp_parser *);
2781static bool cp_parser_is_pure_string_literal
2782 (cp_token *);
2783static bool cp_parser_is_string_literal
2784 (cp_token *);
2785static bool cp_parser_is_keyword
2786 (cp_token *, enum rid);
2787static tree cp_parser_make_typename_type
2788 (cp_parser *, tree, location_t location);
2789static cp_declarator * cp_parser_make_indirect_declarator
2790 (enum tree_code, tree, cp_cv_quals, cp_declarator *, tree);
2791static bool cp_parser_compound_literal_p
2792 (cp_parser *);
2793static bool cp_parser_array_designator_p
2794 (cp_parser *);
2795static bool cp_parser_init_statement_p
2796 (cp_parser *);
2797static bool cp_parser_skip_to_closing_square_bracket
2798 (cp_parser *);
2799static size_t cp_parser_skip_balanced_tokens (cp_parser *, size_t);
2800
2801// -------------------------------------------------------------------------- //
2802// Unevaluated Operand Guard
2803//
2804// Implementation of an RAII helper for unevaluated operand parsing.
2805cp_unevaluated::cp_unevaluated ()
2806{
2807 ++cp_unevaluated_operand;
2808 ++c_inhibit_evaluation_warnings;
2809}
2810
2811cp_unevaluated::~cp_unevaluated ()
2812{
2813 --c_inhibit_evaluation_warnings;
2814 --cp_unevaluated_operand;
2815}
2816
2817// -------------------------------------------------------------------------- //
2818// Tentative Parsing
2819
2820/* Returns nonzero if we are parsing tentatively. */
2821
2822static inline bool
2823cp_parser_parsing_tentatively (cp_parser* parser)
2824{
2825 return parser->context->next != NULL__null;
2826}
2827
2828/* Returns nonzero if TOKEN is a string literal. */
2829
2830static bool
2831cp_parser_is_pure_string_literal (cp_token* token)
2832{
2833 return (token->type == CPP_STRING ||
2834 token->type == CPP_STRING16 ||
2835 token->type == CPP_STRING32 ||
2836 token->type == CPP_WSTRING ||
2837 token->type == CPP_UTF8STRING);
2838}
2839
2840/* Returns nonzero if TOKEN is a string literal
2841 of a user-defined string literal. */
2842
2843static bool
2844cp_parser_is_string_literal (cp_token* token)
2845{
2846 return (cp_parser_is_pure_string_literal (token) ||
2847 token->type == CPP_STRING_USERDEF ||
2848 token->type == CPP_STRING16_USERDEF ||
2849 token->type == CPP_STRING32_USERDEF ||
2850 token->type == CPP_WSTRING_USERDEF ||
2851 token->type == CPP_UTF8STRING_USERDEF);
2852}
2853
2854/* Returns nonzero if TOKEN is the indicated KEYWORD. */
2855
2856static bool
2857cp_parser_is_keyword (cp_token* token, enum rid keyword)
2858{
2859 return token->keyword == keyword;
2860}
2861
2862/* Return TOKEN's pragma_kind if it is CPP_PRAGMA, otherwise
2863 PRAGMA_NONE. */
2864
2865static enum pragma_kind
2866cp_parser_pragma_kind (cp_token *token)
2867{
2868 if (token->type != CPP_PRAGMA)
2869 return PRAGMA_NONE;
2870 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
2871 return (enum pragma_kind) TREE_INT_CST_LOW (token->u.value)((unsigned long) (*tree_int_cst_elt_check ((token->u.value
), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 2871, __FUNCTION__)))
;
2872}
2873
2874/* Helper function for cp_parser_error.
2875 Having peeked a token of kind TOK1_KIND that might signify
2876 a conflict marker, peek successor tokens to determine
2877 if we actually do have a conflict marker.
2878 Specifically, we consider a run of 7 '<', '=' or '>' characters
2879 at the start of a line as a conflict marker.
2880 These come through the lexer as three pairs and a single,
2881 e.g. three CPP_LSHIFT tokens ("<<") and a CPP_LESS token ('<').
2882 If it returns true, *OUT_LOC is written to with the location/range
2883 of the marker. */
2884
2885static bool
2886cp_lexer_peek_conflict_marker (cp_lexer *lexer, enum cpp_ttype tok1_kind,
2887 location_t *out_loc)
2888{
2889 cp_token *token2 = cp_lexer_peek_nth_token (lexer, 2);
2890 if (token2->type != tok1_kind)
2891 return false;
2892 cp_token *token3 = cp_lexer_peek_nth_token (lexer, 3);
2893 if (token3->type != tok1_kind)
2894 return false;
2895 cp_token *token4 = cp_lexer_peek_nth_token (lexer, 4);
2896 if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind))
2897 return false;
2898
2899 /* It must be at the start of the line. */
2900 location_t start_loc = cp_lexer_peek_token (lexer)->location;
2901 if (LOCATION_COLUMN (start_loc)((expand_location (start_loc)).column) != 1)
2902 return false;
2903
2904 /* We have a conflict marker. Construct a location of the form:
2905 <<<<<<<
2906 ^~~~~~~
2907 with start == caret, finishing at the end of the marker. */
2908 location_t finish_loc = get_finish (token4->location);
2909 *out_loc = make_location (start_loc, start_loc, finish_loc);
2910
2911 return true;
2912}
2913
2914/* Get a description of the matching symbol to TOKEN_DESC e.g. "(" for
2915 RT_CLOSE_PAREN. */
2916
2917static const char *
2918get_matching_symbol (required_token token_desc)
2919{
2920 switch (token_desc)
2921 {
2922 default:
2923 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 2923, __FUNCTION__))
;
2924 return "";
2925 case RT_CLOSE_BRACE:
2926 return "{";
2927 case RT_CLOSE_PAREN:
2928 return "(";
2929 }
2930}
2931
2932/* Attempt to convert TOKEN_DESC from a required_token to an
2933 enum cpp_ttype, returning CPP_EOF if there is no good conversion. */
2934
2935static enum cpp_ttype
2936get_required_cpp_ttype (required_token token_desc)
2937{
2938 switch (token_desc)
2939 {
2940 case RT_SEMICOLON:
2941 return CPP_SEMICOLON;
2942 case RT_OPEN_PAREN:
2943 return CPP_OPEN_PAREN;
2944 case RT_CLOSE_BRACE:
2945 return CPP_CLOSE_BRACE;
2946 case RT_OPEN_BRACE:
2947 return CPP_OPEN_BRACE;
2948 case RT_CLOSE_SQUARE:
2949 return CPP_CLOSE_SQUARE;
2950 case RT_OPEN_SQUARE:
2951 return CPP_OPEN_SQUARE;
2952 case RT_COMMA:
2953 return CPP_COMMA;
2954 case RT_COLON:
2955 return CPP_COLON;
2956 case RT_CLOSE_PAREN:
2957 return CPP_CLOSE_PAREN;
2958
2959 default:
2960 /* Use CPP_EOF as a "no completions possible" code. */
2961 return CPP_EOF;
2962 }
2963}
2964
2965
2966/* Subroutine of cp_parser_error and cp_parser_required_error.
2967
2968 Issue a diagnostic of the form
2969 FILE:LINE: MESSAGE before TOKEN
2970 where TOKEN is the next token in the input stream. MESSAGE
2971 (specified by the caller) is usually of the form "expected
2972 OTHER-TOKEN".
2973
2974 This bypasses the check for tentative passing, and potentially
2975 adds material needed by cp_parser_required_error.
2976
2977 If MISSING_TOKEN_DESC is not RT_NONE, then potentially add fix-it hints
2978 suggesting insertion of the missing token.
2979
2980 Additionally, if MATCHING_LOCATION is not UNKNOWN_LOCATION, then we
2981 have an unmatched symbol at MATCHING_LOCATION; highlight this secondary
2982 location. */
2983
2984static void
2985cp_parser_error_1 (cp_parser* parser, const char* gmsgid,
2986 required_token missing_token_desc,
2987 location_t matching_location)
2988{
2989 cp_token *token = cp_lexer_peek_token (parser->lexer);
2990 /* This diagnostic makes more sense if it is tagged to the line
2991 of the token we just peeked at. */
2992 cp_lexer_set_source_position_from_token (token);
2993
2994 if (token->type == CPP_PRAGMA)
2995 {
2996 error_at (token->location,
2997 "%<#pragma%> is not allowed here");
2998 cp_parser_skip_to_pragma_eol (parser, token);
2999 return;
3000 }
3001
3002 /* If this is actually a conflict marker, report it as such. */
3003 if (token->type == CPP_LSHIFT
3004 || token->type == CPP_RSHIFT
3005 || token->type == CPP_EQ_EQ)
3006 {
3007 location_t loc;
3008 if (cp_lexer_peek_conflict_marker (parser->lexer, token->type, &loc))
3009 {
3010 error_at (loc, "version control conflict marker in file");
3011 expanded_location token_exploc = expand_location (token->location);
3012 /* Consume tokens until the end of the source line. */
3013 for (;;)
3014 {
3015 cp_lexer_consume_token (parser->lexer);
3016 cp_token *next = cp_lexer_peek_token (parser->lexer);
3017 if (next->type == CPP_EOF)
3018 break;
3019 if (next->location == UNKNOWN_LOCATION((location_t) 0)
3020 || loc == UNKNOWN_LOCATION((location_t) 0))
3021 break;
3022
3023 expanded_location next_exploc = expand_location (next->location);
3024 if (next_exploc.file != token_exploc.file)
3025 break;
3026 if (next_exploc.line != token_exploc.line)
3027 break;
3028 }
3029 return;
3030 }
3031 }
3032
3033 auto_diagnostic_group d;
3034 gcc_rich_location richloc (input_location);
3035
3036 bool added_matching_location = false;
3037
3038 if (missing_token_desc != RT_NONE)
3039 if (cp_token *prev_token = cp_lexer_safe_previous_token (parser->lexer))
3040 {
3041 /* Potentially supply a fix-it hint, suggesting to add the
3042 missing token immediately after the *previous* token.
3043 This may move the primary location within richloc. */
3044 enum cpp_ttype ttype = get_required_cpp_ttype (missing_token_desc);
3045 location_t prev_token_loc = prev_token->location;
3046 maybe_suggest_missing_token_insertion (&richloc, ttype,
3047 prev_token_loc);
3048
3049 /* If matching_location != UNKNOWN_LOCATION, highlight it.
3050 Attempt to consolidate diagnostics by printing it as a
3051 secondary range within the main diagnostic. */
3052 if (matching_location != UNKNOWN_LOCATION((location_t) 0))
3053 added_matching_location
3054 = richloc.add_location_if_nearby (matching_location);
3055 }
3056
3057 /* If we were parsing a string-literal and there is an unknown name
3058 token right after, then check to see if that could also have been
3059 a literal string by checking the name against a list of known
3060 standard string literal constants defined in header files. If
3061 there is one, then add that as an hint to the error message. */
3062 name_hint h;
3063 if (token->type == CPP_NAME)
3064 if (cp_token *prev_token = cp_lexer_safe_previous_token (parser->lexer))
3065 if (cp_parser_is_string_literal (prev_token))
3066 {
3067 tree name = token->u.value;
3068 const char *token_name = IDENTIFIER_POINTER (name)((const char *) (tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3068, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
3069 const char *header_hint
3070 = get_cp_stdlib_header_for_string_macro_name (token_name);
3071 if (header_hint != NULL__null)
3072 h = name_hint (NULL__null, new suggest_missing_header (token->location,
3073 token_name,
3074 header_hint));
3075 }
3076
3077 /* Actually emit the error. */
3078 c_parse_error (gmsgid,
3079 /* Because c_parser_error does not understand
3080 CPP_KEYWORD, keywords are treated like
3081 identifiers. */
3082 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
3083 token->u.value, token->flags, &richloc);
3084
3085 if (missing_token_desc != RT_NONE)
3086 {
3087 /* If we weren't able to consolidate matching_location, then
3088 print it as a secondary diagnostic. */
3089 if (matching_location != UNKNOWN_LOCATION((location_t) 0)
3090 && !added_matching_location)
3091 inform (matching_location, "to match this %qs",
3092 get_matching_symbol (missing_token_desc));
3093 }
3094}
3095
3096/* If not parsing tentatively, issue a diagnostic of the form
3097 FILE:LINE: MESSAGE before TOKEN
3098 where TOKEN is the next token in the input stream. MESSAGE
3099 (specified by the caller) is usually of the form "expected
3100 OTHER-TOKEN". */
3101
3102static void
3103cp_parser_error (cp_parser* parser, const char* gmsgid)
3104{
3105 if (!cp_parser_simulate_error (parser))
3106 cp_parser_error_1 (parser, gmsgid, RT_NONE, UNKNOWN_LOCATION((location_t) 0));
3107}
3108
3109/* Issue an error about name-lookup failing. NAME is the
3110 IDENTIFIER_NODE DECL is the result of
3111 the lookup (as returned from cp_parser_lookup_name). DESIRED is
3112 the thing that we hoped to find. */
3113
3114static void
3115cp_parser_name_lookup_error (cp_parser* parser,
3116 tree name,
3117 tree decl,
3118 name_lookup_error desired,
3119 location_t location)
3120{
3121 /* If name lookup completely failed, tell the user that NAME was not
3122 declared. */
3123 if (decl == error_mark_nodeglobal_trees[TI_ERROR_MARK])
3124 {
3125 if (parser->scope && parser->scope != global_namespacecp_global_trees[CPTI_GLOBAL])
3126 error_at (location, "%<%E::%E%> has not been declared",
3127 parser->scope, name);
3128 else if (parser->scope == global_namespacecp_global_trees[CPTI_GLOBAL])
3129 error_at (location, "%<::%E%> has not been declared", name);
3130 else if (parser->object_scope
3131 && !CLASS_TYPE_P (parser->object_scope)(((((enum tree_code) (parser->object_scope)->base.code)
) == RECORD_TYPE || (((enum tree_code) (parser->object_scope
)->base.code)) == UNION_TYPE) && ((tree_class_check
((parser->object_scope), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3131, __FUNCTION__))->type_common.lang_flag_5))
)
3132 error_at (location, "request for member %qE in non-class type %qT",
3133 name, parser->object_scope);
3134 else if (parser->object_scope)
3135 error_at (location, "%<%T::%E%> has not been declared",
3136 parser->object_scope, name);
3137 else
3138 error_at (location, "%qE has not been declared", name);
3139 }
3140 else if (parser->scope && parser->scope != global_namespacecp_global_trees[CPTI_GLOBAL])
3141 {
3142 switch (desired)
3143 {
3144 case NLE_TYPE:
3145 error_at (location, "%<%E::%E%> is not a type",
3146 parser->scope, name);
3147 break;
3148 case NLE_CXX98:
3149 error_at (location, "%<%E::%E%> is not a class or namespace",
3150 parser->scope, name);
3151 break;
3152 case NLE_NOT_CXX98:
3153 error_at (location,
3154 "%<%E::%E%> is not a class, namespace, or enumeration",
3155 parser->scope, name);
3156 break;
3157 default:
3158 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3158, __FUNCTION__))
;
3159
3160 }
3161 }
3162 else if (parser->scope == global_namespacecp_global_trees[CPTI_GLOBAL])
3163 {
3164 switch (desired)
3165 {
3166 case NLE_TYPE:
3167 error_at (location, "%<::%E%> is not a type", name);
3168 break;
3169 case NLE_CXX98:
3170 error_at (location, "%<::%E%> is not a class or namespace", name);
3171 break;
3172 case NLE_NOT_CXX98:
3173 error_at (location,
3174 "%<::%E%> is not a class, namespace, or enumeration",
3175 name);
3176 break;
3177 default:
3178 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3178, __FUNCTION__))
;
3179 }
3180 }
3181 else
3182 {
3183 switch (desired)
3184 {
3185 case NLE_TYPE:
3186 error_at (location, "%qE is not a type", name);
3187 break;
3188 case NLE_CXX98:
3189 error_at (location, "%qE is not a class or namespace", name);
3190 break;
3191 case NLE_NOT_CXX98:
3192 error_at (location,
3193 "%qE is not a class, namespace, or enumeration", name);
3194 break;
3195 default:
3196 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3196, __FUNCTION__))
;
3197 }
3198 }
3199}
3200
3201/* If we are parsing tentatively, remember that an error has occurred
3202 during this tentative parse. Returns true if the error was
3203 simulated; false if a message should be issued by the caller. */
3204
3205static bool
3206cp_parser_simulate_error (cp_parser* parser)
3207{
3208 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
3209 {
3210 parser->context->status = CP_PARSER_STATUS_KIND_ERROR;
3211 return true;
3212 }
3213 return false;
3214}
3215
3216/* This function is called when a type is defined. If type
3217 definitions are forbidden at this point, an error message is
3218 issued. */
3219
3220static bool
3221cp_parser_check_type_definition (cp_parser* parser)
3222{
3223 /* If types are forbidden here, issue a message. */
3224 if (parser->type_definition_forbidden_message)
3225 {
3226 /* Don't use `%s' to print the string, because quotations (`%<', `%>')
3227 or %qs in the message need to be interpreted. */
3228 error (parser->type_definition_forbidden_message,
3229 parser->type_definition_forbidden_message_arg);
3230 return false;
3231 }
3232 return true;
3233}
3234
3235/* This function is called when the DECLARATOR is processed. The TYPE
3236 was a type defined in the decl-specifiers. If it is invalid to
3237 define a type in the decl-specifiers for DECLARATOR, an error is
3238 issued. TYPE_LOCATION is the location of TYPE and is used
3239 for error reporting. */
3240
3241static void
3242cp_parser_check_for_definition_in_return_type (cp_declarator *declarator,
3243 tree type, location_t type_location)
3244{
3245 /* [dcl.fct] forbids type definitions in return types.
3246 Unfortunately, it's not easy to know whether or not we are
3247 processing a return type until after the fact. */
3248 while (declarator
3249 && (declarator->kind == cdk_pointer
3250 || declarator->kind == cdk_reference
3251 || declarator->kind == cdk_ptrmem))
3252 declarator = declarator->declarator;
3253 if (declarator
3254 && declarator->kind == cdk_function)
3255 {
3256 error_at (type_location,
3257 "new types may not be defined in a return type");
3258 inform (type_location,
3259 "(perhaps a semicolon is missing after the definition of %qT)",
3260 type);
3261 }
3262}
3263
3264/* A type-specifier (TYPE) has been parsed which cannot be followed by
3265 "<" in any valid C++ program. If the next token is indeed "<",
3266 issue a message warning the user about what appears to be an
3267 invalid attempt to form a template-id. LOCATION is the location
3268 of the type-specifier (TYPE) */
3269
3270static void
3271cp_parser_check_for_invalid_template_id (cp_parser* parser,
3272 tree type,
3273 enum tag_types tag_type,
3274 location_t location)
3275{
3276 cp_token_position start = 0;
3277
3278 if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
3279 {
3280 if (TREE_CODE (type)((enum tree_code) (type)->base.code) == TYPE_DECL)
3281 type = TREE_TYPE (type)((contains_struct_check ((type), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3281, __FUNCTION__))->typed.type)
;
3282 if (TYPE_P (type)(tree_code_type[(int) (((enum tree_code) (type)->base.code
))] == tcc_type)
&& !template_placeholder_p (type))
3283 error_at (location, "%qT is not a template", type);
3284 else if (identifier_p (type))
3285 {
3286 if (tag_type != none_type)
3287 error_at (location, "%qE is not a class template", type);
3288 else
3289 error_at (location, "%qE is not a template", type);
3290 }
3291 else
3292 error_at (location, "invalid template-id");
3293 /* Remember the location of the invalid "<". */
3294 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
3295 start = cp_lexer_token_position (parser->lexer, true);
3296 /* Consume the "<". */
3297 cp_lexer_consume_token (parser->lexer);
3298 /* Parse the template arguments. */
3299 cp_parser_enclosed_template_argument_list (parser);
3300 /* Permanently remove the invalid template arguments so that
3301 this error message is not issued again. */
3302 if (start)
3303 cp_lexer_purge_tokens_after (parser->lexer, start);
3304 }
3305}
3306
3307/* If parsing an integral constant-expression, issue an error message
3308 about the fact that THING appeared and return true. Otherwise,
3309 return false. In either case, set
3310 PARSER->NON_INTEGRAL_CONSTANT_EXPRESSION_P. */
3311
3312static bool
3313cp_parser_non_integral_constant_expression (cp_parser *parser,
3314 non_integral_constant thing)
3315{
3316 parser->non_integral_constant_expression_p = true;
3317 if (parser->integral_constant_expression_p)
3318 {
3319 if (!parser->allow_non_integral_constant_expression_p)
3320 {
3321 const char *msg = NULL__null;
3322 switch (thing)
3323 {
3324 case NIC_FLOAT:
3325 pedwarn (input_location, OPT_Wpedantic,
3326 "ISO C++ forbids using a floating-point literal "
3327 "in a constant-expression");
3328 return true;
3329 case NIC_CAST:
3330 error ("a cast to a type other than an integral or "
3331 "enumeration type cannot appear in a "
3332 "constant-expression");
3333 return true;
3334 case NIC_TYPEID:
3335 error ("%<typeid%> operator "
3336 "cannot appear in a constant-expression");
3337 return true;
3338 case NIC_NCC:
3339 error ("non-constant compound literals "
3340 "cannot appear in a constant-expression");
3341 return true;
3342 case NIC_FUNC_CALL:
3343 error ("a function call "
3344 "cannot appear in a constant-expression");
3345 return true;
3346 case NIC_INC:
3347 error ("an increment "
3348 "cannot appear in a constant-expression");
3349 return true;
3350 case NIC_DEC:
3351 error ("an decrement "
3352 "cannot appear in a constant-expression");
3353 return true;
3354 case NIC_ARRAY_REF:
3355 error ("an array reference "
3356 "cannot appear in a constant-expression");
3357 return true;
3358 case NIC_ADDR_LABEL:
3359 error ("the address of a label "
3360 "cannot appear in a constant-expression");
3361 return true;
3362 case NIC_OVERLOADED:
3363 error ("calls to overloaded operators "
3364 "cannot appear in a constant-expression");
3365 return true;
3366 case NIC_ASSIGNMENT:
3367 error ("an assignment cannot appear in a constant-expression");
3368 return true;
3369 case NIC_COMMA:
3370 error ("a comma operator "
3371 "cannot appear in a constant-expression");
3372 return true;
3373 case NIC_CONSTRUCTOR:
3374 error ("a call to a constructor "
3375 "cannot appear in a constant-expression");
3376 return true;
3377 case NIC_TRANSACTION:
3378 error ("a transaction expression "
3379 "cannot appear in a constant-expression");
3380 return true;
3381 case NIC_THIS:
3382 msg = "this";
3383 break;
3384 case NIC_FUNC_NAME:
3385 msg = "__FUNCTION__";
3386 break;
3387 case NIC_PRETTY_FUNC:
3388 msg = "__PRETTY_FUNCTION__";
3389 break;
3390 case NIC_C99_FUNC:
3391 msg = "__func__";
3392 break;
3393 case NIC_VA_ARG:
3394 msg = "va_arg";
3395 break;
3396 case NIC_ARROW:
3397 msg = "->";
3398 break;
3399 case NIC_POINT:
3400 msg = ".";
3401 break;
3402 case NIC_STAR:
3403 msg = "*";
3404 break;
3405 case NIC_ADDR:
3406 msg = "&";
3407 break;
3408 case NIC_PREINCREMENT:
3409 msg = "++";
3410 break;
3411 case NIC_PREDECREMENT:
3412 msg = "--";
3413 break;
3414 case NIC_NEW:
3415 msg = "new";
3416 break;
3417 case NIC_DEL:
3418 msg = "delete";
3419 break;
3420 default:
3421 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3421, __FUNCTION__))
;
3422 }
3423 if (msg)
3424 error ("%qs cannot appear in a constant-expression", msg);
3425 return true;
3426 }
3427 }
3428 return false;
3429}
3430
3431/* Emit a diagnostic for an invalid type name. This function commits
3432 to the current active tentative parse, if any. (Otherwise, the
3433 problematic construct might be encountered again later, resulting
3434 in duplicate error messages.) LOCATION is the location of ID. */
3435
3436static void
3437cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
3438 location_t location)
3439{
3440 tree decl, ambiguous_decls;
3441 cp_parser_commit_to_tentative_parse (parser);
3442 /* Try to lookup the identifier. */
3443 decl = cp_parser_lookup_name (parser, id, none_type,
3444 /*is_template=*/false,
3445 /*is_namespace=*/false,
3446 /*check_dependency=*/true,
3447 &ambiguous_decls, location);
3448 if (ambiguous_decls)
3449 /* If the lookup was ambiguous, an error will already have
3450 been issued. */
3451 return;
3452 /* If the lookup found a template-name, it means that the user forgot
3453 to specify an argument list. Emit a useful error message. */
3454 if (DECL_TYPE_TEMPLATE_P (decl)(((enum tree_code) (decl)->base.code) == TEMPLATE_DECL &&
((struct tree_template_decl *)(const_cast<union tree_node
*> ((((tree_check ((decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3454, __FUNCTION__, (TEMPLATE_DECL))))))))->result != (tree
) __null && ((enum tree_code) (((struct tree_template_decl
*)(const_cast<union tree_node *> ((((tree_check ((decl
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3454, __FUNCTION__, (TEMPLATE_DECL))))))))->result)->
base.code) == TYPE_DECL)
)
3455 {
3456 auto_diagnostic_group d;
3457 error_at (location,
3458 "invalid use of template-name %qE without an argument list",
3459 decl);
3460 if (DECL_CLASS_TEMPLATE_P (decl)((((enum tree_code) (decl)->base.code) == TEMPLATE_DECL &&
((struct tree_template_decl *)(const_cast<union tree_node
*> ((((tree_check ((decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3460, __FUNCTION__, (TEMPLATE_DECL))))))))->result != (tree
) __null && ((enum tree_code) (((struct tree_template_decl
*)(const_cast<union tree_node *> ((((tree_check ((decl
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3460, __FUNCTION__, (TEMPLATE_DECL))))))))->result)->
base.code) == TYPE_DECL) && (((enum tree_code) (((struct
tree_template_decl *)(const_cast<union tree_node *> ((
((tree_check ((decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3460, __FUNCTION__, (TEMPLATE_DECL))))))))->result)->
base.code) == TYPE_DECL && ((contains_struct_check ((
((struct tree_template_decl *)(const_cast<union tree_node *
> ((((tree_check ((decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3460, __FUNCTION__, (TEMPLATE_DECL))))))))->result), (TS_DECL_COMMON
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3460, __FUNCTION__))->decl_common.lang_flag_2)))
&& cxx_dialect < cxx17)
3461 inform (location, "class template argument deduction is only available "
3462 "with %<-std=c++17%> or %<-std=gnu++17%>");
3463 inform (DECL_SOURCE_LOCATION (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3463, __FUNCTION__))->decl_minimal.locus)
, "%qD declared here", decl);
3464 }
3465 else if (TREE_CODE (id)((enum tree_code) (id)->base.code) == BIT_NOT_EXPR)
3466 error_at (location, "invalid use of destructor %qD as a type", id);
3467 else if (TREE_CODE (decl)((enum tree_code) (decl)->base.code) == TYPE_DECL)
3468 /* Something like 'unsigned A a;' */
3469 error_at (location, "invalid combination of multiple type-specifiers");
3470 else if (!parser->scope)
3471 {
3472 /* Issue an error message. */
3473 auto_diagnostic_group d;
3474 name_hint hint;
3475 if (TREE_CODE (id)((enum tree_code) (id)->base.code) == IDENTIFIER_NODE)
3476 hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_TYPENAME, location);
3477 if (const char *suggestion = hint.suggestion ())
3478 {
3479 gcc_rich_location richloc (location);
3480 richloc.add_fixit_replace (suggestion);
3481 error_at (&richloc,
3482 "%qE does not name a type; did you mean %qs?",
3483 id, suggestion);
3484 }
3485 else
3486 error_at (location, "%qE does not name a type", id);
3487 /* If we're in a template class, it's possible that the user was
3488 referring to a type from a base class. For example:
3489
3490 template <typename T> struct A { typedef T X; };
3491 template <typename T> struct B : public A<T> { X x; };
3492
3493 The user should have said "typename A<T>::X". */
3494 if (cxx_dialect < cxx11 && id == ridpointers[(int)RID_CONSTEXPR])
3495 inform (location, "C++11 %<constexpr%> only available with "
3496 "%<-std=c++11%> or %<-std=gnu++11%>");
3497 else if (cxx_dialect < cxx11 && id == ridpointers[(int)RID_NOEXCEPT])
3498 inform (location, "C++11 %<noexcept%> only available with "
3499 "%<-std=c++11%> or %<-std=gnu++11%>");
3500 else if (TREE_CODE (id)((enum tree_code) (id)->base.code) == IDENTIFIER_NODE
3501 && (id_equal (id, "module") || id_equal (id, "import")))
3502 {
3503 if (modules_p ())
3504 inform (location, "%qE is not recognized as a module control-line",
3505 id);
3506 else if (cxx_dialect < cxx20)
3507 inform (location, "C++20 %qE only available with %<-fmodules-ts%>",
3508 id);
3509 else
3510 inform (location, "C++20 %qE only available with %<-fmodules-ts%>"
3511 ", which is not yet enabled with %<-std=c++20%>", id);
3512 }
3513 else if (cxx_dialect < cxx11
3514 && TREE_CODE (id)((enum tree_code) (id)->base.code) == IDENTIFIER_NODE
3515 && id_equal (id, "thread_local"))
3516 inform (location, "C++11 %<thread_local%> only available with "
3517 "%<-std=c++11%> or %<-std=gnu++11%>");
3518 else if (cxx_dialect < cxx20 && id == ridpointers[(int)RID_CONSTINIT])
3519 inform (location, "C++20 %<constinit%> only available with "
3520 "%<-std=c++20%> or %<-std=gnu++20%>");
3521 else if (!flag_conceptsglobal_options.x_flag_concepts && id == ridpointers[(int)RID_CONCEPT])
3522 inform (location, "%<concept%> only available with %<-std=c++20%> or "
3523 "%<-fconcepts%>");
3524 else if (!flag_conceptsglobal_options.x_flag_concepts && id == ridpointers[(int)RID_REQUIRES])
3525 inform (location, "%<requires%> only available with %<-std=c++20%> or "
3526 "%<-fconcepts%>");
3527 else if (processing_template_declscope_chain->x_processing_template_decl && current_class_typescope_chain->class_type
3528 && TYPE_BINFO (current_class_type)((tree_check3 ((scope_chain->class_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3528, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE
)))->type_non_common.maxval)
)
3529 {
3530 for (tree b = TREE_CHAIN (TYPE_BINFO (current_class_type))((contains_struct_check ((((tree_check3 ((scope_chain->class_type
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3530, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE
)))->type_non_common.maxval)), (TS_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3530, __FUNCTION__))->common.chain)
;
3531 b; b = TREE_CHAIN (b)((contains_struct_check ((b), (TS_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3531, __FUNCTION__))->common.chain)
)
3532 {
3533 tree base_type = BINFO_TYPE (b)((contains_struct_check (((tree_check ((b), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3533, __FUNCTION__, (TREE_BINFO)))), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3533, __FUNCTION__))->typed.type)
;
3534 if (CLASS_TYPE_P (base_type)(((((enum tree_code) (base_type)->base.code)) == RECORD_TYPE
|| (((enum tree_code) (base_type)->base.code)) == UNION_TYPE
) && ((tree_class_check ((base_type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3534, __FUNCTION__))->type_common.lang_flag_5))
3535 && dependent_type_p (base_type))
3536 {
3537 /* Go from a particular instantiation of the
3538 template (which will have an empty TYPE_FIELDs),
3539 to the main version. */
3540 base_type = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (base_type)((((((tree_class_check (((base_type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__))->type_with_lang_specific.lang_specific
))->use_template) && !(((((tree_class_check (((base_type
)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__))->type_with_lang_specific.lang_specific
))->use_template) == 2)) ? ((contains_struct_check ((((struct
tree_template_decl *)(const_cast<union tree_node *> ((
((tree_check ((((((contains_struct_check ((((tree_check ((((struct
tree_template_decl *)(const_cast<union tree_node *> ((
((tree_check ((((struct tree_template_info*)(tree_check (((((
tree_class_check (((tree_check3 (((base_type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE
)))), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__))->type_non_common.lang_1))), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__, (TEMPLATE_INFO))))->tmpl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__, (TEMPLATE_DECL))))))))->arguments), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__, (TREE_LIST)))->list.value)), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__))->typed.type)))), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__, (TEMPLATE_DECL))))))))->result), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3540, __FUNCTION__))->typed.type) : (base_type))
;
3541 for (tree field = TYPE_FIELDS (base_type)((tree_check3 ((base_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3541, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE
)))->type_non_common.values)
;
3542 field; field = DECL_CHAIN (field)(((contains_struct_check (((contains_struct_check ((field), (
TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3542, __FUNCTION__))), (TS_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3542, __FUNCTION__))->common.chain))
)
3543 if (TREE_CODE (field)((enum tree_code) (field)->base.code) == TYPE_DECL
3544 && DECL_NAME (field)((contains_struct_check ((field), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3544, __FUNCTION__))->decl_minimal.name)
== id)
3545 {
3546 inform (location,
3547 "(perhaps %<typename %T::%E%> was intended)",
3548 BINFO_TYPE (b)((contains_struct_check (((tree_check ((b), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3548, __FUNCTION__, (TREE_BINFO)))), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3548, __FUNCTION__))->typed.type)
, id);
3549 goto found;
3550 }
3551 }
3552 }
3553 found:;
3554 }
3555 }
3556 /* Here we diagnose qualified-ids where the scope is actually correct,
3557 but the identifier does not resolve to a valid type name. */
3558 else if (parser->scope != error_mark_nodeglobal_trees[TI_ERROR_MARK])
3559 {
3560 if (TREE_CODE (parser->scope)((enum tree_code) (parser->scope)->base.code) == NAMESPACE_DECL)
3561 {
3562 auto_diagnostic_group d;
3563 name_hint hint;
3564 if (decl == error_mark_nodeglobal_trees[TI_ERROR_MARK])
3565 hint = suggest_alternative_in_explicit_scope (location, id,
3566 parser->scope);
3567 const char *suggestion = hint.suggestion ();
3568 gcc_rich_location richloc (location_of (id));
3569 if (suggestion)
3570 richloc.add_fixit_replace (suggestion);
3571 if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
3572 {
3573 if (suggestion)
3574 error_at (&richloc,
3575 "%qE in namespace %qE does not name a template"
3576 " type; did you mean %qs?",
3577 id, parser->scope, suggestion);
3578 else
3579 error_at (&richloc,
3580 "%qE in namespace %qE does not name a template type",
3581 id, parser->scope);
3582 }
3583 else if (TREE_CODE (id)((enum tree_code) (id)->base.code) == TEMPLATE_ID_EXPR)
3584 {
3585 if (suggestion)
3586 error_at (&richloc,
3587 "%qE in namespace %qE does not name a template"
3588 " type; did you mean %qs?",
3589 TREE_OPERAND (id, 0)(*((const_cast<tree*> (tree_operand_check ((id), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3589, __FUNCTION__)))))
, parser->scope, suggestion);
3590 else
3591 error_at (&richloc,
3592 "%qE in namespace %qE does not name a template"
3593 " type",
3594 TREE_OPERAND (id, 0)(*((const_cast<tree*> (tree_operand_check ((id), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3594, __FUNCTION__)))))
, parser->scope);
3595 }
3596 else
3597 {
3598 if (suggestion)
3599 error_at (&richloc,
3600 "%qE in namespace %qE does not name a type"
3601 "; did you mean %qs?",
3602 id, parser->scope, suggestion);
3603 else
3604 error_at (&richloc,
3605 "%qE in namespace %qE does not name a type",
3606 id, parser->scope);
3607 }
3608 if (DECL_P (decl)(tree_code_type[(int) (((enum tree_code) (decl)->base.code
))] == tcc_declaration)
)
3609 inform (DECL_SOURCE_LOCATION (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3609, __FUNCTION__))->decl_minimal.locus)
, "%qD declared here", decl);
3610 }
3611 else if (CLASS_TYPE_P (parser->scope)(((((enum tree_code) (parser->scope)->base.code)) == RECORD_TYPE
|| (((enum tree_code) (parser->scope)->base.code)) == UNION_TYPE
) && ((tree_class_check ((parser->scope), (tcc_type
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3611, __FUNCTION__))->type_common.lang_flag_5))
3612 && constructor_name_p (id, parser->scope))
3613 {
3614 /* A<T>::A<T>() */
3615 auto_diagnostic_group d;
3616 error_at (location, "%<%T::%E%> names the constructor, not"
3617 " the type", parser->scope, id);
3618 if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
3619 error_at (location, "and %qT has no template constructors",
3620 parser->scope);
3621 }
3622 else if (TYPE_P (parser->scope)(tree_code_type[(int) (((enum tree_code) (parser->scope)->
base.code))] == tcc_type)
3623 && dependent_scope_p (parser->scope))
3624 {
3625 gcc_rich_location richloc (location);
3626 richloc.add_fixit_insert_before ("typename ");
3627 if (TREE_CODE (parser->scope)((enum tree_code) (parser->scope)->base.code) == TYPENAME_TYPE)
3628 error_at (&richloc,
3629 "need %<typename%> before %<%T::%D::%E%> because "
3630 "%<%T::%D%> is a dependent scope",
3631 TYPE_CONTEXT (parser->scope)((tree_class_check ((parser->scope), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3631, __FUNCTION__))->type_common.context)
,
3632 TYPENAME_TYPE_FULLNAME (parser->scope)(((tree_class_check (((tree_check ((parser->scope), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3632, __FUNCTION__, (TYPENAME_TYPE)))), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3632, __FUNCTION__))->type_non_common.values))
,
3633 id,
3634 TYPE_CONTEXT (parser->scope)((tree_class_check ((parser->scope), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3634, __FUNCTION__))->type_common.context)
,
3635 TYPENAME_TYPE_FULLNAME (parser->scope)(((tree_class_check (((tree_check ((parser->scope), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3635, __FUNCTION__, (TYPENAME_TYPE)))), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3635, __FUNCTION__))->type_non_common.values))
);
3636 else
3637 error_at (&richloc, "need %<typename%> before %<%T::%E%> because "
3638 "%qT is a dependent scope",
3639 parser->scope, id, parser->scope);
3640 }
3641 else if (TYPE_P (parser->scope)(tree_code_type[(int) (((enum tree_code) (parser->scope)->
base.code))] == tcc_type)
)
3642 {
3643 auto_diagnostic_group d;
3644 if (!COMPLETE_TYPE_P (parser->scope)(((tree_class_check ((parser->scope), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3644, __FUNCTION__))->type_common.size) != (tree) __null
)
)
3645 cxx_incomplete_type_error (location_of (id), NULL_TREE(tree) __null,
3646 parser->scope);
3647 else if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
3648 error_at (location_of (id),
3649 "%qE in %q#T does not name a template type",
3650 id, parser->scope);
3651 else if (TREE_CODE (id)((enum tree_code) (id)->base.code) == TEMPLATE_ID_EXPR)
3652 error_at (location_of (id),
3653 "%qE in %q#T does not name a template type",
3654 TREE_OPERAND (id, 0)(*((const_cast<tree*> (tree_operand_check ((id), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3654, __FUNCTION__)))))
, parser->scope);
3655 else
3656 error_at (location_of (id),
3657 "%qE in %q#T does not name a type",
3658 id, parser->scope);
3659 if (DECL_P (decl)(tree_code_type[(int) (((enum tree_code) (decl)->base.code
))] == tcc_declaration)
)
3660 inform (DECL_SOURCE_LOCATION (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3660, __FUNCTION__))->decl_minimal.locus)
, "%qD declared here", decl);
3661 }
3662 else
3663 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 3663, __FUNCTION__))
;
3664 }
3665}
3666
3667/* Check for a common situation where a type-name should be present,
3668 but is not, and issue a sensible error message. Returns true if an
3669 invalid type-name was detected.
3670
3671 The situation handled by this function are variable declarations of the
3672 form `ID a', where `ID' is an id-expression and `a' is a plain identifier.
3673 Usually, `ID' should name a type, but if we got here it means that it
3674 does not. We try to emit the best possible error message depending on
3675 how exactly the id-expression looks like. */
3676
3677static bool
3678cp_parser_parse_and_diagnose_invalid_type_name (cp_parser *parser)
3679{
3680 tree id;
3681 cp_token *token = cp_lexer_peek_token (parser->lexer);
3682
3683 /* Avoid duplicate error about ambiguous lookup. */
3684 if (token->type == CPP_NESTED_NAME_SPECIFIER((enum cpp_ttype) (((enum cpp_ttype) (CPP_KEYWORD + 1)) + 1)))
3685 {
3686 cp_token *next = cp_lexer_peek_nth_token (parser->lexer, 2);
3687 if (next->type == CPP_NAME && next->error_reported)
3688 goto out;
3689 }
3690
3691 cp_parser_parse_tentatively (parser);
3692 id = cp_parser_id_expression (parser,
3693 /*template_keyword_p=*/false,
3694 /*check_dependency_p=*/true,
3695 /*template_p=*/NULL__null,
3696 /*declarator_p=*/true,
3697 /*optional_p=*/false);
3698 /* If the next token is a (, this is a function with no explicit return
3699 type, i.e. constructor, destructor or conversion op. */
3700 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)
3701 || TREE_CODE (id)((enum tree_code) (id)->base.code) == TYPE_DECL)
3702 {
3703 cp_parser_abort_tentative_parse (parser);
3704 return false;
3705 }
3706 if (!cp_parser_parse_definitely (parser))
3707 return false;
3708
3709 /* Emit a diagnostic for the invalid type. */
3710 cp_parser_diagnose_invalid_type_name (parser, id, token->location);
3711 out:
3712 /* If we aren't in the middle of a declarator (i.e. in a
3713 parameter-declaration-clause), skip to the end of the declaration;
3714 there's no point in trying to process it. */
3715 if (!parser->in_declarator_p)
3716 cp_parser_skip_to_end_of_block_or_statement (parser);
3717 return true;
3718}
3719
3720/* Consume tokens up to, and including, the next non-nested closing `)'.
3721 Returns 1 iff we found a closing `)'. RECOVERING is true, if we
3722 are doing error recovery. Returns -1 if OR_TTYPE is not CPP_EOF and we
3723 found an unnested token of that type. */
3724
3725static int
3726cp_parser_skip_to_closing_parenthesis_1 (cp_parser *parser,
3727 bool recovering,
3728 cpp_ttype or_ttype,
3729 bool consume_paren)
3730{
3731 unsigned paren_depth = 0;
3732 unsigned brace_depth = 0;
3733 unsigned square_depth = 0;
3734 unsigned condop_depth = 0;
3735
3736 if (recovering && or_ttype == CPP_EOF
3737 && cp_parser_uncommitted_to_tentative_parse_p (parser))
3738 return 0;
3739
3740 while (true)
3741 {
3742 cp_token * token = cp_lexer_peek_token (parser->lexer);
3743
3744 /* Have we found what we're looking for before the closing paren? */
3745 if (token->type == or_ttype && or_ttype != CPP_EOF
3746 && !brace_depth && !paren_depth && !square_depth && !condop_depth)
3747 return -1;
3748
3749 switch (token->type)
3750 {
3751 case CPP_PRAGMA_EOL:
3752 if (!parser->lexer->in_pragma)
3753 break;
3754 /* FALLTHRU */
3755 case CPP_EOF:
3756 /* If we've run out of tokens, then there is no closing `)'. */
3757 return 0;
3758
3759 /* This is good for lambda expression capture-lists. */
3760 case CPP_OPEN_SQUARE:
3761 ++square_depth;
3762 break;
3763 case CPP_CLOSE_SQUARE:
3764 if (!square_depth--)
3765 return 0;
3766 break;
3767
3768 case CPP_SEMICOLON:
3769 /* This matches the processing in skip_to_end_of_statement. */
3770 if (!brace_depth)
3771 return 0;
3772 break;
3773
3774 case CPP_OPEN_BRACE:
3775 ++brace_depth;
3776 break;
3777 case CPP_CLOSE_BRACE:
3778 if (!brace_depth--)
3779 return 0;
3780 break;
3781
3782 case CPP_OPEN_PAREN:
3783 if (!brace_depth)
3784 ++paren_depth;
3785 break;
3786
3787 case CPP_CLOSE_PAREN:
3788 if (!brace_depth && !paren_depth--)
3789 {
3790 if (consume_paren)
3791 cp_lexer_consume_token (parser->lexer);
3792 return 1;
3793 }
3794 break;
3795
3796 case CPP_QUERY:
3797 if (!brace_depth && !paren_depth && !square_depth)
3798 ++condop_depth;
3799 break;
3800
3801 case CPP_COLON:
3802 if (!brace_depth && !paren_depth && !square_depth && condop_depth > 0)
3803 condop_depth--;
3804 break;
3805
3806 case CPP_KEYWORD:
3807 if (token->keyword != RID__EXPORT
3808 && token->keyword != RID__MODULE
3809 && token->keyword != RID__IMPORT)
3810 break;
3811 /* FALLTHROUGH */
3812
3813 case CPP_PRAGMA:
3814 /* We fell into a pragma. Skip it, and continue. */
3815 cp_parser_skip_to_pragma_eol (parser, recovering ? token : nullptr);
3816 continue;
3817
3818 default:
3819 break;
3820 }
3821
3822 /* Consume the token. */
3823 cp_lexer_consume_token (parser->lexer);
3824 }
3825}
3826
3827/* Consume tokens up to, and including, the next non-nested closing `)'.
3828 Returns 1 iff we found a closing `)'. RECOVERING is true, if we
3829 are doing error recovery. Returns -1 if OR_COMMA is true and we
3830 found an unnested token of that type. */
3831
3832static int
3833cp_parser_skip_to_closing_parenthesis (cp_parser *parser,
3834 bool recovering,
3835 bool or_comma,
3836 bool consume_paren)
3837{
3838 cpp_ttype ttype = or_comma ? CPP_COMMA : CPP_EOF;
3839 return cp_parser_skip_to_closing_parenthesis_1 (parser, recovering,
3840 ttype, consume_paren);
3841}
3842
3843/* Consume tokens until we reach the end of the current statement.
3844 Normally, that will be just before consuming a `;'. However, if a
3845 non-nested `}' comes first, then we stop before consuming that. */
3846
3847static void
3848cp_parser_skip_to_end_of_statement (cp_parser* parser)
3849{
3850 unsigned nesting_depth = 0;
3851
3852 /* Unwind generic function template scope if necessary. */
3853 if (parser->fully_implicit_function_template_p)
3854 abort_fully_implicit_template (parser);
3855
3856 while (true)
3857 {
3858 cp_token *token = cp_lexer_peek_token (parser->lexer);
3859
3860 switch (token->type)
3861 {
3862 case CPP_PRAGMA_EOL:
3863 if (!parser->lexer->in_pragma)
3864 break;
3865 /* FALLTHRU */
3866 case CPP_EOF:
3867 /* If we've run out of tokens, stop. */
3868 return;
3869
3870 case CPP_SEMICOLON:
3871 /* If the next token is a `;', we have reached the end of the
3872 statement. */
3873 if (!nesting_depth)
3874 return;
3875 break;
3876
3877 case CPP_CLOSE_BRACE:
3878 /* If this is a non-nested '}', stop before consuming it.
3879 That way, when confronted with something like:
3880
3881 { 3 + }
3882
3883 we stop before consuming the closing '}', even though we
3884 have not yet reached a `;'. */
3885 if (nesting_depth == 0)
3886 return;
3887
3888 /* If it is the closing '}' for a block that we have
3889 scanned, stop -- but only after consuming the token.
3890 That way given:
3891
3892 void f g () { ... }
3893 typedef int I;
3894
3895 we will stop after the body of the erroneously declared
3896 function, but before consuming the following `typedef'
3897 declaration. */
3898 if (--nesting_depth == 0)
3899 {
3900 cp_lexer_consume_token (parser->lexer);
3901 return;
3902 }
3903 break;
3904
3905 case CPP_OPEN_BRACE:
3906 ++nesting_depth;
3907 break;
3908
3909 case CPP_KEYWORD:
3910 if (token->keyword != RID__EXPORT
3911 && token->keyword != RID__MODULE
3912 && token->keyword != RID__IMPORT)
3913 break;
3914 /* FALLTHROUGH */
3915
3916 case CPP_PRAGMA:
3917 /* We fell into a pragma. Skip it, and continue or return. */
3918 cp_parser_skip_to_pragma_eol (parser, token);
3919 if (!nesting_depth)
3920 return;
3921 continue;
3922
3923 default:
3924 break;
3925 }
3926
3927 /* Consume the token. */
3928 cp_lexer_consume_token (parser->lexer);
3929 }
3930}
3931
3932/* This function is called at the end of a statement or declaration.
3933 If the next token is a semicolon, it is consumed; otherwise, error
3934 recovery is attempted. */
3935
3936static void
3937cp_parser_consume_semicolon_at_end_of_statement (cp_parser *parser)
3938{
3939 /* Look for the trailing `;'. */
3940 if (!cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON))
3941 {
3942 /* If there is additional (erroneous) input, skip to the end of
3943 the statement. */
3944 cp_parser_skip_to_end_of_statement (parser);
3945 /* If the next token is now a `;', consume it. */
3946 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
3947 cp_lexer_consume_token (parser->lexer);
3948 }
3949}
3950
3951/* Skip tokens until we have consumed an entire block, or until we
3952 have consumed a non-nested `;'. */
3953
3954static void
3955cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser)
3956{
3957 int nesting_depth = 0;
3958
3959 /* Unwind generic function template scope if necessary. */
3960 if (parser->fully_implicit_function_template_p)
3961 abort_fully_implicit_template (parser);
3962
3963 while (nesting_depth >= 0)
3964 {
3965 cp_token *token = cp_lexer_peek_token (parser->lexer);
3966
3967 switch (token->type)
3968 {
3969 case CPP_PRAGMA_EOL:
3970 if (!parser->lexer->in_pragma)
3971 break;
3972 /* FALLTHRU */
3973 case CPP_EOF:
3974 /* If we've run out of tokens, stop. */
3975 return;
3976
3977 case CPP_SEMICOLON:
3978 /* Stop if this is an unnested ';'. */
3979 if (!nesting_depth)
3980 nesting_depth = -1;
3981 break;
3982
3983 case CPP_CLOSE_BRACE:
3984 /* Stop if this is an unnested '}', or closes the outermost
3985 nesting level. */
3986 nesting_depth--;
3987 if (nesting_depth < 0)
3988 return;
3989 if (!nesting_depth)
3990 nesting_depth = -1;
3991 break;
3992
3993 case CPP_OPEN_BRACE:
3994 /* Nest. */
3995 nesting_depth++;
3996 break;
3997
3998 case CPP_KEYWORD:
3999 if (token->keyword != RID__EXPORT
4000 && token->keyword != RID__MODULE
4001 && token->keyword != RID__IMPORT)
4002 break;
4003 /* FALLTHROUGH */
4004
4005 case CPP_PRAGMA:
4006 /* Skip it, and continue or return. */
4007 cp_parser_skip_to_pragma_eol (parser, token);
4008 if (!nesting_depth)
4009 return;
4010 continue;
4011
4012 default:
4013 break;
4014 }
4015
4016 /* Consume the token. */
4017 cp_lexer_consume_token (parser->lexer);
4018 }
4019}
4020
4021/* Skip tokens until a non-nested closing curly brace is the next
4022 token, or there are no more tokens. Return true in the first case,
4023 false otherwise. */
4024
4025static bool
4026cp_parser_skip_to_closing_brace (cp_parser *parser)
4027{
4028 unsigned nesting_depth = 0;
4029
4030 while (true)
4031 {
4032 cp_token *token = cp_lexer_peek_token (parser->lexer);
4033
4034 switch (token->type)
4035 {
4036 case CPP_PRAGMA_EOL:
4037 if (!parser->lexer->in_pragma)
4038 break;
4039 /* FALLTHRU */
4040 case CPP_EOF:
4041 /* If we've run out of tokens, stop. */
4042 return false;
4043
4044 case CPP_CLOSE_BRACE:
4045 /* If the next token is a non-nested `}', then we have reached
4046 the end of the current block. */
4047 if (nesting_depth-- == 0)
4048 return true;
4049 break;
4050
4051 case CPP_OPEN_BRACE:
4052 /* If it the next token is a `{', then we are entering a new
4053 block. Consume the entire block. */
4054 ++nesting_depth;
4055 break;
4056
4057 default:
4058 break;
4059 }
4060
4061 /* Consume the token. */
4062 cp_lexer_consume_token (parser->lexer);
4063 }
4064}
4065
4066/* Consume tokens until we reach the end of the pragma. The PRAGMA_TOK
4067 parameter is the PRAGMA token, allowing us to purge the entire pragma
4068 sequence. PRAGMA_TOK can be NULL, if we're speculatively scanning
4069 forwards (not error recovery). */
4070
4071static void
4072cp_parser_skip_to_pragma_eol (cp_parser* parser, cp_token *pragma_tok)
4073{
4074 cp_token *token;
4075
4076 do
4077 {
4078 /* The preprocessor makes sure that a PRAGMA_EOL token appears
4079 before an EOF token, even when the EOF is on the pragma line.
4080 We should never get here without being inside a deferred
4081 pragma. */
4082 gcc_checking_assert (cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))((void)(!(cp_lexer_next_token_is_not (parser->lexer, CPP_EOF
)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4082, __FUNCTION__), 0 : 0))
;
4083 token = cp_lexer_consume_token (parser->lexer);
4084 }
4085 while (token->type != CPP_PRAGMA_EOL);
4086
4087 if (pragma_tok)
4088 {
4089 /* Ensure that the pragma is not parsed again. */
4090 cp_lexer_purge_tokens_after (parser->lexer, pragma_tok);
4091 parser->lexer->in_pragma = false;
4092 if (parser->lexer->in_omp_attribute_pragma
4093 && cp_lexer_next_token_is (parser->lexer, CPP_EOF))
4094 {
4095 parser->lexer = parser->lexer->next;
4096 /* Put the current source position back where it was before this
4097 lexer was pushed. */
4098 cp_lexer_set_source_position_from_token (parser->lexer->next_token);
4099 }
4100 }
4101}
4102
4103/* Require pragma end of line, resyncing with it as necessary. The
4104 arguments are as for cp_parser_skip_to_pragma_eol. */
4105
4106static void
4107cp_parser_require_pragma_eol (cp_parser *parser, cp_token *pragma_tok)
4108{
4109 parser->lexer->in_pragma = false;
4110 if (!cp_parser_require (parser, CPP_PRAGMA_EOL, RT_PRAGMA_EOL))
4111 cp_parser_skip_to_pragma_eol (parser, pragma_tok);
4112 else if (parser->lexer->in_omp_attribute_pragma
4113 && cp_lexer_next_token_is (parser->lexer, CPP_EOF))
4114 {
4115 parser->lexer = parser->lexer->next;
4116 /* Put the current source position back where it was before this
4117 lexer was pushed. */
4118 cp_lexer_set_source_position_from_token (parser->lexer->next_token);
4119 }
4120}
4121
4122/* This is a simple wrapper around make_typename_type. When the id is
4123 an unresolved identifier node, we can provide a superior diagnostic
4124 using cp_parser_diagnose_invalid_type_name. */
4125
4126static tree
4127cp_parser_make_typename_type (cp_parser *parser, tree id,
4128 location_t id_location)
4129{
4130 tree result;
4131 if (identifier_p (id))
4132 {
4133 result = make_typename_type (parser->scope, id, typename_type,
4134 /*complain=*/tf_none);
4135 if (result == error_mark_nodeglobal_trees[TI_ERROR_MARK])
4136 cp_parser_diagnose_invalid_type_name (parser, id, id_location);
4137 return result;
4138 }
4139 return make_typename_type (parser->scope, id, typename_type, tf_error);
4140}
4141
4142/* This is a wrapper around the
4143 make_{pointer,ptrmem,reference}_declarator functions that decides
4144 which one to call based on the CODE and CLASS_TYPE arguments. The
4145 CODE argument should be one of the values returned by
4146 cp_parser_ptr_operator. ATTRIBUTES represent the attributes that
4147 appertain to the pointer or reference. */
4148
4149static cp_declarator *
4150cp_parser_make_indirect_declarator (enum tree_code code, tree class_type,
4151 cp_cv_quals cv_qualifiers,
4152 cp_declarator *target,
4153 tree attributes)
4154{
4155 if (code == ERROR_MARK || target == cp_error_declarator)
4156 return cp_error_declarator;
4157
4158 if (code == INDIRECT_REF)
4159 if (class_type == NULL_TREE(tree) __null)
4160 return make_pointer_declarator (cv_qualifiers, target, attributes);
4161 else
4162 return make_ptrmem_declarator (cv_qualifiers, class_type,
4163 target, attributes);
4164 else if (code == ADDR_EXPR && class_type == NULL_TREE(tree) __null)
4165 return make_reference_declarator (cv_qualifiers, target,
4166 false, attributes);
4167 else if (code == NON_LVALUE_EXPR && class_type == NULL_TREE(tree) __null)
4168 return make_reference_declarator (cv_qualifiers, target,
4169 true, attributes);
4170 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4170, __FUNCTION__))
;
4171}
4172
4173/* Create a new C++ parser. */
4174
4175static cp_parser *
4176cp_parser_new (cp_lexer *lexer)
4177{
4178 /* Initialize the binops_by_token so that we can get the tree
4179 directly from the token. */
4180 for (unsigned i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
4181 binops_by_token[binops[i].token_type] = binops[i];
4182
4183 cp_parser *parser = ggc_cleared_alloc<cp_parser> ();
4184 parser->lexer = lexer;
4185 parser->context = cp_parser_context_new (NULL__null);
4186
4187 /* For now, we always accept GNU extensions. */
4188 parser->allow_gnu_extensions_p = 1;
4189
4190 /* The `>' token is a greater-than operator, not the end of a
4191 template-id. */
4192 parser->greater_than_is_operator_p = true;
4193
4194 parser->default_arg_ok_p = true;
4195
4196 /* We are not parsing a constant-expression. */
4197 parser->integral_constant_expression_p = false;
4198 parser->allow_non_integral_constant_expression_p = false;
4199 parser->non_integral_constant_expression_p = false;
4200
4201 /* Local variable names are not forbidden. */
4202 parser->local_variables_forbidden_p = 0;
4203
4204 /* We are not processing an `extern "C"' declaration. */
4205 parser->in_unbraced_linkage_specification_p = false;
4206
4207 /* We are not processing a declarator. */
4208 parser->in_declarator_p = false;
4209
4210 /* We are not processing a template-argument-list. */
4211 parser->in_template_argument_list_p = false;
4212
4213 /* We are not in an iteration statement. */
4214 parser->in_statement = 0;
4215
4216 /* We are not in a switch statement. */
4217 parser->in_switch_statement_p = false;
4218
4219 /* We are not parsing a type-id inside an expression. */
4220 parser->in_type_id_in_expr_p = false;
4221
4222 /* String literals should be translated to the execution character set. */
4223 parser->translate_strings_p = true;
4224
4225 /* We are not parsing a function body. */
4226 parser->in_function_body = false;
4227
4228 /* We can correct until told otherwise. */
4229 parser->colon_corrects_to_scope_p = true;
4230
4231 /* The unparsed function queue is empty. */
4232 push_unparsed_function_queues (parser);
4233
4234 /* There are no classes being defined. */
4235 parser->num_classes_being_defined = 0;
4236
4237 /* No template parameters apply. */
4238 parser->num_template_parameter_lists = 0;
4239
4240 /* Special parsing data structures. */
4241 parser->omp_declare_simd = NULL__null;
4242 parser->oacc_routine = NULL__null;
4243
4244 /* Not declaring an implicit function template. */
4245 parser->auto_is_implicit_function_template_parm_p = false;
4246 parser->fully_implicit_function_template_p = false;
4247 parser->implicit_template_parms = 0;
4248 parser->implicit_template_scope = 0;
4249
4250 /* Allow constrained-type-specifiers. */
4251 parser->prevent_constrained_type_specifiers = 0;
4252
4253 /* We haven't yet seen an 'extern "C"'. */
4254 parser->innermost_linkage_specification_location = UNKNOWN_LOCATION((location_t) 0);
4255
4256 return parser;
4257}
4258
4259/* Create a cp_lexer structure which will emit the tokens in CACHE
4260 and push it onto the parser's lexer stack. This is used for delayed
4261 parsing of in-class method bodies and default arguments, and should
4262 not be confused with tentative parsing. */
4263static void
4264cp_parser_push_lexer_for_tokens (cp_parser *parser, cp_token_cache *cache)
4265{
4266 cp_lexer *lexer = cp_lexer_new_from_tokens (cache);
4267 lexer->next = parser->lexer;
4268 parser->lexer = lexer;
4269
4270 /* Move the current source position to that of the first token in the
4271 new lexer. */
4272 cp_lexer_set_source_position_from_token (lexer->next_token);
4273}
4274
4275/* Pop the top lexer off the parser stack. This is never used for the
4276 "main" lexer, only for those pushed by cp_parser_push_lexer_for_tokens. */
4277static void
4278cp_parser_pop_lexer (cp_parser *parser)
4279{
4280 cp_lexer *lexer = parser->lexer;
4281 parser->lexer = lexer->next;
4282 cp_lexer_destroy (lexer);
4283
4284 /* Put the current source position back where it was before this
4285 lexer was pushed. */
4286 cp_lexer_set_source_position_from_token (parser->lexer->next_token);
4287}
4288
4289/* Lexical conventions [gram.lex] */
4290
4291/* Parse an identifier. Returns an IDENTIFIER_NODE representing the
4292 identifier. */
4293
4294static cp_expr
4295cp_parser_identifier (cp_parser* parser)
4296{
4297 cp_token *token;
4298
4299 /* Look for the identifier. */
4300 token = cp_parser_require (parser, CPP_NAME, RT_NAME);
4301 /* Return the value. */
4302 if (token)
4303 return cp_expr (token->u.value, token->location);
4304 else
4305 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
4306}
4307
4308/* Parse a sequence of adjacent string constants. Returns a
4309 TREE_STRING representing the combined, nul-terminated string
4310 constant. If TRANSLATE is true, translate the string to the
4311 execution character set. If WIDE_OK is true, a wide string is
4312 invalid here.
4313
4314 C++98 [lex.string] says that if a narrow string literal token is
4315 adjacent to a wide string literal token, the behavior is undefined.
4316 However, C99 6.4.5p4 says that this results in a wide string literal.
4317 We follow C99 here, for consistency with the C front end.
4318
4319 This code is largely lifted from lex_string() in c-lex.c.
4320
4321 FUTURE: ObjC++ will need to handle @-strings here. */
4322static cp_expr
4323cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok,
4324 bool lookup_udlit = true)
4325{
4326 tree value;
4327 size_t count;
4328 struct obstack str_ob;
4329 struct obstack loc_ob;
4330 cpp_string str, istr, *strs;
4331 cp_token *tok;
4332 enum cpp_ttype type, curr_type;
4333 int have_suffix_p = 0;
4334 tree string_tree;
4335 tree suffix_id = NULL_TREE(tree) __null;
4336 bool curr_tok_is_userdef_p = false;
4337
4338 tok = cp_lexer_peek_token (parser->lexer);
4339 if (!cp_parser_is_string_literal (tok))
4340 {
4341 cp_parser_error (parser, "expected string-literal");
4342 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
4343 }
4344
4345 location_t loc = tok->location;
4346
4347 if (cpp_userdef_string_p (tok->type))
4348 {
4349 string_tree = USERDEF_LITERAL_VALUE (tok->u.value)(((struct tree_userdef_literal *)(tree_check ((tok->u.value
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4349, __FUNCTION__, (USERDEF_LITERAL))))->value)
;
4350 curr_type = cpp_userdef_string_remove_type (tok->type);
4351 curr_tok_is_userdef_p = true;
4352 }
4353 else
4354 {
4355 string_tree = tok->u.value;
4356 curr_type = tok->type;
4357 }
4358 type = curr_type;
4359
4360 /* Try to avoid the overhead of creating and destroying an obstack
4361 for the common case of just one string. */
4362 if (!cp_parser_is_string_literal
4363 (cp_lexer_peek_nth_token (parser->lexer, 2)))
4364 {
4365 cp_lexer_consume_token (parser->lexer);
4366
4367 str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree)((const char *)((tree_check ((string_tree), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4367, __FUNCTION__, (STRING_CST)))->string.str))
;
4368 str.len = TREE_STRING_LENGTH (string_tree)((tree_check ((string_tree), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4368, __FUNCTION__, (STRING_CST)))->string.length)
;
4369 count = 1;
4370
4371 if (curr_tok_is_userdef_p)
4372 {
4373 suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value)(((struct tree_userdef_literal *)(tree_check ((tok->u.value
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4373, __FUNCTION__, (USERDEF_LITERAL))))->suffix_id)
;
4374 have_suffix_p = 1;
4375 curr_type = cpp_userdef_string_remove_type (tok->type);
4376 }
4377 else
4378 curr_type = tok->type;
4379
4380 strs = &str;
4381 }
4382 else
4383 {
4384 location_t last_tok_loc = tok->location;
4385 gcc_obstack_init (&str_ob)_obstack_begin (((&str_ob)), (memory_block_pool::block_size
), (0), (mempool_obstack_chunk_alloc), (mempool_obstack_chunk_free
))
;
4386 gcc_obstack_init (&loc_ob)_obstack_begin (((&loc_ob)), (memory_block_pool::block_size
), (0), (mempool_obstack_chunk_alloc), (mempool_obstack_chunk_free
))
;
4387 count = 0;
4388
4389 do
4390 {
4391 cp_lexer_consume_token (parser->lexer);
4392 count++;
4393 str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree)((const char *)((tree_check ((string_tree), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4393, __FUNCTION__, (STRING_CST)))->string.str))
;
4394 str.len = TREE_STRING_LENGTH (string_tree)((tree_check ((string_tree), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4394, __FUNCTION__, (STRING_CST)))->string.length)
;
4395
4396 if (curr_tok_is_userdef_p)
4397 {
4398 tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value)(((struct tree_userdef_literal *)(tree_check ((tok->u.value
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4398, __FUNCTION__, (USERDEF_LITERAL))))->suffix_id)
;
4399 if (have_suffix_p == 0)
4400 {
4401 suffix_id = curr_suffix_id;
4402 have_suffix_p = 1;
4403 }
4404 else if (have_suffix_p == 1
4405 && curr_suffix_id != suffix_id)
4406 {
4407 error ("inconsistent user-defined literal suffixes"
4408 " %qD and %qD in string literal",
4409 suffix_id, curr_suffix_id);
4410 have_suffix_p = -1;
4411 }
4412 curr_type = cpp_userdef_string_remove_type (tok->type);
4413 }
4414 else
4415 curr_type = tok->type;
4416
4417 if (type != curr_type)
4418 {
4419 if (type == CPP_STRING)
4420 type = curr_type;
4421 else if (curr_type != CPP_STRING)
4422 {
4423 rich_location rich_loc (line_table, tok->location);
4424 rich_loc.add_range (last_tok_loc);
4425 error_at (&rich_loc,
4426 "concatenation of string literals with "
4427 "conflicting encoding prefixes");
4428 }
4429 }
4430
4431 obstack_grow (&str_ob, &str, sizeof (cpp_string))__extension__ ({ struct obstack *__o = (&str_ob); size_t __len
= (sizeof (cpp_string)); if (__extension__ ({ struct obstack
const *__o1 = (__o); (size_t) (__o1->chunk_limit - __o1->
next_free); }) < __len) _obstack_newchunk (__o, __len); memcpy
(__o->next_free, &str, __len); __o->next_free += __len
; (void) 0; })
;
4432 obstack_grow (&loc_ob, &tok->location, sizeof (location_t))__extension__ ({ struct obstack *__o = (&loc_ob); size_t __len
= (sizeof (location_t)); if (__extension__ ({ struct obstack
const *__o1 = (__o); (size_t) (__o1->chunk_limit - __o1->
next_free); }) < __len) _obstack_newchunk (__o, __len); memcpy
(__o->next_free, &tok->location, __len); __o->next_free
+= __len; (void) 0; })
;
4433
4434 last_tok_loc = tok->location;
4435
4436 tok = cp_lexer_peek_token (parser->lexer);
4437 if (cpp_userdef_string_p (tok->type))
4438 {
4439 string_tree = USERDEF_LITERAL_VALUE (tok->u.value)(((struct tree_userdef_literal *)(tree_check ((tok->u.value
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4439, __FUNCTION__, (USERDEF_LITERAL))))->value)
;
4440 curr_type = cpp_userdef_string_remove_type (tok->type);
4441 curr_tok_is_userdef_p = true;
4442 }
4443 else
4444 {
4445 string_tree = tok->u.value;
4446 curr_type = tok->type;
4447 curr_tok_is_userdef_p = false;
4448 }
4449 }
4450 while (cp_parser_is_string_literal (tok));
4451
4452 /* A string literal built by concatenation has its caret=start at
4453 the start of the initial string, and its finish at the finish of
4454 the final string literal. */
4455 loc = make_location (loc, loc, get_finish (last_tok_loc));
4456
4457 strs = (cpp_string *) obstack_finish (&str_ob)__extension__ ({ struct obstack *__o1 = (&str_ob); void *
__value = (void *) __o1->object_base; if (__o1->next_free
== __value) __o1->maybe_empty_object = 1; __o1->next_free
= (sizeof (ptrdiff_t) < sizeof (void *) ? ((__o1->object_base
) + (((__o1->next_free) - (__o1->object_base) + (__o1->
alignment_mask)) & ~(__o1->alignment_mask))) : (char *
) (((ptrdiff_t) (__o1->next_free) + (__o1->alignment_mask
)) & ~(__o1->alignment_mask))); if ((size_t) (__o1->
next_free - (char *) __o1->chunk) > (size_t) (__o1->
chunk_limit - (char *) __o1->chunk)) __o1->next_free = __o1
->chunk_limit; __o1->object_base = __o1->next_free; __value
; })
;
4458 }
4459
4460 if (type != CPP_STRING && !wide_ok)
4461 {
4462 cp_parser_error (parser, "a wide string is invalid in this context");
4463 type = CPP_STRING;
4464 }
4465
4466 if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate)
4467 (parse_in, strs, count, &istr, type))
4468 {
4469 value = build_string (istr.len, (const char *)istr.text);
4470 free (CONST_CAST (unsigned char *, istr.text)(const_cast<unsigned char *> ((istr.text))));
4471 if (count > 1)
4472 {
4473 location_t *locs = (location_t *)obstack_finish (&loc_ob)__extension__ ({ struct obstack *__o1 = (&loc_ob); void *
__value = (void *) __o1->object_base; if (__o1->next_free
== __value) __o1->maybe_empty_object = 1; __o1->next_free
= (sizeof (ptrdiff_t) < sizeof (void *) ? ((__o1->object_base
) + (((__o1->next_free) - (__o1->object_base) + (__o1->
alignment_mask)) & ~(__o1->alignment_mask))) : (char *
) (((ptrdiff_t) (__o1->next_free) + (__o1->alignment_mask
)) & ~(__o1->alignment_mask))); if ((size_t) (__o1->
next_free - (char *) __o1->chunk) > (size_t) (__o1->
chunk_limit - (char *) __o1->chunk)) __o1->next_free = __o1
->chunk_limit; __o1->object_base = __o1->next_free; __value
; })
;
4474 gcc_assert (g_string_concat_db)((void)(!(g_string_concat_db) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4474, __FUNCTION__), 0 : 0))
;
4475 g_string_concat_db->record_string_concatenation (count, locs);
4476 }
4477
4478 switch (type)
4479 {
4480 default:
4481 case CPP_STRING:
4482 TREE_TYPE (value)((contains_struct_check ((value), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4482, __FUNCTION__))->typed.type)
= char_array_type_nodec_global_trees[CTI_CHAR_ARRAY_TYPE];
4483 break;
4484 case CPP_UTF8STRING:
4485 if (flag_char8_tglobal_options.x_flag_char8_t)
4486 TREE_TYPE (value)((contains_struct_check ((value), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4486, __FUNCTION__))->typed.type)
= char8_array_type_nodec_global_trees[CTI_CHAR8_ARRAY_TYPE];
4487 else
4488 TREE_TYPE (value)((contains_struct_check ((value), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4488, __FUNCTION__))->typed.type)
= char_array_type_nodec_global_trees[CTI_CHAR_ARRAY_TYPE];
4489 break;
4490 case CPP_STRING16:
4491 TREE_TYPE (value)((contains_struct_check ((value), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4491, __FUNCTION__))->typed.type)
= char16_array_type_nodec_global_trees[CTI_CHAR16_ARRAY_TYPE];
4492 break;
4493 case CPP_STRING32:
4494 TREE_TYPE (value)((contains_struct_check ((value), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4494, __FUNCTION__))->typed.type)
= char32_array_type_nodec_global_trees[CTI_CHAR32_ARRAY_TYPE];
4495 break;
4496 case CPP_WSTRING:
4497 TREE_TYPE (value)((contains_struct_check ((value), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4497, __FUNCTION__))->typed.type)
= wchar_array_type_nodec_global_trees[CTI_WCHAR_ARRAY_TYPE];
4498 break;
4499 }
4500
4501 value = fix_string_type (value);
4502
4503 if (have_suffix_p)
4504 {
4505 tree literal = build_userdef_literal (suffix_id, value,
4506 OT_NONE, NULL_TREE(tree) __null);
4507 if (lookup_udlit)
4508 value = cp_parser_userdef_string_literal (literal);
4509 else
4510 value = literal;
4511 }
4512 }
4513 else
4514 /* cpp_interpret_string has issued an error. */
4515 value = error_mark_nodeglobal_trees[TI_ERROR_MARK];
4516
4517 if (count > 1)
4518 {
4519 obstack_free (&str_ob, 0)__extension__ ({ struct obstack *__o = (&str_ob); void *__obj
= (void *) (0); if (__obj > (void *) __o->chunk &&
__obj < (void *) __o->chunk_limit) __o->next_free =
__o->object_base = (char *) __obj; else _obstack_free (__o
, __obj); })
;
4520 obstack_free (&loc_ob, 0)__extension__ ({ struct obstack *__o = (&loc_ob); void *__obj
= (void *) (0); if (__obj > (void *) __o->chunk &&
__obj < (void *) __o->chunk_limit) __o->next_free =
__o->object_base = (char *) __obj; else _obstack_free (__o
, __obj); })
;
4521 }
4522
4523 return cp_expr (value, loc);
4524}
4525
4526/* Look up a literal operator with the name and the exact arguments. */
4527
4528static tree
4529lookup_literal_operator (tree name, vec<tree, va_gc> *args)
4530{
4531 tree decl = lookup_name (name);
4532 if (!decl || !is_overloaded_fn (decl))
4533 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
4534
4535 for (lkp_iterator iter (decl); iter; ++iter)
4536 {
4537 tree fn = *iter;
4538
4539 if (tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (fn))((tree_check2 ((((contains_struct_check ((fn), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4539, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4539, __FUNCTION__, (FUNCTION_TYPE), (METHOD_TYPE)))->type_non_common
.values)
)
4540 {
4541 unsigned int ix;
4542 bool found = true;
4543
4544 for (ix = 0;
4545 found && ix < vec_safe_length (args) && parmtypes != NULL_TREE(tree) __null;
4546 ++ix, parmtypes = TREE_CHAIN (parmtypes)((contains_struct_check ((parmtypes), (TS_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4546, __FUNCTION__))->common.chain)
)
4547 {
4548 tree tparm = TREE_VALUE (parmtypes)((tree_check ((parmtypes), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4548, __FUNCTION__, (TREE_LIST)))->list.value)
;
4549 tree targ = TREE_TYPE ((*args)[ix])((contains_struct_check (((*args)[ix]), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4549, __FUNCTION__))->typed.type)
;
4550 bool ptr = TYPE_PTR_P (tparm)(((enum tree_code) (tparm)->base.code) == POINTER_TYPE);
4551 bool arr = TREE_CODE (targ)((enum tree_code) (targ)->base.code) == ARRAY_TYPE;
4552 if ((ptr || arr || !same_type_p (tparm, targ)comptypes ((tparm), (targ), 0))
4553 && (!ptr || !arr
4554 || !same_type_p (TREE_TYPE (tparm),comptypes ((((contains_struct_check ((tparm), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4554, __FUNCTION__))->typed.type)), (((contains_struct_check
((targ), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4555, __FUNCTION__))->typed.type)), 0)
4555 TREE_TYPE (targ))comptypes ((((contains_struct_check ((tparm), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4554, __FUNCTION__))->typed.type)), (((contains_struct_check
((targ), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4555, __FUNCTION__))->typed.type)), 0)
))
4556 found = false;
4557 }
4558
4559 if (found
4560 && ix == vec_safe_length (args)
4561 /* May be this should be sufficient_parms_p instead,
4562 depending on how exactly should user-defined literals
4563 work in presence of default arguments on the literal
4564 operator parameters. */
4565 && parmtypes == void_list_nodeglobal_trees[TI_VOID_LIST_NODE])
4566 return decl;
4567 }
4568 }
4569
4570 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
4571}
4572
4573/* Parse a user-defined char constant. Returns a call to a user-defined
4574 literal operator taking the character as an argument. */
4575
4576static cp_expr
4577cp_parser_userdef_char_literal (cp_parser *parser)
4578{
4579 cp_token *token = cp_lexer_consume_token (parser->lexer);
4580 tree literal = token->u.value;
4581 tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal)(((struct tree_userdef_literal *)(tree_check ((literal), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4581, __FUNCTION__, (USERDEF_LITERAL))))->suffix_id)
;
4582 tree value = USERDEF_LITERAL_VALUE (literal)(((struct tree_userdef_literal *)(tree_check ((literal), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4582, __FUNCTION__, (USERDEF_LITERAL))))->value)
;
4583 tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id)((const char *) (tree_check ((suffix_id), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4583, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
4584 tree decl, result;
4585
4586 /* Build up a call to the user-defined operator */
4587 /* Lookup the name we got back from the id-expression. */
4588 releasing_vec args;
4589 vec_safe_push (args, value);
4590 decl = lookup_literal_operator (name, args);
4591 if (!decl || decl == error_mark_nodeglobal_trees[TI_ERROR_MARK])
4592 {
4593 error ("unable to find character literal operator %qD with %qT argument",
4594 name, TREE_TYPE (value)((contains_struct_check ((value), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4594, __FUNCTION__))->typed.type)
);
4595 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
4596 }
4597 result = finish_call_expr (decl, &args, false, true, tf_warning_or_error);
4598 return result;
4599}
4600
4601/* A subroutine of cp_parser_userdef_numeric_literal to
4602 create a char... template parameter pack from a string node. */
4603
4604static tree
4605make_char_string_pack (tree value)
4606{
4607 tree charvec;
4608 tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
4609 const char *str = TREE_STRING_POINTER (value)((const char *)((tree_check ((value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4609, __FUNCTION__, (STRING_CST)))->string.str))
;
4610 int i, len = TREE_STRING_LENGTH (value)((tree_check ((value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4610, __FUNCTION__, (STRING_CST)))->string.length)
- 1;
4611 tree argvec = make_tree_vec (1);
4612
4613 /* Fill in CHARVEC with all of the parameters. */
4614 charvec = make_tree_vec (len);
4615 for (i = 0; i < len; ++i)
4616 {
4617 unsigned char s[3] = { '\'', str[i], '\'' };
4618 cpp_string in = { 3, s };
4619 cpp_string out = { 0, 0 };
4620 if (!cpp_interpret_string (parse_in, &in, 1, &out, CPP_STRING))
4621 return NULL_TREE(tree) __null;
4622 gcc_assert (out.len == 2)((void)(!(out.len == 2) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4622, __FUNCTION__), 0 : 0))
;
4623 TREE_VEC_ELT (charvec, i)(*((const_cast<tree *> (tree_vec_elt_check ((charvec), (
i), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4623, __FUNCTION__)))))
= build_int_cst (char_type_nodeinteger_types[itk_char],
4624 out.text[0]);
4625 }
4626
4627 /* Build the argument packs. */
4628 SET_ARGUMENT_PACK_ARGS (argpack, charvec)if (((enum tree_code) (argpack)->base.code) == TYPE_ARGUMENT_PACK
) ((contains_struct_check ((argpack), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4628, __FUNCTION__))->typed.type) = charvec; else (*((const_cast
<tree*> (tree_operand_check ((argpack), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4628, __FUNCTION__))))) = charvec
;
4629
4630 TREE_VEC_ELT (argvec, 0)(*((const_cast<tree *> (tree_vec_elt_check ((argvec), (
0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4630, __FUNCTION__)))))
= argpack;
4631
4632 return argvec;
4633}
4634
4635/* A subroutine of cp_parser_userdef_numeric_literal to
4636 create a char... template parameter pack from a string node. */
4637
4638static tree
4639make_string_pack (tree value)
4640{
4641 tree charvec;
4642 tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
4643 const unsigned char *str
4644 = (const unsigned char *) TREE_STRING_POINTER (value)((const char *)((tree_check ((value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4644, __FUNCTION__, (STRING_CST)))->string.str))
;
4645 int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (value))))((unsigned long) (*tree_int_cst_elt_check ((((tree_class_check
((((contains_struct_check ((((contains_struct_check ((value)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4645, __FUNCTION__))->typed.type)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4645, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4645, __FUNCTION__))->type_common.size_unit)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4645, __FUNCTION__)))
;
4646 int len = TREE_STRING_LENGTH (value)((tree_check ((value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4646, __FUNCTION__, (STRING_CST)))->string.length)
/ sz - 1;
4647 tree argvec = make_tree_vec (2);
4648
4649 tree str_char_type_node = TREE_TYPE (TREE_TYPE (value))((contains_struct_check ((((contains_struct_check ((value), (
TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4649, __FUNCTION__))->typed.type)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4649, __FUNCTION__))->typed.type)
;
4650 str_char_type_node = TYPE_MAIN_VARIANT (str_char_type_node)((tree_class_check ((str_char_type_node), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4650, __FUNCTION__))->type_common.main_variant)
;
4651
4652 /* First template parm is character type. */
4653 TREE_VEC_ELT (argvec, 0)(*((const_cast<tree *> (tree_vec_elt_check ((argvec), (
0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4653, __FUNCTION__)))))
= str_char_type_node;
4654
4655 /* Fill in CHARVEC with all of the parameters. */
4656 charvec = make_tree_vec (len);
4657 for (int i = 0; i < len; ++i)
4658 TREE_VEC_ELT (charvec, i)(*((const_cast<tree *> (tree_vec_elt_check ((charvec), (
i), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4658, __FUNCTION__)))))
4659 = double_int_to_tree (str_char_type_node,
4660 double_int::from_buffer (str + i * sz, sz));
4661
4662 /* Build the argument packs. */
4663 SET_ARGUMENT_PACK_ARGS (argpack, charvec)if (((enum tree_code) (argpack)->base.code) == TYPE_ARGUMENT_PACK
) ((contains_struct_check ((argpack), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4663, __FUNCTION__))->typed.type) = charvec; else (*((const_cast
<tree*> (tree_operand_check ((argpack), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4663, __FUNCTION__))))) = charvec
;
4664
4665 TREE_VEC_ELT (argvec, 1)(*((const_cast<tree *> (tree_vec_elt_check ((argvec), (
1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4665, __FUNCTION__)))))
= argpack;
4666
4667 return argvec;
4668}
4669
4670/* Parse a user-defined numeric constant. returns a call to a user-defined
4671 literal operator. */
4672
4673static cp_expr
4674cp_parser_userdef_numeric_literal (cp_parser *parser)
4675{
4676 cp_token *token = cp_lexer_consume_token (parser->lexer);
4677 tree literal = token->u.value;
4678 tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal)(((struct tree_userdef_literal *)(tree_check ((literal), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4678, __FUNCTION__, (USERDEF_LITERAL))))->suffix_id)
;
4679 tree value = USERDEF_LITERAL_VALUE (literal)(((struct tree_userdef_literal *)(tree_check ((literal), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4679, __FUNCTION__, (USERDEF_LITERAL))))->value)
;
4680 int overflow = USERDEF_LITERAL_OVERFLOW (literal)(((struct tree_userdef_literal *)(tree_check ((literal), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4680, __FUNCTION__, (USERDEF_LITERAL))))->overflow)
;
4681 tree num_string = USERDEF_LITERAL_NUM_STRING (literal)(((struct tree_userdef_literal *)(tree_check ((literal), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4681, __FUNCTION__, (USERDEF_LITERAL))))->num_string)
;
4682 tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id)((const char *) (tree_check ((suffix_id), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4682, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
4683 tree decl, result;
4684
4685 /* Look for a literal operator taking the exact type of numeric argument
4686 as the literal value. */
4687 releasing_vec args;
4688 vec_safe_push (args, value);
4689 decl = lookup_literal_operator (name, args);
4690 if (decl && decl != error_mark_nodeglobal_trees[TI_ERROR_MARK])
4691 {
4692 result = finish_call_expr (decl, &args, false, true,
4693 tf_warning_or_error);
4694
4695 if (TREE_CODE (TREE_TYPE (value))((enum tree_code) (((contains_struct_check ((value), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4695, __FUNCTION__))->typed.type))->base.code)
== INTEGER_TYPE && overflow > 0)
4696 {
4697 warning_at (token->location, OPT_Woverflow,
4698 "integer literal exceeds range of %qT type",
4699 long_long_unsigned_type_nodeinteger_types[itk_unsigned_long_long]);
4700 }
4701 else
4702 {
4703 if (overflow > 0)
4704 warning_at (token->location, OPT_Woverflow,
4705 "floating literal exceeds range of %qT type",
4706 long_double_type_nodeglobal_trees[TI_LONG_DOUBLE_TYPE]);
4707 else if (overflow < 0)
4708 warning_at (token->location, OPT_Woverflow,
4709 "floating literal truncated to zero");
4710 }
4711
4712 return result;
4713 }
4714
4715 /* If the numeric argument didn't work, look for a raw literal
4716 operator taking a const char* argument consisting of the number
4717 in string format. */
4718 args->truncate (0);
4719 vec_safe_push (args, num_string);
4720 decl = lookup_literal_operator (name, args);
4721 if (decl && decl != error_mark_nodeglobal_trees[TI_ERROR_MARK])
4722 {
4723 result = finish_call_expr (decl, &args, false, true,
4724 tf_warning_or_error);
4725 return result;
4726 }
4727
4728 /* If the raw literal didn't work, look for a non-type template
4729 function with parameter pack char.... Call the function with
4730 template parameter characters representing the number. */
4731 args->truncate (0);
4732 decl = lookup_literal_operator (name, args);
4733 if (decl && decl != error_mark_nodeglobal_trees[TI_ERROR_MARK])
4734 {
4735 tree tmpl_args = make_char_string_pack (num_string);
4736 if (tmpl_args == NULL_TREE(tree) __null)
4737 {
4738 error ("failed to translate literal to execution character set %qT",
4739 num_string);
4740 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
4741 }
4742 decl = lookup_template_function (decl, tmpl_args);
4743 result = finish_call_expr (decl, &args, false, true,
4744 tf_warning_or_error);
4745 return result;
4746 }
4747
4748 /* In C++14 the standard library defines complex number suffixes that
4749 conflict with GNU extensions. Prefer them if <complex> is #included. */
4750 bool ext = cpp_get_options (parse_in)->ext_numeric_literals;
4751 bool i14 = (cxx_dialect > cxx11
4752 && (id_equal (suffix_id, "i")
4753 || id_equal (suffix_id, "if")
4754 || id_equal (suffix_id, "il")));
4755 diagnostic_t kind = DK_ERROR;
4756 int opt = 0;
4757
4758 if (i14 && ext)
4759 {
4760 tree cxlit = lookup_qualified_name (std_nodecp_global_trees[CPTI_STD], "complex_literals",
4761 LOOK_want::NORMAL, false);
4762 if (cxlit == error_mark_nodeglobal_trees[TI_ERROR_MARK])
4763 {
4764 /* No <complex>, so pedwarn and use GNU semantics. */
4765 kind = DK_PEDWARN;
4766 opt = OPT_Wpedantic;
4767 }
4768 }
4769
4770 bool complained
4771 = emit_diagnostic (kind, input_location, opt,
4772 "unable to find numeric literal operator %qD", name);
4773
4774 if (!complained)
4775 /* Don't inform either. */;
4776 else if (i14)
4777 {
4778 inform (token->location, "add %<using namespace std::complex_literals%> "
4779 "(from %<<complex>%>) to enable the C++14 user-defined literal "
4780 "suffixes");
4781 if (ext)
4782 inform (token->location, "or use %<j%> instead of %<i%> for the "
4783 "GNU built-in suffix");
4784 }
4785 else if (!ext)
4786 inform (token->location, "use %<-fext-numeric-literals%> "
4787 "to enable more built-in suffixes");
4788
4789 if (kind == DK_ERROR)
4790 value = error_mark_nodeglobal_trees[TI_ERROR_MARK];
4791 else
4792 {
4793 /* Use the built-in semantics. */
4794 tree type;
4795 if (id_equal (suffix_id, "i"))
4796 {
4797 if (TREE_CODE (value)((enum tree_code) (value)->base.code) == INTEGER_CST)
4798 type = integer_type_nodeinteger_types[itk_int];
4799 else
4800 type = double_type_nodeglobal_trees[TI_DOUBLE_TYPE];
4801 }
4802 else if (id_equal (suffix_id, "if"))
4803 type = float_type_nodeglobal_trees[TI_FLOAT_TYPE];
4804 else /* if (id_equal (suffix_id, "il")) */
4805 type = long_double_type_nodeglobal_trees[TI_LONG_DOUBLE_TYPE];
4806
4807 value = fold_build2 (COMPLEX_EXPR, build_complex_type (type),fold_build2_loc (((location_t) 0), COMPLEX_EXPR, build_complex_type
(type), build_zero_cst (type), fold_convert_loc (((location_t
) 0), type, value) )
4808 build_zero_cst (type), fold_convert (type, value))fold_build2_loc (((location_t) 0), COMPLEX_EXPR, build_complex_type
(type), build_zero_cst (type), fold_convert_loc (((location_t
) 0), type, value) )
;
4809 }
4810
4811 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
4812 /* Avoid repeated diagnostics. */
4813 token->u.value = value;
4814 return value;
4815}
4816
4817/* Parse a user-defined string constant. Returns a call to a user-defined
4818 literal operator taking a character pointer and the length of the string
4819 as arguments. */
4820
4821static tree
4822cp_parser_userdef_string_literal (tree literal)
4823{
4824 tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal)(((struct tree_userdef_literal *)(tree_check ((literal), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4824, __FUNCTION__, (USERDEF_LITERAL))))->suffix_id)
;
4825 tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id)((const char *) (tree_check ((suffix_id), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4825, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
4826 tree value = USERDEF_LITERAL_VALUE (literal)(((struct tree_userdef_literal *)(tree_check ((literal), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4826, __FUNCTION__, (USERDEF_LITERAL))))->value)
;
4827 int len = TREE_STRING_LENGTH (value)((tree_check ((value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4827, __FUNCTION__, (STRING_CST)))->string.length)
4828 / TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (value))))((unsigned long) (*tree_int_cst_elt_check ((((tree_class_check
((((contains_struct_check ((((contains_struct_check ((value)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4828, __FUNCTION__))->typed.type)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4828, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4828, __FUNCTION__))->type_common.size_unit)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4828, __FUNCTION__)))
- 1;
4829 tree decl;
4830
4831 /* Build up a call to the user-defined operator. */
4832 /* Lookup the name we got back from the id-expression. */
4833 releasing_vec args;
4834 vec_safe_push (args, value);
4835 vec_safe_push (args, build_int_cst (size_type_nodeglobal_trees[TI_SIZE_TYPE], len));
4836 decl = lookup_literal_operator (name, args);
4837
4838 if (decl && decl != error_mark_nodeglobal_trees[TI_ERROR_MARK])
4839 return finish_call_expr (decl, &args, false, true,
4840 tf_warning_or_error);
4841
4842 /* Look for a suitable template function, either (C++20) with a single
4843 parameter of class type, or (N3599) with typename parameter CharT and
4844 parameter pack CharT... */
4845 args->truncate (0);
4846 decl = lookup_literal_operator (name, args);
4847 if (decl && decl != error_mark_nodeglobal_trees[TI_ERROR_MARK])
4848 {
4849 /* Use resolve_nondeduced_context to try to choose one form of template
4850 or the other. */
4851 tree tmpl_args = make_tree_vec (1);
4852 TREE_VEC_ELT (tmpl_args, 0)(*((const_cast<tree *> (tree_vec_elt_check ((tmpl_args)
, (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4852, __FUNCTION__)))))
= value;
4853 decl = lookup_template_function (decl, tmpl_args);
4854 tree res = resolve_nondeduced_context (decl, tf_none);
4855 if (DECL_P (res)(tree_code_type[(int) (((enum tree_code) (res)->base.code)
)] == tcc_declaration)
)
4856 decl = res;
4857 else
4858 {
4859 TREE_OPERAND (decl, 1)(*((const_cast<tree*> (tree_operand_check ((decl), (1),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4859, __FUNCTION__)))))
= make_string_pack (value);
4860 res = resolve_nondeduced_context (decl, tf_none);
4861 if (DECL_P (res)(tree_code_type[(int) (((enum tree_code) (res)->base.code)
)] == tcc_declaration)
)
4862 decl = res;
4863 }
4864 if (!DECL_P (decl)(tree_code_type[(int) (((enum tree_code) (decl)->base.code
))] == tcc_declaration)
&& cxx_dialect > cxx17)
4865 TREE_OPERAND (decl, 1)(*((const_cast<tree*> (tree_operand_check ((decl), (1),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4865, __FUNCTION__)))))
= tmpl_args;
4866 return finish_call_expr (decl, &args, false, true,
4867 tf_warning_or_error);
4868 }
4869
4870 error ("unable to find string literal operator %qD with %qT, %qT arguments",
4871 name, TREE_TYPE (value)((contains_struct_check ((value), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4871, __FUNCTION__))->typed.type)
, size_type_nodeglobal_trees[TI_SIZE_TYPE]);
4872 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
4873}
4874
4875
4876/* Basic concepts [gram.basic] */
4877
4878/* Parse a translation-unit.
4879
4880 translation-unit:
4881 declaration-seq [opt] */
4882
4883static void
4884cp_parser_translation_unit (cp_parser* parser)
4885{
4886 gcc_checking_assert (!cp_error_declarator)((void)(!(!cp_error_declarator) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4886, __FUNCTION__), 0 : 0))
;
4887
4888 /* Create the declarator obstack. */
4889 gcc_obstack_init (&declarator_obstack)_obstack_begin (((&declarator_obstack)), (memory_block_pool
::block_size), (0), (mempool_obstack_chunk_alloc), (mempool_obstack_chunk_free
))
;
4890 /* Create the error declarator. */
4891 cp_error_declarator = make_declarator (cdk_error);
4892 /* Create the empty parameter list. */
4893 no_parameters = make_parameter_declarator (NULL__null, NULL__null, NULL_TREE(tree) __null,
4894 UNKNOWN_LOCATION((location_t) 0));
4895 /* Remember where the base of the declarator obstack lies. */
4896 void *declarator_obstack_base = obstack_next_free (&declarator_obstack)((void *) (&declarator_obstack)->next_free);
4897
4898 push_deferring_access_checks (flag_access_controlglobal_options.x_flag_access_control
4899 ? dk_no_deferred : dk_no_check);
4900
4901 module_parse mp_state = MP_NOT_MODULE;
4902 if (modules_p () && !header_module_p ())
4903 mp_state = MP_FIRST;
4904
4905 bool implicit_extern_c = false;
4906
4907 /* Parse until EOF. */
4908 for (;;)
4909 {
4910 cp_token *token = cp_lexer_peek_token (parser->lexer);
4911
4912 /* If we're entering or exiting a region that's implicitly
4913 extern "C", modify the lang context appropriately. This is
4914 so horrible. Please die. */
4915 if (implicit_extern_c
4916 != cp_lexer_peek_token (parser->lexer)->implicit_extern_c)
4917 {
4918 implicit_extern_c = !implicit_extern_c;
4919 if (implicit_extern_c)
4920 push_lang_context (lang_name_ccp_global_trees[CPTI_LANG_NAME_C]);
4921 else
4922 pop_lang_context ();
4923 }
4924
4925 if (token->type == CPP_EOF)
4926 break;
4927
4928 if (modules_p ())
4929 {
4930 /* Top-level module declarations are ok, and change the
4931 portion of file we're in. Top-level import declarations
4932 are significant for the import portions. */
4933
4934 cp_token *next = token;
4935 bool exporting = token->keyword == RID__EXPORT;
4936 if (exporting)
4937 {
4938 cp_lexer_consume_token (parser->lexer);
4939 next = cp_lexer_peek_token (parser->lexer);
4940 }
4941 if (next->keyword == RID__MODULE)
4942 {
4943 mp_state
4944 = cp_parser_module_declaration (parser, mp_state, exporting);
4945 continue;
4946 }
4947 else if (next->keyword == RID__IMPORT)
4948 {
4949 if (mp_state == MP_FIRST)
4950 mp_state = MP_NOT_MODULE;
4951 cp_parser_import_declaration (parser, mp_state, exporting);
4952 continue;
4953 }
4954 else
4955 gcc_checking_assert (!exporting)((void)(!(!exporting) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4955, __FUNCTION__), 0 : 0))
;
4956
4957 if (mp_state == MP_GLOBAL && token->main_source_p)
4958 {
4959 static bool warned = false;
4960 if (!warned)
4961 {
4962 warned = true;
4963 error_at (token->location,
4964 "global module fragment contents must be"
4965 " from preprocessor inclusion");
4966 }
4967 }
4968 }
4969
4970 /* This relies on the ordering of module_parse values. */
4971 if (mp_state == MP_PURVIEW_IMPORTS || mp_state == MP_PRIVATE_IMPORTS)
4972 /* We're no longer in the import portion of a named module. */
4973 mp_state = module_parse (mp_state + 1);
4974 else if (mp_state == MP_FIRST)
4975 mp_state = MP_NOT_MODULE;
4976
4977 if (token->type == CPP_CLOSE_BRACE)
4978 {
4979 cp_parser_error (parser, "expected declaration");
4980 cp_lexer_consume_token (parser->lexer);
4981 /* If the next token is now a `;', consume it. */
4982 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
4983 cp_lexer_consume_token (parser->lexer);
4984 }
4985 else
4986 cp_parser_toplevel_declaration (parser);
4987 }
4988
4989 /* Get rid of the token array; we don't need it any more. */
4990 cp_lexer_destroy (parser->lexer);
4991 parser->lexer = NULL__null;
4992
4993 /* The EOF should have reset this. */
4994 gcc_checking_assert (!implicit_extern_c)((void)(!(!implicit_extern_c) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4994, __FUNCTION__), 0 : 0))
;
4995
4996 /* Make sure the declarator obstack was fully cleaned up. */
4997 gcc_assert (obstack_next_free (&declarator_obstack)((void)(!(((void *) (&declarator_obstack)->next_free) ==
declarator_obstack_base) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4998, __FUNCTION__), 0 : 0))
4998 == declarator_obstack_base)((void)(!(((void *) (&declarator_obstack)->next_free) ==
declarator_obstack_base) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 4998, __FUNCTION__), 0 : 0))
;
4999}
5000
5001/* Return the appropriate tsubst flags for parsing, possibly in N3276
5002 decltype context. */
5003
5004static inline tsubst_flags_t
5005complain_flags (bool decltype_p)
5006{
5007 tsubst_flags_t complain = tf_warning_or_error;
5008 if (decltype_p)
5009 complain |= tf_decltype;
5010 return complain;
5011}
5012
5013/* We're about to parse a collection of statements. If we're currently
5014 parsing tentatively, set up a firewall so that any nested
5015 cp_parser_commit_to_tentative_parse won't affect the current context. */
5016
5017static cp_token_position
5018cp_parser_start_tentative_firewall (cp_parser *parser)
5019{
5020 if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
5021 return 0;
5022
5023 cp_parser_parse_tentatively (parser);
5024 cp_parser_commit_to_topmost_tentative_parse (parser);
5025 return cp_lexer_token_position (parser->lexer, false);
5026}
5027
5028/* We've finished parsing the collection of statements. Wrap up the
5029 firewall and replace the relevant tokens with the parsed form. */
5030
5031static void
5032cp_parser_end_tentative_firewall (cp_parser *parser, cp_token_position start,
5033 tree expr)
5034{
5035 if (!start)
5036 return;
5037
5038 /* Finish the firewall level. */
5039 cp_parser_parse_definitely (parser);
5040 /* And remember the result of the parse for when we try again. */
5041 cp_token *token = cp_lexer_token_at (parser->lexer, start);
5042 token->type = CPP_PREPARSED_EXPR((enum cpp_ttype) (((enum cpp_ttype) (((enum cpp_ttype) (((enum
cpp_ttype) (CPP_KEYWORD + 1)) + 1)) + 1)) + 1))
;
5043 token->u.value = expr;
5044 token->keyword = RID_MAX;
5045 cp_lexer_purge_tokens_after (parser->lexer, start);
5046}
5047
5048/* Like the above functions, but let the user modify the tokens. Used by
5049 CPP_DECLTYPE and CPP_TEMPLATE_ID, where we are saving the side-effects for
5050 later parses, so it makes sense to localize the effects of
5051 cp_parser_commit_to_tentative_parse. */
5052
5053struct tentative_firewall
5054{
5055 cp_parser *parser;
5056 bool set;
5057
5058 tentative_firewall (cp_parser *p): parser(p)
5059 {
5060 /* If we're currently parsing tentatively, start a committed level as a
5061 firewall and then an inner tentative parse. */
5062 if ((set = cp_parser_uncommitted_to_tentative_parse_p (parser)))
5063 {
5064 cp_parser_parse_tentatively (parser);
5065 cp_parser_commit_to_topmost_tentative_parse (parser);
5066 cp_parser_parse_tentatively (parser);
5067 }
5068 }
5069
5070 ~tentative_firewall()
5071 {
5072 if (set)
5073 {
5074 /* Finish the inner tentative parse and the firewall, propagating any
5075 uncommitted error state to the outer tentative parse. */
5076 bool err = cp_parser_error_occurred (parser);
5077 cp_parser_parse_definitely (parser);
5078 cp_parser_parse_definitely (parser);
5079 if (err)
5080 cp_parser_simulate_error (parser);
5081 }
5082 }
5083};
5084
5085/* Some tokens naturally come in pairs e.g.'(' and ')'.
5086 This class is for tracking such a matching pair of symbols.
5087 In particular, it tracks the location of the first token,
5088 so that if the second token is missing, we can highlight the
5089 location of the first token when notifying the user about the
5090 problem. */
5091
5092template <typename traits_t>
5093class token_pair
5094{
5095 public:
5096 /* token_pair's ctor. */
5097 token_pair () : m_open_loc (UNKNOWN_LOCATION((location_t) 0)) {}
5098
5099 /* If the next token is the opening symbol for this pair, consume it and
5100 return true.
5101 Otherwise, issue an error and return false.
5102 In either case, record the location of the opening token. */
5103
5104 bool require_open (cp_parser *parser)
5105 {
5106 m_open_loc = cp_lexer_peek_token (parser->lexer)->location;
5107 return cp_parser_require (parser, traits_t::open_token_type,
5108 traits_t::required_token_open);
5109 }
5110
5111 /* Consume the next token from PARSER, recording its location as
5112 that of the opening token within the pair. */
5113
5114 cp_token * consume_open (cp_parser *parser)
5115 {
5116 cp_token *tok = cp_lexer_consume_token (parser->lexer);
5117 gcc_assert (tok->type == traits_t::open_token_type)((void)(!(tok->type == traits_t::open_token_type) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 5117, __FUNCTION__), 0 : 0))
;
5118 m_open_loc = tok->location;
5119 return tok;
5120 }
5121
5122 /* If the next token is the closing symbol for this pair, consume it
5123 and return it.
5124 Otherwise, issue an error, highlighting the location of the
5125 corresponding opening token, and return NULL. */
5126
5127 cp_token *require_close (cp_parser *parser) const
5128 {
5129 return cp_parser_require (parser, traits_t::close_token_type,
5130 traits_t::required_token_close,
5131 m_open_loc);
5132 }
5133
5134 location_t open_location () const { return m_open_loc; }
5135
5136 private:
5137 location_t m_open_loc;
5138};
5139
5140/* Traits for token_pair<T> for tracking matching pairs of parentheses. */
5141
5142struct matching_paren_traits
5143{
5144 static const enum cpp_ttype open_token_type = CPP_OPEN_PAREN;
5145 static const enum required_token required_token_open = RT_OPEN_PAREN;
5146 static const enum cpp_ttype close_token_type = CPP_CLOSE_PAREN;
5147 static const enum required_token required_token_close = RT_CLOSE_PAREN;
5148};
5149
5150/* "matching_parens" is a token_pair<T> class for tracking matching
5151 pairs of parentheses. */
5152
5153typedef token_pair<matching_paren_traits> matching_parens;
5154
5155/* Traits for token_pair<T> for tracking matching pairs of braces. */
5156
5157struct matching_brace_traits
5158{
5159 static const enum cpp_ttype open_token_type = CPP_OPEN_BRACE;
5160 static const enum required_token required_token_open = RT_OPEN_BRACE;
5161 static const enum cpp_ttype close_token_type = CPP_CLOSE_BRACE;
5162 static const enum required_token required_token_close = RT_CLOSE_BRACE;
5163};
5164
5165/* "matching_braces" is a token_pair<T> class for tracking matching
5166 pairs of braces. */
5167
5168typedef token_pair<matching_brace_traits> matching_braces;
5169
5170
5171/* Parse a GNU statement-expression, i.e. ({ stmts }), except for the
5172 enclosing parentheses. */
5173
5174static cp_expr
5175cp_parser_statement_expr (cp_parser *parser)
5176{
5177 cp_token_position start = cp_parser_start_tentative_firewall (parser);
5178
5179 /* Consume the '('. */
5180 location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
5181 matching_parens parens;
5182 parens.consume_open (parser);
5183 /* Start the statement-expression. */
5184 tree expr = begin_stmt_expr ();
5185 /* Parse the compound-statement. */
5186 cp_parser_compound_statement (parser, expr, BCS_NORMAL, false);
5187 /* Finish up. */
5188 expr = finish_stmt_expr (expr, false);
5189 /* Consume the ')'. */
5190 location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location;
5191 if (!parens.require_close (parser))
5192 cp_parser_skip_to_end_of_statement (parser);
5193
5194 cp_parser_end_tentative_firewall (parser, start, expr);
5195 location_t combined_loc = make_location (start_loc, start_loc, finish_loc);
5196 return cp_expr (expr, combined_loc);
5197}
5198
5199/* Expressions [gram.expr] */
5200
5201/* Parse a fold-operator.
5202
5203 fold-operator:
5204 - * / % ^ & | = < > << >>
5205 = -= *= /= %= ^= &= |= <<= >>=
5206 == != <= >= && || , .* ->*
5207
5208 This returns the tree code corresponding to the matched operator
5209 as an int. When the current token matches a compound assignment
5210 operator, the resulting tree code is the negative value of the
5211 non-assignment operator. */
5212
5213static int
5214cp_parser_fold_operator (cp_token *token)
5215{
5216 switch (token->type)
5217 {
5218 case CPP_PLUS: return PLUS_EXPR;
5219 case CPP_MINUS: return MINUS_EXPR;
5220 case CPP_MULT: return MULT_EXPR;
5221 case CPP_DIV: return TRUNC_DIV_EXPR;
5222 case CPP_MOD: return TRUNC_MOD_EXPR;
5223 case CPP_XOR: return BIT_XOR_EXPR;
5224 case CPP_AND: return BIT_AND_EXPR;
5225 case CPP_OR: return BIT_IOR_EXPR;
5226 case CPP_LSHIFT: return LSHIFT_EXPR;
5227 case CPP_RSHIFT: return RSHIFT_EXPR;
5228
5229 case CPP_EQ: return -NOP_EXPR;
5230 case CPP_PLUS_EQ: return -PLUS_EXPR;
5231 case CPP_MINUS_EQ: return -MINUS_EXPR;
5232 case CPP_MULT_EQ: return -MULT_EXPR;
5233 case CPP_DIV_EQ: return -TRUNC_DIV_EXPR;
5234 case CPP_MOD_EQ: return -TRUNC_MOD_EXPR;
5235 case CPP_XOR_EQ: return -BIT_XOR_EXPR;
5236 case CPP_AND_EQ: return -BIT_AND_EXPR;
5237 case CPP_OR_EQ: return -BIT_IOR_EXPR;
5238 case CPP_LSHIFT_EQ: return -LSHIFT_EXPR;
5239 case CPP_RSHIFT_EQ: return -RSHIFT_EXPR;
5240
5241 case CPP_EQ_EQ: return EQ_EXPR;
5242 case CPP_NOT_EQ: return NE_EXPR;
5243 case CPP_LESS: return LT_EXPR;
5244 case CPP_GREATER: return GT_EXPR;
5245 case CPP_LESS_EQ: return LE_EXPR;
5246 case CPP_GREATER_EQ: return GE_EXPR;
5247
5248 case CPP_AND_AND: return TRUTH_ANDIF_EXPR;
5249 case CPP_OR_OR: return TRUTH_ORIF_EXPR;
5250
5251 case CPP_COMMA: return COMPOUND_EXPR;
5252
5253 case CPP_DOT_STAR: return DOTSTAR_EXPR;
5254 case CPP_DEREF_STAR: return MEMBER_REF;
5255
5256 default: return ERROR_MARK;
5257 }
5258}
5259
5260/* Returns true if CODE indicates a binary expression, which is not allowed in
5261 the LHS of a fold-expression. More codes will need to be added to use this
5262 function in other contexts. */
5263
5264static bool
5265is_binary_op (tree_code code)
5266{
5267 switch (code)
5268 {
5269 case PLUS_EXPR:
5270 case POINTER_PLUS_EXPR:
5271 case MINUS_EXPR:
5272 case MULT_EXPR:
5273 case TRUNC_DIV_EXPR:
5274 case TRUNC_MOD_EXPR:
5275 case BIT_XOR_EXPR:
5276 case BIT_AND_EXPR:
5277 case BIT_IOR_EXPR:
5278 case LSHIFT_EXPR:
5279 case RSHIFT_EXPR:
5280
5281 case MODOP_EXPR:
5282
5283 case EQ_EXPR:
5284 case NE_EXPR:
5285 case LE_EXPR:
5286 case GE_EXPR:
5287 case LT_EXPR:
5288 case GT_EXPR:
5289
5290 case TRUTH_ANDIF_EXPR:
5291 case TRUTH_ORIF_EXPR:
5292
5293 case COMPOUND_EXPR:
5294
5295 case DOTSTAR_EXPR:
5296 case MEMBER_REF:
5297 return true;
5298
5299 default:
5300 return false;
5301 }
5302}
5303
5304/* If the next token is a suitable fold operator, consume it and return as
5305 the function above. */
5306
5307static int
5308cp_parser_fold_operator (cp_parser *parser)
5309{
5310 cp_token* token = cp_lexer_peek_token (parser->lexer);
5311 int code = cp_parser_fold_operator (token);
5312 if (code != ERROR_MARK)
5313 cp_lexer_consume_token (parser->lexer);
5314 return code;
5315}
5316
5317/* Parse a fold-expression.
5318
5319 fold-expression:
5320 ( ... folding-operator cast-expression)
5321 ( cast-expression folding-operator ... )
5322 ( cast-expression folding operator ... folding-operator cast-expression)
5323
5324 Note that the '(' and ')' are matched in primary expression. */
5325
5326static cp_expr
5327cp_parser_fold_expression (cp_parser *parser, tree expr1)
5328{
5329 cp_id_kind pidk;
5330
5331 // Left fold.
5332 if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
5333 {
5334 if (expr1)
5335 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5336 cp_lexer_consume_token (parser->lexer);
5337 int op = cp_parser_fold_operator (parser);
5338 if (op == ERROR_MARK)
5339 {
5340 cp_parser_error (parser, "expected binary operator");
5341 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5342 }
5343
5344 tree expr = cp_parser_cast_expression (parser, false, false,
5345 false, &pidk);
5346 if (expr == error_mark_nodeglobal_trees[TI_ERROR_MARK])
5347 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5348 return finish_left_unary_fold_expr (expr, op);
5349 }
5350
5351 const cp_token* token = cp_lexer_peek_token (parser->lexer);
5352 int op = cp_parser_fold_operator (parser);
5353 if (op == ERROR_MARK)
5354 {
5355 cp_parser_error (parser, "expected binary operator");
5356 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5357 }
5358
5359 if (cp_lexer_next_token_is_not (parser->lexer, CPP_ELLIPSIS))
5360 {
5361 cp_parser_error (parser, "expected ...");
5362 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5363 }
5364 cp_lexer_consume_token (parser->lexer);
5365
5366 /* The operands of a fold-expression are cast-expressions, so binary or
5367 conditional expressions are not allowed. We check this here to avoid
5368 tentative parsing. */
5369 if (EXPR_P (expr1)((tree_code_type[(int) (((enum tree_code) (expr1)->base.code
))]) >= tcc_reference && (tree_code_type[(int) (((
enum tree_code) (expr1)->base.code))]) <= tcc_expression
)
&& warning_suppressed_p (expr1, OPT_Wparentheses))
5370 /* OK, the expression was parenthesized. */;
5371 else if (is_binary_op (TREE_CODE (expr1)((enum tree_code) (expr1)->base.code)))
5372 error_at (location_of (expr1),
5373 "binary expression in operand of fold-expression");
5374 else if (TREE_CODE (expr1)((enum tree_code) (expr1)->base.code) == COND_EXPR
5375 || (REFERENCE_REF_P (expr1)((((enum tree_code) (expr1)->base.code) == INDIRECT_REF) &&
((contains_struct_check (((*((const_cast<tree*> (tree_operand_check
((expr1), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 5375, __FUNCTION__)))))), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 5375, __FUNCTION__))->typed.type) && (((enum tree_code
) (((contains_struct_check (((*((const_cast<tree*> (tree_operand_check
(((expr1)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 5375, __FUNCTION__)))))), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 5375, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
))
5376 && TREE_CODE (TREE_OPERAND (expr1, 0))((enum tree_code) ((*((const_cast<tree*> (tree_operand_check
((expr1), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 5376, __FUNCTION__))))))->base.code)
== COND_EXPR))
5377 error_at (location_of (expr1),
5378 "conditional expression in operand of fold-expression");
5379
5380 // Right fold.
5381 if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN))
5382 return finish_right_unary_fold_expr (expr1, op);
5383
5384 if (cp_lexer_next_token_is_not (parser->lexer, token->type))
5385 {
5386 cp_parser_error (parser, "mismatched operator in fold-expression");
5387 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5388 }
5389 cp_lexer_consume_token (parser->lexer);
5390
5391 // Binary left or right fold.
5392 tree expr2 = cp_parser_cast_expression (parser, false, false, false, &pidk);
5393 if (expr2 == error_mark_nodeglobal_trees[TI_ERROR_MARK])
5394 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5395 return finish_binary_fold_expr (expr1, expr2, op);
5396}
5397
5398/* Parse a primary-expression.
5399
5400 primary-expression:
5401 literal
5402 this
5403 ( expression )
5404 id-expression
5405 lambda-expression (C++11)
5406
5407 GNU Extensions:
5408
5409 primary-expression:
5410 ( compound-statement )
5411 __builtin_va_arg ( assignment-expression , type-id )
5412 __builtin_offsetof ( type-id , offsetof-expression )
5413
5414 C++ Extensions:
5415 __has_nothrow_assign ( type-id )
5416 __has_nothrow_constructor ( type-id )
5417 __has_nothrow_copy ( type-id )
5418 __has_trivial_assign ( type-id )
5419 __has_trivial_constructor ( type-id )
5420 __has_trivial_copy ( type-id )
5421 __has_trivial_destructor ( type-id )
5422 __has_virtual_destructor ( type-id )
5423 __is_abstract ( type-id )
5424 __is_base_of ( type-id , type-id )
5425 __is_class ( type-id )
5426 __is_empty ( type-id )
5427 __is_enum ( type-id )
5428 __is_final ( type-id )
5429 __is_literal_type ( type-id )
5430 __is_pod ( type-id )
5431 __is_polymorphic ( type-id )
5432 __is_std_layout ( type-id )
5433 __is_trivial ( type-id )
5434 __is_union ( type-id )
5435
5436 Objective-C++ Extension:
5437
5438 primary-expression:
5439 objc-expression
5440
5441 literal:
5442 __null
5443
5444 ADDRESS_P is true iff this expression was immediately preceded by
5445 "&" and therefore might denote a pointer-to-member. CAST_P is true
5446 iff this expression is the target of a cast. TEMPLATE_ARG_P is
5447 true iff this expression is a template argument.
5448
5449 Returns a representation of the expression. Upon return, *IDK
5450 indicates what kind of id-expression (if any) was present. */
5451
5452static cp_expr
5453cp_parser_primary_expression (cp_parser *parser,
5454 bool address_p,
5455 bool cast_p,
5456 bool template_arg_p,
5457 bool decltype_p,
5458 cp_id_kind *idk)
5459{
5460 cp_token *token = NULL__null;
5461
5462 /* Assume the primary expression is not an id-expression. */
5463 *idk = CP_ID_KIND_NONE;
5464
5465 /* Peek at the next token. */
5466 token = cp_lexer_peek_token (parser->lexer);
5467 switch ((int) token->type)
5468 {
5469 /* literal:
5470 integer-literal
5471 character-literal
5472 floating-literal
5473 string-literal
5474 boolean-literal
5475 pointer-literal
5476 user-defined-literal */
5477 case CPP_CHAR:
5478 case CPP_CHAR16:
5479 case CPP_CHAR32:
5480 case CPP_WCHAR:
5481 case CPP_UTF8CHAR:
5482 case CPP_NUMBER:
5483 case CPP_PREPARSED_EXPR((enum cpp_ttype) (((enum cpp_ttype) (((enum cpp_ttype) (((enum
cpp_ttype) (CPP_KEYWORD + 1)) + 1)) + 1)) + 1))
:
5484 if (TREE_CODE (token->u.value)((enum tree_code) (token->u.value)->base.code) == USERDEF_LITERAL)
5485 return cp_parser_userdef_numeric_literal (parser);
5486 token = cp_lexer_consume_token (parser->lexer);
5487 if (TREE_CODE (token->u.value)((enum tree_code) (token->u.value)->base.code) == FIXED_CST)
5488 {
5489 error_at (token->location,
5490 "fixed-point types not supported in C++");
5491 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5492 }
5493 /* Floating-point literals are only allowed in an integral
5494 constant expression if they are cast to an integral or
5495 enumeration type. */
5496 if (TREE_CODE (token->u.value)((enum tree_code) (token->u.value)->base.code) == REAL_CST
5497 && parser->integral_constant_expression_p
5498 && pedanticglobal_options.x_pedantic)
5499 {
5500 /* CAST_P will be set even in invalid code like "int(2.7 +
5501 ...)". Therefore, we have to check that the next token
5502 is sure to end the cast. */
5503 if (cast_p)
5504 {
5505 cp_token *next_token;
5506
5507 next_token = cp_lexer_peek_token (parser->lexer);
5508 if (/* The comma at the end of an
5509 enumerator-definition. */
5510 next_token->type != CPP_COMMA
5511 /* The curly brace at the end of an enum-specifier. */
5512 && next_token->type != CPP_CLOSE_BRACE
5513 /* The end of a statement. */
5514 && next_token->type != CPP_SEMICOLON
5515 /* The end of the cast-expression. */
5516 && next_token->type != CPP_CLOSE_PAREN
5517 /* The end of an array bound. */
5518 && next_token->type != CPP_CLOSE_SQUARE
5519 /* The closing ">" in a template-argument-list. */
5520 && (next_token->type != CPP_GREATER
5521 || parser->greater_than_is_operator_p)
5522 /* C++0x only: A ">>" treated like two ">" tokens,
5523 in a template-argument-list. */
5524 && (next_token->type != CPP_RSHIFT
5525 || (cxx_dialect == cxx98)
5526 || parser->greater_than_is_operator_p))
5527 cast_p = false;
5528 }
5529
5530 /* If we are within a cast, then the constraint that the
5531 cast is to an integral or enumeration type will be
5532 checked at that point. If we are not within a cast, then
5533 this code is invalid. */
5534 if (!cast_p)
5535 cp_parser_non_integral_constant_expression (parser, NIC_FLOAT);
5536 }
5537 return (cp_expr (token->u.value, token->location)
5538 .maybe_add_location_wrapper ());
5539
5540 case CPP_CHAR_USERDEF:
5541 case CPP_CHAR16_USERDEF:
5542 case CPP_CHAR32_USERDEF:
5543 case CPP_WCHAR_USERDEF:
5544 case CPP_UTF8CHAR_USERDEF:
5545 return cp_parser_userdef_char_literal (parser);
5546
5547 case CPP_STRING:
5548 case CPP_STRING16:
5549 case CPP_STRING32:
5550 case CPP_WSTRING:
5551 case CPP_UTF8STRING:
5552 case CPP_STRING_USERDEF:
5553 case CPP_STRING16_USERDEF:
5554 case CPP_STRING32_USERDEF:
5555 case CPP_WSTRING_USERDEF:
5556 case CPP_UTF8STRING_USERDEF:
5557 /* ??? Should wide strings be allowed when parser->translate_strings_p
5558 is false (i.e. in attributes)? If not, we can kill the third
5559 argument to cp_parser_string_literal. */
5560 return (cp_parser_string_literal (parser,
5561 parser->translate_strings_p,
5562 true)
5563 .maybe_add_location_wrapper ());
5564
5565 case CPP_OPEN_PAREN:
5566 /* If we see `( { ' then we are looking at the beginning of
5567 a GNU statement-expression. */
5568 if (cp_parser_allow_gnu_extensions_p (parser)
5569 && cp_lexer_nth_token_is (parser->lexer, 2, CPP_OPEN_BRACE))
5570 {
5571 /* Statement-expressions are not allowed by the standard. */
5572 pedwarn (token->location, OPT_Wpedantic,
5573 "ISO C++ forbids braced-groups within expressions");
5574
5575 /* And they're not allowed outside of a function-body; you
5576 cannot, for example, write:
5577
5578 int i = ({ int j = 3; j + 1; });
5579
5580 at class or namespace scope. */
5581 if (!parser->in_function_body
5582 || parser->in_template_argument_list_p)
5583 {
5584 error_at (token->location,
5585 "statement-expressions are not allowed outside "
5586 "functions nor in template-argument lists");
5587 cp_parser_skip_to_end_of_block_or_statement (parser);
5588 if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN))
5589 cp_lexer_consume_token (parser->lexer);
5590 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5591 }
5592 else
5593 return cp_parser_statement_expr (parser);
5594 }
5595 /* Otherwise it's a normal parenthesized expression. */
5596 {
5597 cp_expr expr;
5598 bool saved_greater_than_is_operator_p;
5599
5600 location_t open_paren_loc = token->location;
5601
5602 /* Consume the `('. */
5603 matching_parens parens;
5604 parens.consume_open (parser);
5605 /* Within a parenthesized expression, a `>' token is always
5606 the greater-than operator. */
5607 saved_greater_than_is_operator_p
5608 = parser->greater_than_is_operator_p;
5609 parser->greater_than_is_operator_p = true;
5610
5611 if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
5612 /* Left fold expression. */
5613 expr = NULL_TREE(tree) __null;
5614 else
5615 /* Parse the parenthesized expression. */
5616 expr = cp_parser_expression (parser, idk, cast_p, decltype_p);
5617
5618 token = cp_lexer_peek_token (parser->lexer);
5619 if (token->type == CPP_ELLIPSIS || cp_parser_fold_operator (token))
5620 {
5621 expr = cp_parser_fold_expression (parser, expr);
5622 if (expr != error_mark_nodeglobal_trees[TI_ERROR_MARK]
5623 && cxx_dialect < cxx17)
5624 pedwarn (input_location, OPT_Wc__17_extensions,
5625 "fold-expressions only available with %<-std=c++17%> "
5626 "or %<-std=gnu++17%>");
5627 }
5628 else
5629 /* Let the front end know that this expression was
5630 enclosed in parentheses. This matters in case, for
5631 example, the expression is of the form `A::B', since
5632 `&A::B' might be a pointer-to-member, but `&(A::B)' is
5633 not. */
5634 expr = finish_parenthesized_expr (expr);
5635
5636 /* DR 705: Wrapping an unqualified name in parentheses
5637 suppresses arg-dependent lookup. We want to pass back
5638 CP_ID_KIND_QUALIFIED for suppressing vtable lookup
5639 (c++/37862), but none of the others. */
5640 if (*idk != CP_ID_KIND_QUALIFIED)
5641 *idk = CP_ID_KIND_NONE;
5642
5643 /* The `>' token might be the end of a template-id or
5644 template-parameter-list now. */
5645 parser->greater_than_is_operator_p
5646 = saved_greater_than_is_operator_p;
5647
5648 /* Consume the `)'. */
5649 token = cp_lexer_peek_token (parser->lexer);
5650 location_t close_paren_loc = token->location;
5651 bool no_wparens = warning_suppressed_p (expr, OPT_Wparentheses);
5652 expr.set_range (open_paren_loc, close_paren_loc);
5653 if (no_wparens)
5654 suppress_warning (expr, OPT_Wparentheses);
5655 if (!parens.require_close (parser)
5656 && !cp_parser_uncommitted_to_tentative_parse_p (parser))
5657 cp_parser_skip_to_end_of_statement (parser);
5658
5659 return expr;
5660 }
5661
5662 case CPP_OPEN_SQUARE:
5663 {
5664 if (c_dialect_objc ()((c_language & clk_objc) != 0))
5665 {
5666 /* We might have an Objective-C++ message. */
5667 cp_parser_parse_tentatively (parser);
5668 tree msg = cp_parser_objc_message_expression (parser);
5669 /* If that works out, we're done ... */
5670 if (cp_parser_parse_definitely (parser))
5671 return msg;
5672 /* ... else, fall though to see if it's a lambda. */
5673 }
5674 cp_expr lam = cp_parser_lambda_expression (parser);
5675 /* Don't warn about a failed tentative parse. */
5676 if (cp_parser_error_occurred (parser))
5677 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5678 maybe_warn_cpp0x (CPP0X_LAMBDA_EXPR);
5679 return lam;
5680 }
5681
5682 case CPP_OBJC_STRING:
5683 if (c_dialect_objc ()((c_language & clk_objc) != 0))
5684 /* We have an Objective-C++ string literal. */
5685 return cp_parser_objc_expression (parser);
5686 cp_parser_error (parser, "expected primary-expression");
5687 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5688
5689 case CPP_KEYWORD:
5690 switch (token->keyword)
5691 {
5692 /* These two are the boolean literals. */
5693 case RID_TRUE:
5694 cp_lexer_consume_token (parser->lexer);
5695 return cp_expr (boolean_true_nodeglobal_trees[TI_BOOLEAN_TRUE], token->location);
5696 case RID_FALSE:
5697 cp_lexer_consume_token (parser->lexer);
5698 return cp_expr (boolean_false_nodeglobal_trees[TI_BOOLEAN_FALSE], token->location);
5699
5700 /* The `__null' literal. */
5701 case RID_NULL:
5702 cp_lexer_consume_token (parser->lexer);
5703 return cp_expr (null_nodec_global_trees[CTI_NULL], token->location);
5704
5705 /* The `nullptr' literal. */
5706 case RID_NULLPTR:
5707 cp_lexer_consume_token (parser->lexer);
5708 return cp_expr (nullptr_nodecp_global_trees[CPTI_NULLPTR], token->location);
5709
5710 /* Recognize the `this' keyword. */
5711 case RID_THIS:
5712 cp_lexer_consume_token (parser->lexer);
5713 if (parser->local_variables_forbidden_p & THIS_FORBIDDEN(1 << 1))
5714 {
5715 error_at (token->location,
5716 "%<this%> may not be used in this context");
5717 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5718 }
5719 /* Pointers cannot appear in constant-expressions. */
5720 if (cp_parser_non_integral_constant_expression (parser, NIC_THIS))
5721 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5722 return cp_expr (finish_this_expr (), token->location);
5723
5724 /* The `operator' keyword can be the beginning of an
5725 id-expression. */
5726 case RID_OPERATOR:
5727 goto id_expression;
5728
5729 case RID_FUNCTION_NAME:
5730 case RID_PRETTY_FUNCTION_NAME:
5731 case RID_C99_FUNCTION_NAME:
5732 {
5733 non_integral_constant name;
5734
5735 /* The symbols __FUNCTION__, __PRETTY_FUNCTION__, and
5736 __func__ are the names of variables -- but they are
5737 treated specially. Therefore, they are handled here,
5738 rather than relying on the generic id-expression logic
5739 below. Grammatically, these names are id-expressions.
5740
5741 Consume the token. */
5742 token = cp_lexer_consume_token (parser->lexer);
5743
5744 switch (token->keyword)
5745 {
5746 case RID_FUNCTION_NAME:
5747 name = NIC_FUNC_NAME;
5748 break;
5749 case RID_PRETTY_FUNCTION_NAME:
5750 name = NIC_PRETTY_FUNC;
5751 break;
5752 case RID_C99_FUNCTION_NAME:
5753 name = NIC_C99_FUNC;
5754 break;
5755 default:
5756 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cp/parser.c"
, 5756, __FUNCTION__))
;
5757 }
5758
5759 if (cp_parser_non_integral_constant_expression (parser, name))
5760 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5761
5762 /* Look up the name. */
5763 return finish_fname (token->u.value);
5764 }
5765
5766 case RID_VA_ARG:
5767 {
5768 tree expression;
5769 tree type;
5770 location_t type_location;
5771 location_t start_loc
5772 = cp_lexer_peek_token (parser->lexer)->location;
5773 /* The `__builtin_va_arg' construct is used to handle
5774 `va_arg'. Consume the `__builtin_va_arg' token. */
5775 cp_lexer_consume_token (parser->lexer);
5776 /* Look for the opening `('. */
5777 matching_parens parens;
5778 parens.require_open (parser);
5779 /* Now, parse the assignment-expression. */
5780 expression = cp_parser_assignment_expression (parser);
5781 /* Look for the `,'. */
5782 cp_parser_require (parser, CPP_COMMA, RT_COMMA);
5783 type_location = cp_lexer_peek_token (parser->lexer)->location;
5784 /* Parse the type-id. */
5785 {
5786 type_id_in_expr_sentinel s (parser);
5787 type = cp_parser_type_id (parser);
5788 }
5789 /* Look for the closing `)'. */
5790 location_t finish_loc
5791 = cp_lexer_peek_token (parser->lexer)->location;
5792 parens.require_close (parser);
5793 /* Using `va_arg' in a constant-expression is not
5794 allowed. */
5795 if (cp_parser_non_integral_constant_expression (parser,
5796 NIC_VA_ARG))
5797 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5798 /* Construct a location of the form:
5799 __builtin_va_arg (v, int)
5800 ~~~~~~~~~~~~~~~~~~~~~^~~~
5801 with the caret at the type, ranging from the start of the
5802 "__builtin_va_arg" token to the close paren. */
5803 location_t combined_loc
5804 = make_location (type_location, start_loc, finish_loc);
5805 return build_x_va_arg (combined_loc, expression, type);
5806 }
5807
5808 case RID_OFFSETOF:
5809 return cp_parser_builtin_offsetof (parser);
5810
5811 case RID_HAS_NOTHROW_ASSIGN:
5812 case RID_HAS_NOTHROW_CONSTRUCTOR:
5813 case RID_HAS_NOTHROW_COPY:
5814 case RID_HAS_TRIVIAL_ASSIGN:
5815 case RID_HAS_TRIVIAL_CONSTRUCTOR:
5816 case RID_HAS_TRIVIAL_COPY:
5817 case RID_HAS_TRIVIAL_DESTRUCTOR:
5818 case RID_HAS_UNIQUE_OBJ_REPRESENTATIONS:
5819 case RID_HAS_VIRTUAL_DESTRUCTOR:
5820 case RID_IS_ABSTRACT:
5821 case RID_IS_AGGREGATE:
5822 case RID_IS_BASE_OF:
5823 case RID_IS_CLASS:
5824 case RID_IS_EMPTY:
5825 case RID_IS_ENUM:
5826 case RID_IS_FINAL:
5827 case RID_IS_LAYOUT_COMPATIBLE:
5828 case RID_IS_LITERAL_TYPE:
5829 case RID_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
5830 case RID_IS_POD:
5831 case RID_IS_POLYMORPHIC:
5832 case RID_IS_SAME_AS:
5833 case RID_IS_STD_LAYOUT:
5834 case RID_IS_TRIVIAL:
5835 case RID_IS_TRIVIALLY_ASSIGNABLE:
5836 case RID_IS_TRIVIALLY_CONSTRUCTIBLE:
5837 case RID_IS_TRIVIALLY_COPYABLE:
5838 case RID_IS_UNION:
5839 case RID_IS_ASSIGNABLE:
5840 case RID_IS_CONSTRUCTIBLE:
5841 case RID_IS_NOTHROW_ASSIGNABLE:
5842 case RID_IS_NOTHROW_CONSTRUCTIBLE:
5843 return cp_parser_trait_expr (parser, token->keyword);
5844
5845 // C++ concepts
5846 case RID_REQUIRES:
5847 return cp_parser_requires_expression (parser);
5848
5849 /* Objective-C++ expressions. */
5850 case RID_AT_ENCODE:
5851 case RID_AT_PROTOCOL:
5852 case RID_AT_SELECTOR:
5853 return cp_parser_objc_expression (parser);
5854
5855 case RID_TEMPLATE:
5856 if (parser->in_function_body
5857 && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
5858 == CPP_LESS))
5859 {
5860 error_at (token->location,
5861 "a template declaration cannot appear at block scope");
5862 cp_parser_skip_to_end_of_block_or_statement (parser);
5863 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5864 }
5865 /* FALLTHRU */
5866 default:
5867 cp_parser_error (parser, "expected primary-expression");
5868 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5869 }
5870
5871 /* An id-expression can start with either an identifier, a
5872 `::' as the beginning of a qualified-id, or the "operator"
5873 keyword. */
5874 case CPP_NAME:
5875 case CPP_SCOPE:
5876 case CPP_TEMPLATE_ID((enum cpp_ttype) (CPP_KEYWORD + 1)):
5877 case CPP_NESTED_NAME_SPECIFIER((enum cpp_ttype) (((enum cpp_ttype) (CPP_KEYWORD + 1)) + 1)):
5878 {
5879 id_expression:
5880 cp_expr id_expression;
5881 cp_expr decl;
5882 const char *error_msg;
5883 bool template_p;
5884 bool done;
5885 cp_token *id_expr_token;
5886
5887 /* Parse the id-expression. */
5888 id_expression
5889 = cp_parser_id_expression (parser,
5890 /*template_keyword_p=*/false,
5891 /*check_dependency_p=*/true,
5892 &template_p,
5893 /*declarator_p=*/false,
5894 /*optional_p=*/false);
5895 if (id_expression == error_mark_nodeglobal_trees[TI_ERROR_MARK])
5896 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5897 id_expr_token = token;
5898 token = cp_lexer_peek_token (parser->lexer);
5899 done = (token->type != CPP_OPEN_SQUARE
5900 && token->type != CPP_OPEN_PAREN
5901 && token->type != CPP_DOT
5902 && token->type != CPP_DEREF
5903 && token->type != CPP_PLUS_PLUS
5904 && token->type != CPP_MINUS_MINUS);
5905 /* If we have a template-id, then no further lookup is
5906 required. If the template-id was for a template-class, we
5907 will sometimes have a TYPE_DECL at this point. */
5908 if (TREE_CODE (id_expression)((enum tree_code) (id_expression)->base.code) == TEMPLATE_ID_EXPR
5909 || TREE_CODE (id_expression)((enum tree_code) (id_expression)->base.code) == TYPE_DECL)
5910 decl = id_expression;
5911 /* Look up the name. */
5912 else
5913 {
5914 tree ambiguous_decls;
5915
5916 /* If we already know that this lookup is ambiguous, then
5917 we've already issued an error message; there's no reason
5918 to check again. */
5919 if (id_expr_token->type == CPP_NAME
5920 && id_expr_token->error_reported)
5921 {
5922 cp_parser_simulate_error (parser);
5923 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5924 }
5925
5926 decl = cp_parser_lookup_name (parser, id_expression,
5927 none_type,
5928 template_p,
5929 /*is_namespace=*/false,
5930 /*check_dependency=*/true,
5931 &ambiguous_decls,
5932 id_expression.get_location ());
5933 /* If the lookup was ambiguous, an error will already have
5934 been issued. */
5935 if (ambiguous_decls)
5936 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5937
5938 /* In Objective-C++, we may have an Objective-C 2.0
5939 dot-syntax for classes here. */
5940 if (c_dialect_objc ()((c_language & clk_objc) != 0)
5941 && cp_lexer_peek_token (parser->lexer)->type == CPP_DOT
5942 && TREE_CODE (decl)((enum tree_code) (decl)->base.code) == TYPE_DECL
5943 && objc_is_class_name (decl))
5944 {
5945 tree component;
5946 cp_lexer_consume_token (parser->lexer);
5947 component = cp_parser_identifier (parser);
5948 if (component == error_mark_nodeglobal_trees[TI_ERROR_MARK])
5949 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
5950
5951 tree result = objc_build_class_component_ref (id_expression,
5952 component);
5953 /* Build a location of the form:
5954 expr.component
5955 ~~~~~^~~~~~~~~
5956 with caret at the start of the component name (at
5957 input_location), ranging from the start of the id_expression
5958 to the end of the component name. */
5959 location_t combined_loc
5960 = make_location (input_location, id_expression.get_start (),
5961 get_finish (input_location));
5962 protected_set_expr_location (result, combined_loc);
5963 return result;
5964 }
5965
5966 /* In Objective-C++, an instance variable (ivar) may be preferred
5967 to whatever cp_parser_lookup_name() found.
5968 Call objc_lookup_ivar. To avoid exposing cp_expr to the
5969 rest of c-family, we have to do a little extra work to preserve
5970 any location information in cp_expr "decl". Given that
5971 objc_lookup_ivar is implemented in "c-family" and "objc", we
5972 have a trip through the pure "tree" type, rather than cp_expr.
5973 Naively copying it back to "decl" would implicitly give the
5974 new cp_expr value an UNKNOWN_LOCATION for nodes that don't
5975 store an EXPR_LOCATION. Hence we only update "decl" (and
5976 hence its location_t) if we get back a different tree node. */
5977 tree decl_tree = objc_lookup_ivar (decl.get_value (),
5978 id_expression);
5979 if (decl_tree != decl.get_value ())
5980 decl = cp_expr (decl_tree);
5981
5982 /* If name lookup gives us a SCOPE_REF, then the
5983 qualifying scope was dependent. */
5984 if (TREE_CODE (decl)((enum tree_code) (decl)->base.code) == SCOPE_REF)
5985 {
5986 /* At this point, we do not know if DECL is a valid
5987 integral constant expression. We assume that it is
5988 in fact such an expression, so that code like:
5989
5990 template <int N> struct A {
5991 int a[B<N>::i];
5992 };
5993
5994 is accepted. At template-instantiation time, we
5995 will check that B<N>::i is actually a constant. */
5996 return decl;
5997 }
5998 /* Check to see if DECL is a local variable in a context
5999 where that is forbidden. */
6000 if ((parser->local_variables_forbidden_p & LOCAL_VARS_FORBIDDEN(1 << 0))
6001 && local_variable_p (decl)
6002 /* DR 2082 permits local variables in unevaluated contexts
6003 within a default argument. */
6004 && !cp_unevaluated_operand)
6005 {
6006 const char *msg
6007 = (TREE_CODE (decl)((enum tree_code) (decl)->base.code) == PARM_DECL
6008 ? _("parameter %qD may not appear in this context")gettext ("parameter %qD may not appear in this context")
6009 : _("local variable %qD may not appear in this context")gettext ("local variable %qD may not appear in this context"));
6010 error_at (id_expression.get_location (), msg,
6011 decl.get_value ());
6012 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
6013 }
6014 }
6015
6016 decl = (finish_id_expression
6017 (id_expression, decl, parser->scope,
6018 idk,
6019 parser->integral_constant_expression_p,
6020 parser->allow_non_integral_constant_expression_p,
6021 &parser->non_integral_constant_expression_p,
6022 template_p, done, address_p,
6023 template_arg_p,
6024 &error_msg,
6025 id_expression.get_location ()));
6026 if (error_msg)
6027 cp_parser_error (parser, error_msg);
6028 /* Build a location for an id-expression of the form:
6029 ::ns::id
6030 ~~~~~~^~
6031 or:
6032 id
6033 ^~
6034 i.e. from the start of the first token to the end of the final
6035 token, with the caret at the start of the unqualified-id. */
6036 location_t caret_loc = get_pure_location (id_expression.get_location ());
6037 location_t start_loc = get_start (id_expr_token->location);
6038 location_t finish_loc = get_finish (id_expression.get_location ());
6039 location_t combined_loc
6040 = make_location (caret_loc, start_loc, finish_loc);
6041
6042 decl.set_location (combined_loc);
6043 return decl;
6044 }
6045
6046 /* Anything else is an error. */
6047 default:
6048 cp_parser_error (parser, "expected primary-expression");
6049 return error_mark_nodeglobal_trees[TI_ERROR_MARK];
6050 }
6051}
6052
6053static inline cp_expr
6054cp_parser_primary_expression (cp_parser *parser,
6055 bool address_p,
6056 bool cast_p,
6057 bool template_arg_p,
6058 cp_id_kind *idk)
6059{
6060 return cp_parser_primary_expression (parser, address_p, cast_p, template_arg_p,
6061 /*decltype*/false, idk);
6062}
6063
6064/* Parse an id-expression.
6065
6066 id-expression:
6067 unqualified-id
6068 qualified-id
6069
6070 qualified-id:
6071 :: [opt] nested-name-specifier template [opt] unqualified-id
6072 :: identifier
6073 :: operator-function-id
6074 :: template-id
6075
6076 Return a representation of the unqualified portion of the
6077 identifier. Sets PARSER->SCOPE to the qualifying scope if there is
6078 a `::' or nested-name-specifier.
6079
6080 Often, if the id-expression was a qualified-id, the caller will
6081 want to make a SCOPE_REF to represent the qualified-id. This
6082 function does not do this in order to avoid wastefully creating
6083 SCOPE_REFs when they are not required.
6084
6085 If TEMPLATE_KEYWORD_P is true, then we have just seen the
6086 `template' keyword.
6087
6088 If CHECK_DEPENDENCY_P is false, then names are looked up inside
6089 uninstantiated templates.
6090
6091 If *TEMPLATE_P is non-NULL, it is set to true iff the
6092 `template' keyword is used to explicitly indicate that the entity
6093 named is a template.
6094
6095 If DECLARATOR_P is true, the id-expression is appearing as part of
6096 a declarator, rather than as part of an expression. */
6097
6098static cp_expr
6099cp_parser_id_expression (cp_parser *parser,
6100 bool template_keyword_p,
6101 bool check_dependency_p,
6102 bool *template_p,
6103 bool declarator_p,
6104 bool optional_p)
6105{
6106 bool global_scope_p;
6107 bool nested_name_specifier_p;
6108
6109 /* Assume the `template' keyword was not used. */
6110 if (template_p)
6111 *template_p = template_keyword_p;
6112
6113 /* Look for the optional `::' operator. */
6114 global_scope_p
6115 = (!template_keyword_p
6116 && (cp_parser_global_scope_opt (parser,
6117 /*current_scope_valid_p=*/false)
6118 != NULL_TREE(tree) __null));
6119
6120 /* Look for the optional nested-name-specifier. */
6121 nested_name_specifier_p
6122 = (cp_parser_nested_name_specifier_opt (parser,
6123 /*typename_keyword_p=*/false,
6124 check_dependency_p,
6125 /*type_p=*/false,
6126 declarator_p,
6127 template_keyword_p)
6128 != NULL_TREE(tree) __null);
6129
6130 /* If there is a nested-name-specifier, then we are looking at
6131 the first qualified-id production. */