[C++ PATCH] Commonixe using directive finishing
[gcc.git] / gcc / cp / parser.c
index c90782eafde4d915ee05f844444d36c21e48097b..b2d6c33300d40f4195c7f21ce23550694296c25c 100644 (file)
@@ -1308,7 +1308,7 @@ cp_lexer_start_debugging (cp_lexer* lexer)
 {
   if (!LEXER_DEBUGGING_ENABLED_P)
     fatal_error (input_location,
-                "LEXER_DEBUGGING_ENABLED_P is not set to true");
+                "%<LEXER_DEBUGGING_ENABLED_P%> is not set to true");
 
   lexer->debugging_p = true;
   cp_lexer_debug_stream = stderr;
@@ -1321,7 +1321,7 @@ cp_lexer_stop_debugging (cp_lexer* lexer)
 {
   if (!LEXER_DEBUGGING_ENABLED_P)
     fatal_error (input_location,
-                "LEXER_DEBUGGING_ENABLED_P is not set to true");
+                "%<LEXER_DEBUGGING_ENABLED_P%> is not set to true");
 
   lexer->debugging_p = false;
   cp_lexer_debug_stream = NULL;
@@ -4537,7 +4537,7 @@ cp_parser_userdef_numeric_literal (cp_parser *parser)
   else if (i14)
     {
       inform (token->location, "add %<using namespace std::complex_literals%> "
-             "(from <complex>) to enable the C++14 user-defined literal "
+             "(from %<<complex>%>) to enable the C++14 user-defined literal "
              "suffixes");
       if (ext)
        inform (token->location, "or use %<j%> instead of %<i%> for the "
@@ -6400,7 +6400,7 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
                  == CPP_SCOPE))
            {
              token = cp_lexer_consume_token (parser->lexer);
-             error_at (token->location, "decltype evaluates to %qT, "
+             error_at (token->location, "%<decltype%> evaluates to %qT, "
                        "which is not a class or enumeration type",
                        token->u.tree_check_value->value);
              parser->scope = error_mark_node;
@@ -9671,7 +9671,7 @@ cp_parser_question_colon_clause (cp_parser* parser, cp_expr logical_or_expr)
       && token->type == CPP_COLON)
     {
       pedwarn (token->location, OPT_Wpedantic, 
-               "ISO C++ does not allow ?: with omitted middle operand");
+              "ISO C++ does not allow %<?:%> with omitted middle operand");
       /* Implicit true clause.  */
       expr = NULL_TREE;
       c_inhibit_evaluation_warnings +=
@@ -14442,7 +14442,7 @@ cp_parser_static_assert(cp_parser *parser, bool member_p)
     {
       if (cxx_dialect < cxx17)
        pedwarn (input_location, OPT_Wpedantic,
-                "static_assert without a message "
+                "%<static_assert%> without a message "
                 "only available with %<-std=c++17%> or %<-std=gnu++17%>");
       /* Eat the ')'  */
       cp_lexer_consume_token (parser->lexer);
@@ -16479,10 +16479,7 @@ cp_parser_template_id (cp_parser *parser,
     {
       /* If it's not a class-template or a template-template, it should be
         a function-template.  */
-      gcc_assert ((DECL_FUNCTION_TEMPLATE_P (templ)
-                  || TREE_CODE (templ) == OVERLOAD
-                  || TREE_CODE (templ) == FUNCTION_DECL
-                  || BASELINK_P (templ)));
+      gcc_assert (OVL_P (templ) || BASELINK_P (templ));
 
       template_id = lookup_template_function (templ, arguments);
       if (TREE_CODE (template_id) == TEMPLATE_ID_EXPR)
@@ -19740,10 +19737,7 @@ cp_parser_using_directive (cp_parser* parser)
   attribs = cp_parser_attributes_opt (parser);
 
   /* Update the symbol table.  */
-  if (namespace_bindings_p ())
-    finish_namespace_using_directive (namespace_decl, attribs);
-  else
-    finish_local_using_directive (namespace_decl, attribs);
+  finish_using_directive (namespace_decl, attribs);
 
   /* Look for the final `;'.  */
   cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
@@ -19821,14 +19815,15 @@ cp_parser_asm_definition (cp_parser* parser)
          case RID_VOLATILE:
            if (volatile_loc)
              {
-               error_at (loc, "duplicate asm qualifier %qT", token->u.value);
+               error_at (loc, "duplicate %<asm%> qualifier %qT",
+                         token->u.value);
                inform (volatile_loc, "first seen here");
              }
            else
              {
                if (!parser->in_function_body)
-                 warning_at (loc, 0, "asm qualifier %qT ignored outside of "
-                                     "function body", token->u.value);
+                 warning_at (loc, 0, "%<asm%> qualifier %qT ignored "
+                             "outside of function body", token->u.value);
                volatile_loc = loc;
              }
            cp_lexer_consume_token (parser->lexer);
@@ -19837,7 +19832,8 @@ cp_parser_asm_definition (cp_parser* parser)
          case RID_INLINE:
            if (inline_loc)
              {
-               error_at (loc, "duplicate asm qualifier %qT", token->u.value);
+               error_at (loc, "duplicate %<asm%> qualifier %qT",
+                         token->u.value);
                inform (inline_loc, "first seen here");
              }
            else
@@ -19850,7 +19846,8 @@ cp_parser_asm_definition (cp_parser* parser)
          case RID_GOTO:
            if (goto_loc)
              {
-               error_at (loc, "duplicate asm qualifier %qT", token->u.value);
+               error_at (loc, "duplicate %<asm%> qualifier %qT",
+                         token->u.value);
                inform (goto_loc, "first seen here");
              }
            else
@@ -19862,7 +19859,7 @@ cp_parser_asm_definition (cp_parser* parser)
 
          case RID_CONST:
          case RID_RESTRICT:
-           error_at (loc, "%qT is not an asm qualifier", token->u.value);
+           error_at (loc, "%qT is not an %<asm%> qualifier", token->u.value);
            cp_lexer_consume_token (parser->lexer);
            continue;
 
@@ -19878,7 +19875,7 @@ cp_parser_asm_definition (cp_parser* parser)
 
   if (!parser->in_function_body && (inline_p || goto_p))
     {
-      error_at (first_loc, "asm qualifier outside of function body");
+      error_at (first_loc, "%<asm%> qualifier outside of function body");
       inline_p = goto_p = false;
     }
 
@@ -20260,7 +20257,7 @@ cp_parser_init_declarator (cp_parser* parser,
             on a function-definition.  */
          if (asm_specification)
            error_at (asm_spec_start_token->location,
-                     "an asm-specification is not allowed "
+                     "an %<asm%> specification is not allowed "
                      "on a function-definition");
          if (attributes)
            error_at (attributes_start_token->location,
@@ -27916,12 +27913,12 @@ cp_parser_template_declaration_after_parameters (cp_parser* parser,
        {
          if (cxx_dialect > cxx17)
            error ("literal operator template %qD has invalid parameter list;"
-                  "  Expected non-type template parameter pack <char...> "
+                  " expected non-type template parameter pack %<<char...>%> "
                   "or single non-type parameter of class type",
                   decl);
          else
-           error ("literal operator template %qD has invalid parameter list."
-                  "  Expected non-type template parameter pack <char...>",
+           error ("literal operator template %qD has invalid parameter list;"
+                  " expected non-type template parameter pack %<<char...>%>",
                   decl);
        }
     }
@@ -39637,8 +39634,8 @@ cp_parser_omp_declare_reduction (cp_parser *parser, cp_token *pragma_tok,
        error_at (loc, "reference type %qT in "
                       "%<#pragma omp declare reduction%>", type);
       else if (TYPE_QUALS_NO_ADDR_SPACE (type))
-       error_at (loc, "const, volatile or __restrict qualified type %qT in "
-                      "%<#pragma omp declare reduction%>", type);
+       error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
+                 "type %qT in %<#pragma omp declare reduction%>", type);
       else
        types.safe_push (type);
 
@@ -40136,6 +40133,9 @@ cp_parser_oacc_routine (cp_parser *parser, cp_token *pragma_tok,
        = cp_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
                                      "#pragma acc routine",
                                      cp_lexer_peek_token (parser->lexer));
+      /* The clauses are in reverse order; fix that to make later diagnostic
+        emission easier.  */
+      data.clauses = nreverse (data.clauses);
 
       if (decl && is_overloaded_fn (decl)
          && (TREE_CODE (decl) != FUNCTION_DECL
@@ -40232,6 +40232,9 @@ cp_parser_late_parsing_oacc_routine (cp_parser *parser, tree attrs)
   parser->oacc_routine->clauses
     = cp_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
                                  "#pragma acc routine", pragma_tok);
+  /* The clauses are in reverse order; fix that to make later diagnostic
+     emission easier.  */
+  parser->oacc_routine->clauses = nreverse (parser->oacc_routine->clauses);
   cp_parser_pop_lexer (parser);
   /* Later, cp_finalize_oacc_routine will process the clauses, and then set
      fndecl_seen.  */
@@ -40266,33 +40269,42 @@ cp_finalize_oacc_routine (cp_parser *parser, tree fndecl, bool is_defn)
          return;
        }
 
-      if (oacc_get_fn_attrib (fndecl))
+      int compatible
+       = oacc_verify_routine_clauses (fndecl, &parser->oacc_routine->clauses,
+                                      parser->oacc_routine->loc,
+                                      "#pragma acc routine");
+      if (compatible < 0)
        {
-         error_at (parser->oacc_routine->loc,
-                   "%<#pragma acc routine%> already applied to %qD", fndecl);
          parser->oacc_routine = NULL;
          return;
        }
-
-      if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl)))
+      if (compatible > 0)
        {
-         error_at (parser->oacc_routine->loc,
-                   TREE_USED (fndecl)
-                   ? G_("%<#pragma acc routine%> must be applied before use")
-                   : G_("%<#pragma acc routine%> must be applied before "
-                        "definition"));
-         parser->oacc_routine = NULL;
-         return;
        }
+      else
+       {
+         if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl)))
+           {
+             error_at (parser->oacc_routine->loc,
+                       TREE_USED (fndecl)
+                       ? G_("%<#pragma acc routine%> must be applied before"
+                            " use")
+                       : G_("%<#pragma acc routine%> must be applied before"
+                            " definition"));
+             parser->oacc_routine = NULL;
+             return;
+           }
 
-      /* Process the routine's dimension clauses.  */
-      tree dims = oacc_build_routine_dims (parser->oacc_routine->clauses);
-      oacc_replace_fn_attrib (fndecl, dims);
+         /* Set the routine's level of parallelism.  */
+         tree dims = oacc_build_routine_dims (parser->oacc_routine->clauses);
+         oacc_replace_fn_attrib (fndecl, dims);
 
-      /* Add an "omp declare target" attribute.  */
-      DECL_ATTRIBUTES (fndecl)
-       = tree_cons (get_identifier ("omp declare target"),
-                    NULL_TREE, DECL_ATTRIBUTES (fndecl));
+         /* Add an "omp declare target" attribute.  */
+         DECL_ATTRIBUTES (fndecl)
+           = tree_cons (get_identifier ("omp declare target"),
+                        parser->oacc_routine->clauses,
+                        DECL_ATTRIBUTES (fndecl));
+       }
 
       /* Don't unset parser->oacc_routine here: we may still need it to
         diagnose wrong usage.  But, remember that we've used this "#pragma acc
@@ -40489,7 +40501,7 @@ cp_parser_transaction (cp_parser *parser, cp_token *token)
   else if (keyword == RID_ATOMIC_CANCEL)
     {
       /* cancel-and-throw is unimplemented.  */
-      sorry ("atomic_cancel");
+      sorry ("%<atomic_cancel%>");
       noex = NULL_TREE;
     }
   else