OSDN Git Service

2014-02-26 Fabien Chene <fabien@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / cp / parser.c
index 9b3e56d..120360a 100644 (file)
@@ -1,6 +1,6 @@
 /* C++ Parser.
    Copyright (C) 2000, 2001, 2002, 2003, 2004,
-   2005, 2007, 2008, 2009, 2010, 2011  Free Software Foundation, Inc.
+   2005, 2007, 2008, 2009, 2010, 2011, 2012  Free Software Foundation, Inc.
    Written by Mark Mitchell <mark@codesourcery.com>.
 
    This file is part of GCC.
@@ -106,7 +106,9 @@ typedef enum non_integral_constant {
   /* a comma operator */
   NIC_COMMA,
   /* a call to a constructor */
-  NIC_CONSTRUCTOR
+  NIC_CONSTRUCTOR,
+  /* a transaction expression */
+  NIC_TRANSACTION
 } non_integral_constant;
 
 /* The various kinds of errors about name-lookup failing. */
@@ -171,7 +173,10 @@ typedef enum required_token {
   RT_INTERATION, /* iteration-statement */
   RT_JUMP, /* jump-statement */
   RT_CLASS_KEY, /* class-key */
-  RT_CLASS_TYPENAME_TEMPLATE /* class, typename, or template */
+  RT_CLASS_TYPENAME_TEMPLATE, /* class, typename, or template */
+  RT_TRANSACTION_ATOMIC, /* __transaction_atomic */
+  RT_TRANSACTION_RELAXED, /* __transaction_relaxed */
+  RT_TRANSACTION_CANCEL /* __transaction_cancel */
 } required_token;
 
 /* Prototypes.  */
@@ -210,7 +215,6 @@ static void cp_lexer_commit_tokens
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
-#ifdef ENABLE_CHECKING
 static void cp_lexer_print_token
   (FILE *, cp_token *);
 static inline bool cp_lexer_debugging_p
@@ -219,15 +223,6 @@ static void cp_lexer_start_debugging
   (cp_lexer *) ATTRIBUTE_UNUSED;
 static void cp_lexer_stop_debugging
   (cp_lexer *) ATTRIBUTE_UNUSED;
-#else
-/* If we define cp_lexer_debug_stream to NULL it will provoke warnings
-   about passing NULL to functions that require non-NULL arguments
-   (fputs, fprintf).  It will never be used, so all we need is a value
-   of the right type that's guaranteed not to be NULL.  */
-#define cp_lexer_debug_stream stdout
-#define cp_lexer_print_token(str, tok) (void) 0
-#define cp_lexer_debugging_p(lexer) 0
-#endif /* ENABLE_CHECKING */
 
 static cp_token_cache *cp_token_cache_new
   (cp_token *, cp_token *);
@@ -235,39 +230,73 @@ static cp_token_cache *cp_token_cache_new
 static void cp_parser_initial_pragma
   (cp_token *);
 
+static tree cp_literal_operator_id
+  (const char *);
+
 /* Manifest constants.  */
 #define CP_LEXER_BUFFER_SIZE ((256 * 1024) / sizeof (cp_token))
 #define CP_SAVED_TOKEN_STACK 5
 
 /* Variables.  */
 
-#ifdef ENABLE_CHECKING
 /* The stream to which debugging output should be written.  */
 static FILE *cp_lexer_debug_stream;
-#endif /* ENABLE_CHECKING */
 
 /* Nonzero if we are parsing an unevaluated operand: an operand to
    sizeof, typeof, or alignof.  */
 int cp_unevaluated_operand;
 
-#ifdef ENABLE_CHECKING
-/* Dump up to NUM tokens in BUFFER to FILE.  If NUM is 0, dump all the
-   tokens.  */
+/* Dump up to NUM tokens in BUFFER to FILE starting with token
+   START_TOKEN.  If START_TOKEN is NULL, the dump starts with the
+   first token in BUFFER.  If NUM is 0, dump all the tokens.  If
+   CURR_TOKEN is set and it is one of the tokens in BUFFER, it will be
+   highlighted by surrounding it in [[ ]].  */
 
-void
-cp_lexer_dump_tokens (FILE *file, VEC(cp_token,gc) *buffer, unsigned num)
+static void
+cp_lexer_dump_tokens (FILE *file, VEC(cp_token,gc) *buffer,
+                     cp_token *start_token, unsigned num,
+                     cp_token *curr_token)
 {
-  unsigned i;
+  unsigned i, nprinted;
   cp_token *token;
+  bool do_print;
 
   fprintf (file, "%u tokens\n", VEC_length (cp_token, buffer));
 
+  if (buffer == NULL)
+    return;
+
   if (num == 0)
     num = VEC_length (cp_token, buffer);
 
-  for (i = 0; VEC_iterate (cp_token, buffer, i, token) && i < num; i++)
+  if (start_token == NULL)
+    start_token = VEC_address (cp_token, buffer);
+
+  if (start_token > VEC_address (cp_token, buffer))
+    {
+      cp_lexer_print_token (file, VEC_index (cp_token, buffer, 0));
+      fprintf (file, " ... ");
+    }
+
+  do_print = false;
+  nprinted = 0;
+  for (i = 0; VEC_iterate (cp_token, buffer, i, token) && nprinted < num; i++)
     {
+      if (token == start_token)
+       do_print = true;
+
+      if (!do_print)
+       continue;
+
+      nprinted++;
+      if (token == curr_token)
+       fprintf (file, "[[");
+
       cp_lexer_print_token (file, token);
+
+      if (token == curr_token)
+       fprintf (file, "]]");
+
       switch (token->type)
        {
          case CPP_SEMICOLON:
@@ -298,9 +327,227 @@ cp_lexer_dump_tokens (FILE *file, VEC(cp_token,gc) *buffer, unsigned num)
 void
 cp_lexer_debug_tokens (VEC(cp_token,gc) *buffer)
 {
-  cp_lexer_dump_tokens (stderr, buffer, 0);
+  cp_lexer_dump_tokens (stderr, buffer, NULL, 0, NULL);
+}
+
+
+/* Dump the cp_parser tree field T to FILE if T is non-NULL.  DESC is the
+   description for T.  */
+
+static void
+cp_debug_print_tree_if_set (FILE *file, const char *desc, tree t)
+{
+  if (t)
+    {
+      fprintf (file, "%s: ", desc);
+      print_node_brief (file, "", t, 0);
+    }
+}
+
+
+/* Dump parser context C to FILE.  */
+
+static void
+cp_debug_print_context (FILE *file, cp_parser_context *c)
+{
+  const char *status_s[] = { "OK", "ERROR", "COMMITTED" };
+  fprintf (file, "{ status = %s, scope = ", status_s[c->status]);
+  print_node_brief (file, "", c->object_type, 0);
+  fprintf (file, "}\n");
+}
+
+
+/* Print the stack of parsing contexts to FILE starting with FIRST.  */
+
+static void
+cp_debug_print_context_stack (FILE *file, cp_parser_context *first)
+{
+  unsigned i;
+  cp_parser_context *c;
+
+  fprintf (file, "Parsing context stack:\n");
+  for (i = 0, c = first; c; c = c->next, i++)
+    {
+      fprintf (file, "\t#%u: ", i);
+      cp_debug_print_context (file, c);
+    }
+}
+
+
+/* Print the value of FLAG to FILE.  DESC is a string describing the flag.  */
+
+static void
+cp_debug_print_flag (FILE *file, const char *desc, bool flag)
+{
+  if (flag)
+    fprintf (file, "%s: true\n", desc);
+}
+
+
+/* Print an unparsed function entry UF to FILE.  */
+
+static void
+cp_debug_print_unparsed_function (FILE *file, cp_unparsed_functions_entry *uf)
+{
+  unsigned i;
+  cp_default_arg_entry *default_arg_fn;
+  tree fn;
+
+  fprintf (file, "\tFunctions with default args:\n");
+  for (i = 0;
+       VEC_iterate (cp_default_arg_entry, uf->funs_with_default_args, i,
+                   default_arg_fn);
+       i++)
+    {
+      fprintf (file, "\t\tClass type: ");
+      print_node_brief (file, "", default_arg_fn->class_type, 0);
+      fprintf (file, "\t\tDeclaration: ");
+      print_node_brief (file, "", default_arg_fn->decl, 0);
+      fprintf (file, "\n");
+    }
+
+  fprintf (file, "\n\tFunctions with definitions that require "
+          "post-processing\n\t\t");
+  for (i = 0; VEC_iterate (tree, uf->funs_with_definitions, i, fn); i++)
+    {
+      print_node_brief (file, "", fn, 0);
+      fprintf (file, " ");
+    }
+  fprintf (file, "\n");
+
+  fprintf (file, "\n\tNon-static data members with initializers that require "
+           "post-processing\n\t\t");
+  for (i = 0; VEC_iterate (tree, uf->nsdmis, i, fn); i++)
+    {
+      print_node_brief (file, "", fn, 0);
+      fprintf (file, " ");
+    }
+  fprintf (file, "\n");
+}
+
+
+/* Print the stack of unparsed member functions S to FILE.  */
+
+static void
+cp_debug_print_unparsed_queues (FILE *file,
+                               VEC(cp_unparsed_functions_entry, gc) *s)
+{
+  unsigned i;
+  cp_unparsed_functions_entry *uf;
+
+  fprintf (file, "Unparsed functions\n");
+  for (i = 0; VEC_iterate (cp_unparsed_functions_entry, s, i, uf); i++)
+    {
+      fprintf (file, "#%u:\n", i);
+      cp_debug_print_unparsed_function (file, uf);
+    }
+}
+
+
+/* Dump the tokens in a window of size WINDOW_SIZE around the next_token for
+   the given PARSER.  If FILE is NULL, the output is printed on stderr. */
+
+static void
+cp_debug_parser_tokens (FILE *file, cp_parser *parser, int window_size)
+{
+  cp_token *next_token, *first_token, *start_token;
+
+  if (file == NULL)
+    file = stderr;
+
+  next_token = parser->lexer->next_token;
+  first_token = VEC_address (cp_token, parser->lexer->buffer);
+  start_token = (next_token > first_token + window_size / 2)
+               ? next_token - window_size / 2
+               : first_token;
+  cp_lexer_dump_tokens (file, parser->lexer->buffer, start_token, window_size,
+                       next_token);
+}
+
+
+/* Dump debugging information for the given PARSER.  If FILE is NULL,
+   the output is printed on stderr.  */
+
+void
+cp_debug_parser (FILE *file, cp_parser *parser)
+{
+  const size_t window_size = 20;
+  cp_token *token;
+  expanded_location eloc;
+
+  if (file == NULL)
+    file = stderr;
+
+  fprintf (file, "Parser state\n\n");
+  fprintf (file, "Number of tokens: %u\n",
+          VEC_length (cp_token, parser->lexer->buffer));
+  cp_debug_print_tree_if_set (file, "Lookup scope", parser->scope);
+  cp_debug_print_tree_if_set (file, "Object scope",
+                                    parser->object_scope);
+  cp_debug_print_tree_if_set (file, "Qualifying scope",
+                                    parser->qualifying_scope);
+  cp_debug_print_context_stack (file, parser->context);
+  cp_debug_print_flag (file, "Allow GNU extensions",
+                             parser->allow_gnu_extensions_p);
+  cp_debug_print_flag (file, "'>' token is greater-than",
+                             parser->greater_than_is_operator_p);
+  cp_debug_print_flag (file, "Default args allowed in current "
+                             "parameter list", parser->default_arg_ok_p);
+  cp_debug_print_flag (file, "Parsing integral constant-expression",
+                             parser->integral_constant_expression_p);
+  cp_debug_print_flag (file, "Allow non-constant expression in current "
+                             "constant-expression",
+                             parser->allow_non_integral_constant_expression_p);
+  cp_debug_print_flag (file, "Seen non-constant expression",
+                             parser->non_integral_constant_expression_p);
+  cp_debug_print_flag (file, "Local names and 'this' forbidden in "
+                             "current context",
+                             parser->local_variables_forbidden_p);
+  cp_debug_print_flag (file, "In unbraced linkage specification",
+                             parser->in_unbraced_linkage_specification_p);
+  cp_debug_print_flag (file, "Parsing a declarator",
+                             parser->in_declarator_p);
+  cp_debug_print_flag (file, "In template argument list",
+                             parser->in_template_argument_list_p);
+  cp_debug_print_flag (file, "Parsing an iteration statement",
+                             parser->in_statement & IN_ITERATION_STMT);
+  cp_debug_print_flag (file, "Parsing a switch statement",
+                             parser->in_statement & IN_SWITCH_STMT);
+  cp_debug_print_flag (file, "Parsing a structured OpenMP block",
+                             parser->in_statement & IN_OMP_BLOCK);
+  cp_debug_print_flag (file, "Parsing a an OpenMP loop",
+                             parser->in_statement & IN_OMP_FOR);
+  cp_debug_print_flag (file, "Parsing an if statement",
+                             parser->in_statement & IN_IF_STMT);
+  cp_debug_print_flag (file, "Parsing a type-id in an expression "
+                             "context", parser->in_type_id_in_expr_p);
+  cp_debug_print_flag (file, "Declarations are implicitly extern \"C\"",
+                             parser->implicit_extern_c);
+  cp_debug_print_flag (file, "String expressions should be translated "
+                             "to execution character set",
+                             parser->translate_strings_p);
+  cp_debug_print_flag (file, "Parsing function body outside of a "
+                             "local class", parser->in_function_body);
+  cp_debug_print_flag (file, "Auto correct a colon to a scope operator",
+                             parser->colon_corrects_to_scope_p);
+  if (parser->type_definition_forbidden_message)
+    fprintf (file, "Error message for forbidden type definitions: %s\n",
+            parser->type_definition_forbidden_message);
+  cp_debug_print_unparsed_queues (file, parser->unparsed_queues);
+  fprintf (file, "Number of class definitions in progress: %u\n",
+          parser->num_classes_being_defined);
+  fprintf (file, "Number of template parameter lists for the current "
+          "declaration: %u\n", parser->num_template_parameter_lists);
+  cp_debug_parser_tokens (file, parser, window_size);
+  token = parser->lexer->next_token;
+  fprintf (file, "Next token to parse:\n");
+  fprintf (file, "\tToken:  ");
+  cp_lexer_print_token (file, token);
+  eloc = expand_location (token->location);
+  fprintf (file, "\n\tFile:   %s\n", eloc.file);
+  fprintf (file, "\tLine:   %d\n", eloc.line);
+  fprintf (file, "\tColumn: %d\n", eloc.column);
 }
-#endif
 
 
 /* Allocate memory for a new lexer object and return it.  */
@@ -315,10 +562,9 @@ cp_lexer_alloc (void)
   /* Allocate the memory.  */
   lexer = ggc_alloc_cleared_cp_lexer ();
 
-#ifdef ENABLE_CHECKING
   /* Initially we are not debugging.  */
   lexer->debugging_p = false;
-#endif /* ENABLE_CHECKING */
+
   lexer->saved_tokens = VEC_alloc (cp_token_position, heap,
                                   CP_SAVED_TOKEN_STACK);
 
@@ -388,10 +634,8 @@ cp_lexer_new_from_tokens (cp_token_cache *cache)
   lexer->saved_tokens = VEC_alloc (cp_token_position, heap,
                                   CP_SAVED_TOKEN_STACK);
 
-#ifdef ENABLE_CHECKING
   /* Initially we are not debugging.  */
   lexer->debugging_p = false;
-#endif
 
   gcc_assert (!lexer->next_token->purged_p);
   return lexer;
@@ -409,15 +653,12 @@ cp_lexer_destroy (cp_lexer *lexer)
 
 /* Returns nonzero if debugging information should be output.  */
 
-#ifdef ENABLE_CHECKING
-
 static inline bool
 cp_lexer_debugging_p (cp_lexer *lexer)
 {
   return lexer->debugging_p;
 }
 
-#endif /* ENABLE_CHECKING */
 
 static inline cp_token_position
 cp_lexer_token_position (cp_lexer *lexer, bool previous_p)
@@ -508,7 +749,7 @@ cp_lexer_get_preprocessor_token (cp_lexer *lexer, cp_token *token)
               /* Warn about the C++0x keyword (but still treat it as
                  an identifier).  */
               warning (OPT_Wc__0x_compat, 
-                       "identifier %qE will become a keyword in C++0x",
+                       "identifier %qE is a keyword in C++11",
                        token->u.value);
 
               /* Clear out the C_RID_CODE so we don't warn about this
@@ -852,8 +1093,6 @@ cp_lexer_rollback_tokens (cp_lexer* lexer)
 
 /* Print a representation of the TOKEN on the STREAM.  */
 
-#ifdef ENABLE_CHECKING
-
 static void
 cp_lexer_print_token (FILE * stream, cp_token *token)
 {
@@ -914,6 +1153,7 @@ static void
 cp_lexer_start_debugging (cp_lexer* lexer)
 {
   lexer->debugging_p = true;
+  cp_lexer_debug_stream = stderr;
 }
 
 /* Stop emitting debugging information.  */
@@ -922,10 +1162,9 @@ static void
 cp_lexer_stop_debugging (cp_lexer* lexer)
 {
   lexer->debugging_p = false;
+  cp_lexer_debug_stream = NULL;
 }
 
-#endif /* ENABLE_CHECKING */
-
 /* Create a new cp_token_cache, representing a range of tokens.  */
 
 static cp_token_cache *
@@ -1486,6 +1725,8 @@ cp_parser_context_new (cp_parser_context* next)
   VEC_last (cp_unparsed_functions_entry, parser->unparsed_queues)->funs_with_default_args
 #define unparsed_funs_with_definitions \
   VEC_last (cp_unparsed_functions_entry, parser->unparsed_queues)->funs_with_definitions
+#define unparsed_nsdmis \
+  VEC_last (cp_unparsed_functions_entry, parser->unparsed_queues)->nsdmis
 
 static void
 push_unparsed_function_queues (cp_parser *parser)
@@ -1494,6 +1735,7 @@ push_unparsed_function_queues (cp_parser *parser)
                 parser->unparsed_queues, NULL);
   unparsed_funs_with_default_args = NULL;
   unparsed_funs_with_definitions = make_tree_vector ();
+  unparsed_nsdmis = NULL;
 }
 
 static void
@@ -1528,6 +1770,12 @@ static tree cp_parser_identifier
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -1692,6 +1940,8 @@ static bool cp_parser_using_declaration
   (cp_parser *, bool);
 static void cp_parser_using_directive
   (cp_parser *);
+static tree cp_parser_alias_declaration
+  (cp_parser *);
 static void cp_parser_asm_definition
   (cp_parser *);
 static void cp_parser_linkage_specification
@@ -1757,7 +2007,7 @@ static tree cp_parser_class_name
 static tree cp_parser_class_specifier
   (cp_parser *);
 static tree cp_parser_class_head
-  (cp_parser *, bool *, tree *, tree *);
+  (cp_parser *, bool *);
 static enum tag_types cp_parser_class_key
   (cp_parser *);
 static void cp_parser_member_specification_opt
@@ -1861,6 +2111,17 @@ static bool cp_parser_extension_opt
 static void cp_parser_label_declaration
   (cp_parser *);
 
+/* Transactional Memory Extensions */
+
+static tree cp_parser_transaction
+  (cp_parser *, enum rid);
+static tree cp_parser_transaction_expression
+  (cp_parser *, enum rid);
+static bool cp_parser_function_transaction
+  (cp_parser *, enum rid);
+static tree cp_parser_transaction_cancel
+  (cp_parser *);
+
 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
 static bool cp_parser_pragma
   (cp_parser *, enum pragma_context);
@@ -1936,12 +2197,18 @@ static tree cp_parser_functional_cast
   (cp_parser *, tree);
 static tree cp_parser_save_member_function_body
   (cp_parser *, cp_decl_specifier_seq *, cp_declarator *, tree);
+static tree cp_parser_save_nsdmi
+  (cp_parser *);
 static tree cp_parser_enclosed_template_argument_list
   (cp_parser *);
 static void cp_parser_save_default_args
   (cp_parser *, tree);
 static void cp_parser_late_parsing_for_member
   (cp_parser *, tree);
+static tree cp_parser_late_parse_one_default_arg
+  (cp_parser *, tree, tree, tree);
+static void cp_parser_late_parsing_nsdmi
+  (cp_parser *, tree);
 static void cp_parser_late_parsing_default_args
   (cp_parser *, tree);
 static tree cp_parser_sizeof_operand
@@ -1982,6 +2249,8 @@ static void cp_parser_pre_parsed_nested_name_specifier
   (cp_parser *);
 static bool cp_parser_cache_group
   (cp_parser *, enum cpp_ttype, unsigned);
+static tree cp_parser_cache_defarg
+  (cp_parser *parser, bool nsdmi);
 static void cp_parser_parse_tentatively
   (cp_parser *);
 static void cp_parser_commit_to_tentative_parse
@@ -2030,6 +2299,8 @@ static bool cp_parser_error_occurred
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2050,7 +2321,7 @@ cp_parser_parsing_tentatively (cp_parser* parser)
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
          token->type == CPP_STRING16 ||
@@ -2059,6 +2330,20 @@ cp_parser_is_string_literal (cp_token* token)
          token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+         token->type == CPP_STRING_USERDEF ||
+         token->type == CPP_STRING16_USERDEF ||
+         token->type == CPP_STRING32_USERDEF ||
+         token->type == CPP_WSTRING_USERDEF ||
+         token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -2244,6 +2529,7 @@ cp_parser_check_decl_spec (cp_decl_specifier_seq *decl_specs,
            "explicit",
            "friend",
            "typedef",
+           "using",
             "constexpr",
            "__complex",
            "__thread"
@@ -2403,6 +2689,10 @@ cp_parser_non_integral_constant_expression (cp_parser  *parser,
                error ("a call to a constructor "
                       "cannot appear in a constant-expression");
                return true;
+             case NIC_TRANSACTION:
+               error ("a transaction expression "
+                      "cannot appear in a constant-expression");
+               return true;
              case NIC_THIS:
                msg = "this";
                break;
@@ -2494,8 +2784,8 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser,
 
         The user should have said "typename A<T>::X".  */
       if (cxx_dialect < cxx0x && id == ridpointers[(int)RID_CONSTEXPR])
-       inform (location, "C++0x %<constexpr%> only available with "
-               "-std=c++0x or -std=gnu++0x");
+       inform (location, "C++11 %<constexpr%> only available with "
+               "-std=c++11 or -std=gnu++11");
       else if (processing_template_decl && current_class_type
               && TYPE_BINFO (current_class_type))
        {
@@ -3098,7 +3388,11 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3107,7 +3401,18 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3116,10 +3421,19 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+       {
+         suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+         have_suffix_p = 1;
+         curr_type = cpp_userdef_string_remove_type (tok->type);
+       }
+      else
+       curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3131,14 +3445,35 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
        {
          cp_lexer_consume_token (parser->lexer);
          count++;
-         str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-         str.len = TREE_STRING_LENGTH (tok->u.value);
+         str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+         str.len = TREE_STRING_LENGTH (string_tree);
+
+         if (curr_tok_is_userdef_p)
+           {
+             tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+             if (have_suffix_p == 0)
+               {
+                 suffix_id = curr_suffix_id;
+                 have_suffix_p = 1;
+               }
+             else if (have_suffix_p == 1
+                      && curr_suffix_id != suffix_id)
+               {
+                 error ("inconsistent user-defined literal suffixes"
+                        " %qD and %qD in string literal",
+                        suffix_id, curr_suffix_id);
+                 have_suffix_p = -1;
+               }
+             curr_type = cpp_userdef_string_remove_type (tok->type);
+           }
+         else
+           curr_type = tok->type;
 
-         if (type != tok->type)
+         if (type != curr_type)
            {
              if (type == CPP_STRING)
-               type = tok->type;
-             else if (tok->type != CPP_STRING)
+               type = curr_type;
+             else if (curr_type != CPP_STRING)
                error_at (tok->location,
                          "unsupported non-standard concatenation "
                          "of string literals");
@@ -3147,6 +3482,18 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
          obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
          tok = cp_lexer_peek_token (parser->lexer);
+         if (cpp_userdef_string_p (tok->type))
+           {
+             string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+             curr_type = cpp_userdef_string_remove_type (tok->type);
+             curr_tok_is_userdef_p = true;
+           }
+         else
+           {
+             string_tree = tok->u.value;
+             curr_type = tok->type;
+             curr_tok_is_userdef_p = false;
+           }
        }
       while (cp_parser_is_string_literal (tok));
 
@@ -3184,6 +3531,13 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
        }
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+       {
+         tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+         tok->u.value = literal;
+         return cp_parser_userdef_string_literal (tok);
+       }
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3195,6 +3549,220 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
   return value;
 }
 
+/* Look up a literal operator with the name and the exact arguments.  */
+
+static tree
+lookup_literal_operator (tree name, VEC(tree,gc) *args)
+{
+  tree decl, fns;
+  decl = lookup_name (name);
+  if (!decl || !is_overloaded_fn (decl))
+    return error_mark_node;
+
+  for (fns = decl; fns; fns = OVL_NEXT (fns))
+    {
+      unsigned int ix;
+      bool found = true;
+      tree fn = OVL_CURRENT (fns);
+      tree argtypes = NULL_TREE;
+      argtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
+      if (argtypes != NULL_TREE)
+       {
+         for (ix = 0; ix < VEC_length (tree, args) && argtypes != NULL_TREE;
+              ++ix, argtypes = TREE_CHAIN (argtypes))
+           {
+             tree targ = TREE_VALUE (argtypes);
+             tree tparm = TREE_TYPE (VEC_index (tree, args, ix));
+             bool ptr = TREE_CODE (targ) == POINTER_TYPE;
+             bool arr = TREE_CODE (tparm) == ARRAY_TYPE;
+             if ((ptr || arr || !same_type_p (targ, tparm))
+                 && (!ptr || !arr
+                     || !same_type_p (TREE_TYPE (targ),
+                                      TREE_TYPE (tparm))))
+               found = false;
+           }
+         if (found
+             && ix == VEC_length (tree, args)
+             /* May be this should be sufficient_parms_p instead,
+                depending on how exactly should user-defined literals
+                work in presence of default arguments on the literal
+                operator parameters.  */
+             && argtypes == void_list_node)
+           return fn;
+       }
+    }
+
+  return error_mark_node;
+}
+
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
+
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = cp_lexer_consume_token (parser->lexer);
+  tree literal = token->u.value;
+  tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  tree value = USERDEF_LITERAL_VALUE (literal);
+  tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  tree decl, result;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  VEC(tree,gc) *args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_literal_operator (name, args);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find character literal operator %qD with %qT argument",
+            name, TREE_TYPE (value));
+      release_tree_vector (args);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &args, false, true, tf_warning_or_error);
+  release_tree_vector (args);
+  if (result != error_mark_node)
+    return result;
+
+  error ("unable to find character literal operator %qD with %qT argument",
+        name, TREE_TYPE (value));
+  return error_mark_node;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree charvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value) - 1;
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in CHARVEC with all of the parameters.  */
+  charvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (charvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, charvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = cp_lexer_consume_token (parser->lexer);
+  tree literal = token->u.value;
+  tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  tree value = USERDEF_LITERAL_VALUE (literal);
+  tree num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  tree decl, result;
+  VEC(tree,gc) *args;
+
+  /* Look for a literal operator taking the exact type of numeric argument
+     as the literal value.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_literal_operator (name, args);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+       {
+         release_tree_vector (args);
+         return result;
+       }
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_literal_operator (name, args);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+       {
+         release_tree_vector (args);
+         return result;
+       }
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_literal_operator (name, args);
+  if (decl && decl != error_mark_node)
+    {
+      tree tmpl_args = make_char_string_pack (num_string);
+      decl = lookup_template_function (decl, tmpl_args);
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+       {
+         release_tree_vector (args);
+         return result;
+       }
+    }
+  release_tree_vector (args);
+
+  error ("unable to find numeric literal operator %qD", name);
+  return error_mark_node;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal = token->u.value;
+  tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  tree value = USERDEF_LITERAL_VALUE (literal);
+  int len = TREE_STRING_LENGTH (value)
+       / TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (value)))) - 1;
+  tree decl, result;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  VEC(tree,gc) *args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  VEC_safe_push (tree, gc, args, build_int_cst (size_type_node, len));
+  decl = lookup_name (name);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find string literal operator %qD", name);
+      release_tree_vector (args);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &args, false, true, tf_none);
+  release_tree_vector (args);
+  if (result != error_mark_node)
+    return result;
+
+  error ("unable to find string literal operator %qD with %qT, %qT arguments",
+        name, TREE_TYPE (value), size_type_node);
+  return error_mark_node;
+}
+
 
 /* Basic concepts [gram.basic]  */
 
@@ -3294,6 +3862,7 @@ cp_parser_translation_unit (cp_parser* parser)
      __is_convertible_to ( type-id , type-id )     
      __is_empty ( type-id )
      __is_enum ( type-id )
+     __is_final ( type-id )
      __is_literal_type ( type-id )
      __is_pod ( type-id )
      __is_polymorphic ( type-id )
@@ -3338,12 +3907,16 @@ cp_parser_primary_expression (cp_parser *parser,
           character-literal
           floating-literal
           string-literal
-          boolean-literal  */
+          boolean-literal
+          pointer-literal
+          user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+       return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
        {
@@ -3397,11 +3970,22 @@ cp_parser_primary_expression (cp_parser *parser,
        }
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
         is false (i.e. in attributes)?  If not, we can kill the third
         argument to cp_parser_string_literal.  */
@@ -3624,6 +4208,7 @@ cp_parser_primary_expression (cp_parser *parser,
        case RID_IS_CONVERTIBLE_TO:
        case RID_IS_EMPTY:
        case RID_IS_ENUM:
+       case RID_IS_FINAL:
        case RID_IS_LITERAL_TYPE:
        case RID_IS_POD:
        case RID_IS_POLYMORPHIC:
@@ -4237,6 +4822,14 @@ cp_parser_unqualified_id (cp_parser* parser,
          /* If that didn't work, try a conversion-function-id.  */
          if (!cp_parser_parse_definitely (parser))
            id = cp_parser_conversion_function_id (parser);
+         else if (UDLIT_OPER_P (id))
+           {
+             /* 17.6.3.3.5  */
+             const char *name = UDLIT_OP_SUFFIX (id);
+             if (name[0] != '_' && !in_system_header)
+               warning (0, "literal operator suffixes not preceded by %<_%>"
+                           " are reserved for future standardization");
+           }
 
          return id;
        }
@@ -4512,8 +5105,8 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
               && (TREE_CODE (TYPENAME_TYPE_FULLNAME (new_scope))
                   == TEMPLATE_ID_EXPR)))
        permerror (input_location, TYPE_P (new_scope)
-                  ? "%qT is not a template"
-                  : "%qD is not a template",
+                  ? G_("%qT is not a template")
+                  : G_("%qD is not a template"),
                   new_scope);
       /* If it is a class scope, try to complete it; we are about to
         be looking up names inside the class.  */
@@ -4602,7 +5195,7 @@ cp_parser_nested_name_specifier (cp_parser *parser,
    this is either a class-name or a namespace-name (which corresponds
    to the class-or-namespace-name production in the grammar). For
    C++0x, it can also be a type-name that refers to an enumeration
-   type.
+   type or a simple-template-id.
 
    TYPENAME_KEYWORD_P is TRUE iff the `typename' keyword is in effect.
    TEMPLATE_KEYWORD_P is TRUE iff the `template' keyword is in effect.
@@ -4678,8 +5271,8 @@ cp_parser_qualifying_entity (cp_parser *parser,
       /* Parse tentatively.  */
       cp_parser_parse_tentatively (parser);
      
-      /* Parse a typedef-name or enum-name.  */
-      scope = cp_parser_nonclass_name (parser);
+      /* Parse a type-name  */
+      scope = cp_parser_type_name (parser);
 
       /* "If the name found does not designate a namespace or a class,
         enumeration, or dependent type, the program is ill-formed."
@@ -4879,7 +5472,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
        /* Restore the saved message.  */
        parser->type_definition_forbidden_message = saved_message;
        /* `typeid' may not appear in an integral constant expression.  */
-       if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+       if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
          return error_mark_node;
       }
       break;
@@ -5244,6 +5837,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
    by cp_parser_builtin_offsetof.  We're looking for
 
      postfix-expression [ expression ]
+     postfix-expression [ braced-init-list ] (C++11)
 
    FOR_OFFSETOF is set if we're being called in that context, which
    changes how we deal with integer constant expressions.  */
@@ -5269,7 +5863,16 @@ cp_parser_postfix_open_square_expression (cp_parser *parser,
   if (for_offsetof)
     index = cp_parser_constant_expression (parser, false, NULL);
   else
-    index = cp_parser_expression (parser, /*cast_p=*/false, NULL);
+    {
+      if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
+       {
+         bool expr_nonconst_p;
+         maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
+         index = cp_parser_braced_list (parser, &expr_nonconst_p);
+       }
+      else
+       index = cp_parser_expression (parser, /*cast_p=*/false, NULL);
+    }
 
   /* Look for the closing `]'.  */
   cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
@@ -5433,17 +6036,24 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser,
        {
          if (name != error_mark_node && !BASELINK_P (name) && parser->scope)
            {
-             name = build_qualified_name (/*type=*/NULL_TREE,
-                                          parser->scope,
-                                          name,
-                                          template_p);
+             if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
+               {
+                 error_at (token->location, "%<%D::%D%> is not a class member",
+                           parser->scope, name);
+                 postfix_expression = error_mark_node;
+               }
+             else
+               name = build_qualified_name (/*type=*/NULL_TREE,
+                                            parser->scope,
+                                            name,
+                                            template_p);
              parser->scope = NULL_TREE;
              parser->qualifying_scope = NULL_TREE;
              parser->object_scope = NULL_TREE;
            }
-         if (scope && name && BASELINK_P (name))
+         if (parser->scope && name && BASELINK_P (name))
            adjust_result_of_qualified_name_lookup
-             (name, BINFO_TYPE (BASELINK_ACCESS_BINFO (name)), scope);
+             (name, parser->scope, scope);
          postfix_expression
            = finish_class_member_access_expr (postfix_expression, name,
                                               template_p, 
@@ -5707,10 +6317,6 @@ cp_parser_pseudo_destructor_name (cp_parser* parser,
   /* Look for the `~'.  */
   cp_parser_require (parser, CPP_COMPL, RT_COMPL);
 
-  /* Once we see the ~, this has to be a pseudo-destructor.  */
-  if (!processing_template_decl && !cp_parser_error_occurred (parser))
-    cp_parser_commit_to_tentative_parse (parser);
-
   /* Look for the type-name again.  We are not responsible for
      checking that it matches the first type-name.  */
   *type = cp_parser_nonclass_name (parser);
@@ -5829,6 +6435,10 @@ cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p,
          }
          break;
 
+       case RID_TRANSACTION_ATOMIC:
+       case RID_TRANSACTION_RELAXED:
+         return cp_parser_transaction_expression (parser, keyword);
+
        case RID_NOEXCEPT:
          {
            tree expr;
@@ -6060,10 +6670,17 @@ cp_parser_new_expression (cp_parser* parser)
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
     {
       cp_token *token;
+      const char *saved_message = parser->type_definition_forbidden_message;
+
       /* Consume the `('.  */
       cp_lexer_consume_token (parser->lexer);
+
       /* Parse the type-id.  */
+      parser->type_definition_forbidden_message
+       = G_("types may not be defined in a new-expression");
       type = cp_parser_type_id (parser);
+      parser->type_definition_forbidden_message = saved_message;
+
       /* Look for the closing `)'.  */
       cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
       token = cp_lexer_peek_token (parser->lexer);
@@ -6389,8 +7006,9 @@ cp_parser_delete_expression (cp_parser* parser)
    otherwise.  */
 
 static bool
-cp_parser_token_starts_cast_expression (cp_token *token)
+cp_parser_tokens_start_cast_expression (cp_parser *parser)
 {
+  cp_token *token = cp_lexer_peek_token (parser->lexer);
   switch (token->type)
     {
     case CPP_COMMA:
@@ -6431,6 +7049,12 @@ cp_parser_token_starts_cast_expression (cp_token *token)
     case CPP_EOF:
       return false;
 
+    case CPP_OPEN_PAREN:
+      /* In ((type ()) () the last () isn't a valid cast-expression,
+        so the whole must be parsed as postfix-expression.  */
+      return cp_lexer_peek_nth_token (parser->lexer, 2)->type
+            != CPP_CLOSE_PAREN;
+
       /* '[' may start a primary-expression in obj-c++.  */
     case CPP_OPEN_SQUARE:
       return c_dialect_objc ();
@@ -6523,8 +7147,7 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p,
         parenthesized ctor such as `(T ())' that looks like a cast to
         function returning T.  */
       if (!cp_parser_error_occurred (parser)
-         && cp_parser_token_starts_cast_expression (cp_lexer_peek_token
-                                                    (parser->lexer)))
+         && cp_parser_tokens_start_cast_expression (parser))
        {
          cp_parser_parse_definitely (parser);
          expr = cp_parser_cast_expression (parser,
@@ -6655,6 +7278,9 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
   lhs = cp_parser_cast_expression (parser, /*address_p=*/false, cast_p, pidk);
   lhs_type = ERROR_MARK;
 
+  if (cp_parser_error_occurred (parser))
+    return error_mark_node;
+
   for (;;)
     {
       /* Get an operator token.  */
@@ -6665,8 +7291,8 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
           && !parser->greater_than_is_operator_p)
         {
           if (warning_at (token->location, OPT_Wc__0x_compat, 
-                         "%<>>%> operator will be treated as"
-                         " two right angle brackets in C++0x"))
+                         "%<>>%> operator is treated as"
+                         " two right angle brackets in C++11"))
            inform (token->location,
                    "suggest parentheses around %<>>%> expression");
         }
@@ -7274,6 +7900,9 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword)
     case RID_IS_ENUM:
       kind = CPTK_IS_ENUM;
       break;
+    case RID_IS_FINAL:
+      kind = CPTK_IS_FINAL;
+      break;
     case RID_IS_LITERAL_TYPE:
       kind = CPTK_IS_LITERAL_TYPE;
       break;
@@ -7295,6 +7924,12 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword)
     case RID_UNDERLYING_TYPE:
       kind = CPTK_UNDERLYING_TYPE;
       break;
+    case RID_BASES:
+      kind = CPTK_BASES;
+      break;
+    case RID_DIRECT_BASES:
+      kind = CPTK_DIRECT_BASES;
+      break;
     default:
       gcc_unreachable ();
     }
@@ -7339,9 +7974,17 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword)
 
   /* Complete the trait expression, which may mean either processing
      the trait expr now or saving it for template instantiation.  */
-  return kind != CPTK_UNDERLYING_TYPE
-    ? finish_trait_expr (kind, type1, type2)
-    : finish_underlying_type (type1);
+  switch(kind)
+    {
+    case CPTK_UNDERLYING_TYPE:
+      return finish_underlying_type (type1);
+    case CPTK_BASES:
+      return finish_bases (type1, false);
+    case CPTK_DIRECT_BASES:
+      return finish_bases (type1, true);
+    default:
+      return finish_trait_expr (kind, type1, type2);
+    }
 }
 
 /* Lambdas that appear in variable initializer or default argument scope
@@ -7425,7 +8068,9 @@ cp_parser_lambda_expression (cp_parser* parser)
   cp_parser_lambda_introducer (parser, lambda_expr);
 
   type = begin_lambda_type (lambda_expr);
-
+  if (type == error_mark_node)
+    return error_mark_node;
+
   record_lambda_scope (lambda_expr);
 
   /* Do this again now that LAMBDA_EXPR_EXTRA_SCOPE is set.  */
@@ -7621,6 +8266,31 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
                  /*ambiguous_decls=*/NULL,
                  capture_token->location);
 
+         if (capture_init_expr == error_mark_node)
+           {
+             unqualified_name_lookup_error (capture_id);
+             continue;
+           }
+         else if (DECL_P (capture_init_expr)
+                  && (TREE_CODE (capture_init_expr) != VAR_DECL
+                      && TREE_CODE (capture_init_expr) != PARM_DECL))
+           {
+             error_at (capture_token->location,
+                       "capture of non-variable %qD ",
+                       capture_init_expr);
+             inform (0, "%q+#D declared here", capture_init_expr);
+             continue;
+           }
+         if (TREE_CODE (capture_init_expr) == VAR_DECL
+             && decl_storage_duration (capture_init_expr) != dk_auto)
+           {
+             pedwarn (capture_token->location, 0, "capture of variable "
+                      "%qD with non-automatic storage duration",
+                      capture_init_expr);
+             inform (0, "%q+#D declared here", capture_init_expr);
+             continue;
+           }
+
          capture_init_expr
             = finish_id_expression
                 (capture_id,
@@ -7638,10 +8308,6 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
                  capture_token->location);
        }
 
-      if (TREE_CODE (capture_init_expr) == IDENTIFIER_NODE)
-       capture_init_expr
-         = unqualified_name_lookup_error (capture_init_expr);
-
       if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) != CPLD_NONE
          && !explicit_init_p)
        {
@@ -7928,6 +8594,11 @@ cp_parser_lambda_body (cp_parser* parser, tree lambda_expr)
      declaration-statement
      try-block
 
+  TM Extension:
+
+   statement:
+     atomic-statement
+
   IN_COMPOUND is true when the statement is nested inside a
   cp_parser_compound_statement; this matters for certain pragmas.
 
@@ -8004,6 +8675,14 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
          cp_parser_declaration_statement (parser);
          return;
          
+       case RID_TRANSACTION_ATOMIC:
+       case RID_TRANSACTION_RELAXED:
+         statement = cp_parser_transaction (parser, keyword);
+         break;
+       case RID_TRANSACTION_CANCEL:
+         statement = cp_parser_transaction_cancel (parser);
+         break;
+
        default:
          /* It might be a keyword like `int' that can start a
             declaration-statement.  */
@@ -8677,9 +9356,17 @@ cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl)
      at instantiation. If not, it is done just ahead. */
   if (processing_template_decl)
     {
+      if (check_for_bare_parameter_packs (range_expr))
+       range_expr = error_mark_node;
       stmt = begin_range_for_stmt (scope, init);
       finish_range_for_decl (stmt, range_decl, range_expr);
-      do_range_for_auto_deduction (range_decl, range_expr);
+      if (range_expr != error_mark_node
+         && !type_dependent_expression_p (range_expr)
+         /* The length of an array might be dependent.  */
+         && COMPLETE_TYPE_P (TREE_TYPE (range_expr))
+         /* do_auto_deduction doesn't mess with template init-lists.  */
+         && !BRACE_ENCLOSED_INITIALIZER_P (range_expr))
+       do_range_for_auto_deduction (range_decl, range_expr);
     }
   else
     {
@@ -8877,9 +9564,11 @@ cp_parser_perform_range_for_lookup (tree range, tree *begin, tree *end)
       id_begin = get_identifier ("begin");
       id_end = get_identifier ("end");
       member_begin = lookup_member (TREE_TYPE (range), id_begin,
-                                   /*protect=*/2, /*want_type=*/false);
+                                   /*protect=*/2, /*want_type=*/false,
+                                   tf_warning_or_error);
       member_end = lookup_member (TREE_TYPE (range), id_end,
-                                 /*protect=*/2, /*want_type=*/false);
+                                 /*protect=*/2, /*want_type=*/false,
+                                 tf_warning_or_error);
 
       if (member_begin != NULL_TREE || member_end != NULL_TREE)
        {
@@ -9461,7 +10150,7 @@ cp_parser_declaration (cp_parser* parser)
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -9579,8 +10268,8 @@ cp_parser_block_declaration (cp_parser *parser,
      namespace-alias-definition.  */
   else if (token1->keyword == RID_NAMESPACE)
     cp_parser_namespace_alias_definition (parser);
-  /* If the next keyword is `using', we have either a
-     using-declaration or a using-directive.  */
+  /* If the next keyword is `using', we have a
+     using-declaration, a using-directive, or an alias-declaration.  */
   else if (token1->keyword == RID_USING)
     {
       cp_token *token2;
@@ -9592,6 +10281,14 @@ cp_parser_block_declaration (cp_parser *parser,
       token2 = cp_lexer_peek_nth_token (parser->lexer, 2);
       if (token2->keyword == RID_NAMESPACE)
        cp_parser_using_directive (parser);
+      /* If the second token after 'using' is '=', then we have an
+        alias-declaration.  */
+      else if (cxx_dialect >= cxx0x
+              && token2->type == CPP_NAME
+              && ((cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_EQ)
+                  || (cp_lexer_peek_nth_token (parser->lexer, 3)->keyword
+                      == RID_ATTRIBUTE)))
+       cp_parser_alias_declaration (parser);
       /* Otherwise, it's a using-declaration.  */
       else
        cp_parser_using_declaration (parser,
@@ -9957,7 +10654,7 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
               /* Complain about `auto' as a storage specifier, if
                  we're complaining about C++0x compatibility.  */
               warning_at (token->location, OPT_Wc__0x_compat, "%<auto%>"
-                         " will change meaning in C++0x; please remove it");
+                         " changes meaning in C++11; please remove it");
 
               /* Set the storage class anyway.  */
               cp_parser_set_storage_class (parser, decl_specs, RID_AUTO,
@@ -10664,6 +11361,7 @@ static void
 cp_parser_mem_initializer_list (cp_parser* parser)
 {
   tree mem_initializer_list = NULL_TREE;
+  tree target_ctor = error_mark_node;
   cp_token *token = cp_lexer_peek_token (parser->lexer);
 
   /* Let the semantic analysis code know that we are starting the
@@ -10701,6 +11399,27 @@ cp_parser_mem_initializer_list (cp_parser* parser)
           if (mem_initializer != error_mark_node)
             mem_initializer = make_pack_expansion (mem_initializer);
         }
+      if (target_ctor != error_mark_node
+         && mem_initializer != error_mark_node)
+       {
+         error ("mem-initializer for %qD follows constructor delegation",
+                TREE_PURPOSE (mem_initializer));
+         mem_initializer = error_mark_node;
+       }
+      /* Look for a target constructor. */
+      if (mem_initializer != error_mark_node
+         && TYPE_P (TREE_PURPOSE (mem_initializer))
+         && same_type_p (TREE_PURPOSE (mem_initializer), current_class_type))
+       {
+         maybe_warn_cpp0x (CPP0X_DELEGATING_CTORS);
+         if (mem_initializer_list)
+           {
+             error ("constructor delegation follows mem-initializer for %qD",
+                    TREE_PURPOSE (mem_initializer_list));
+             mem_initializer = error_mark_node;
+           }
+         target_ctor = mem_initializer;
+       }
       /* Add it to the list, unless it was erroneous.  */
       if (mem_initializer != error_mark_node)
        {
@@ -10892,6 +11611,22 @@ cp_parser_operator_function_id (cp_parser* parser)
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+                             + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11111,6 +11846,37 @@ cp_parser_operator (cp_parser* parser)
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+       maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+       {
+         error ("expected empty string after %<operator%> keyword");
+         return error_mark_node;
+       }
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for the suffix identifier.  */
+      token = cp_lexer_peek_token (parser->lexer);
+      if (token->type == CPP_NAME)
+       {
+         id = cp_parser_identifier (parser);
+         if (id != error_mark_node)
+           {
+             const char *name = IDENTIFIER_POINTER (id);
+             return cp_literal_operator_id (name);
+           }
+       }
+      else
+       {
+         error ("expected suffix identifier");
+         return error_mark_node;
+       }
+
+    case CPP_STRING_USERDEF:
+      error ("missing space between %<\"\"%> and suffix identifier");
+      return error_mark_node;
+
     default:
       /* Anything else is an error.  */
       break;
@@ -11206,8 +11972,7 @@ cp_parser_template_parameter_list (cp_parser* parser)
                                                parm_loc,
                                                parameter,
                                                is_non_type,
-                                               is_parameter_pack,
-                                               0);
+                                               is_parameter_pack);
       else
        {
          tree err_parm = build_tree_list (parameter, parameter);
@@ -11342,9 +12107,7 @@ cp_parser_template_parameter (cp_parser* parser, bool *is_non_type,
         user may try to do so, so we'll parse them and give an
         appropriate diagnostic here.  */
 
-      /* Consume the `='.  */
       cp_token *start_token = cp_lexer_peek_token (parser->lexer);
-      cp_lexer_consume_token (parser->lexer);
       
       /* Find the name of the parameter pack.  */     
       id_declarator = parameter_declarator->declarator;
@@ -11727,7 +12490,7 @@ cp_parser_template_id (cp_parser *parser,
   /* Build a representation of the specialization.  */
   if (TREE_CODE (templ) == IDENTIFIER_NODE)
     template_id = build_min_nt (TEMPLATE_ID_EXPR, templ, arguments);
-  else if (DECL_CLASS_TEMPLATE_P (templ)
+  else if (DECL_TYPE_TEMPLATE_P (templ)
           || DECL_TEMPLATE_TEMPLATE_PARM_P (templ))
     {
       bool entering_scope;
@@ -11972,7 +12735,7 @@ cp_parser_template_name (cp_parser* parser,
      its name; we will look it up again during template instantiation.  */
   if (DECL_FUNCTION_TEMPLATE_P (decl) || !DECL_P (decl))
     {
-      tree scope = CP_DECL_CONTEXT (get_first_fn (decl));
+      tree scope = ovl_scope (decl);
       if (TYPE_P (scope) && dependent_type_p (scope))
        return identifier;
     }
@@ -12009,6 +12772,7 @@ cp_parser_template_argument_list (cp_parser* parser)
   parser->integral_constant_expression_p = false;
   saved_non_ice_p = parser->non_integral_constant_expression_p;
   parser->non_integral_constant_expression_p = false;
+
   /* Parse the arguments.  */
   do
     {
@@ -12576,7 +13340,7 @@ cp_parser_type_specifier (cp_parser* parser,
            cp_parser_set_decl_spec_type (decl_specs,
                                          type_spec,
                                          token->location,
-                                         /*user_defined_p=*/true);
+                                         /*type_definition_p=*/true);
          return type_spec;
        }
       else
@@ -12605,7 +13369,7 @@ cp_parser_type_specifier (cp_parser* parser,
            cp_parser_set_decl_spec_type (decl_specs,
                                          type_spec,
                                          token->location,
-                                         /*user_defined_p=*/true);
+                                         /*type_definition_p=*/true);
          return type_spec;
        }
 
@@ -12627,7 +13391,7 @@ cp_parser_type_specifier (cp_parser* parser,
        cp_parser_set_decl_spec_type (decl_specs,
                                      type_spec,
                                      token->location,
-                                     /*user_defined_p=*/true);
+                                     /*type_definition_p=*/false);
       return type_spec;
 
     case RID_CONST:
@@ -12820,20 +13584,27 @@ cp_parser_simple_type_specifier (cp_parser* parser,
       if (decl_specs)
        cp_parser_set_decl_spec_type (decl_specs, type,
                                      token->location,
-                                     /*user_defined_p=*/true);
+                                     /*type_definition_p=*/false);
 
       return type;
 
     case RID_UNDERLYING_TYPE:
       type = cp_parser_trait_expr (parser, RID_UNDERLYING_TYPE);
-
       if (decl_specs)
        cp_parser_set_decl_spec_type (decl_specs, type,
                                      token->location,
-                                     /*user_defined_p=*/true);
+                                     /*type_definition_p=*/false);
 
       return type;
 
+    case RID_BASES:
+    case RID_DIRECT_BASES:
+      type = cp_parser_trait_expr (parser, token->keyword);
+      if (decl_specs)
+       cp_parser_set_decl_spec_type (decl_specs, type,
+                                     token->location,
+                                     /*type_definition_p=*/false);
+      return type;
     default:
       break;
     }
@@ -12847,7 +13618,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
       if (decl_specs)
        cp_parser_set_decl_spec_type (decl_specs, type,
                                      token->location,
-                                     /*user_defined_p=*/true);
+                                     /*type_definition_p=*/false);
       cp_lexer_consume_token (parser->lexer);
       return type;
     }
@@ -12864,7 +13635,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
        cp_parser_set_decl_spec_type (decl_specs,
                                      type,
                                      token->location,
-                                     /*user_defined=*/false);
+                                     /*type_definition_p=*/false);
       if (decl_specs)
        decl_specs->any_specifiers_p = true;
 
@@ -12939,7 +13710,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
       if (type && decl_specs)
        cp_parser_set_decl_spec_type (decl_specs, type,
                                      token->location,
-                                     /*user_defined=*/true);
+                                     /*type_definition_p=*/false);
     }
 
   /* If we didn't get a type-name, issue an error message.  */
@@ -12987,6 +13758,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
      class-name
      enum-name
      typedef-name
+     simple-template-id [in c++0x]
 
    enum-name:
      identifier
@@ -13014,8 +13786,37 @@ cp_parser_type_name (cp_parser* parser)
   /* If it's not a class-name, keep looking.  */
   if (!cp_parser_parse_definitely (parser))
     {
-      /* It must be a typedef-name or an enum-name.  */
-      return cp_parser_nonclass_name (parser);
+      if (cxx_dialect < cxx0x)
+       /* It must be a typedef-name or an enum-name.  */
+       return cp_parser_nonclass_name (parser);
+
+      cp_parser_parse_tentatively (parser);
+      /* It is either a simple-template-id representing an
+        instantiation of an alias template...  */
+      type_decl = cp_parser_template_id (parser,
+                                        /*template_keyword_p=*/false,
+                                        /*check_dependency_p=*/false,
+                                        /*is_declaration=*/false);
+      /* Note that this must be an instantiation of an alias template
+        because [temp.names]/6 says:
+        
+            A template-id that names an alias template specialization
+            is a type-name.
+
+        Whereas [temp.names]/7 says:
+        
+            A simple-template-id that names a class template
+            specialization is a class-name.  */
+      if (type_decl != NULL_TREE
+         && TREE_CODE (type_decl) == TYPE_DECL
+         && TYPE_DECL_ALIAS_P (type_decl))
+       gcc_assert (DECL_TEMPLATE_INSTANTIATION (type_decl));
+      else
+       cp_parser_simulate_error (parser);
+
+      if (!cp_parser_parse_definitely (parser))
+       /* ... Or a typedef-name or an enum-name.  */
+       return cp_parser_nonclass_name (parser);
     }
 
   return type_decl;
@@ -13045,6 +13846,8 @@ cp_parser_nonclass_name (cp_parser* parser)
   /* Look up the type-name.  */
   type_decl = cp_parser_lookup_name_simple (parser, identifier, token->location);
 
+  type_decl = strip_using_decl (type_decl);
+  
   if (TREE_CODE (type_decl) != TYPE_DECL
       && (objc_is_id (identifier) || objc_is_class_name (identifier)))
     {
@@ -13213,11 +14016,14 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
                                   typename_type,
                                   /*complain=*/tf_error);
       /* If the `typename' keyword is in effect and DECL is not a type
-        decl. Then type is non existant.   */
+        decl, then type is non existent.   */
       else if (tag_type == typename_type && TREE_CODE (decl) != TYPE_DECL)
-        type = NULL_TREE; 
-      else 
-       type = TREE_TYPE (decl);
+        ; 
+      else if (TREE_CODE (decl) == TYPE_DECL)
+        type = check_elaborated_type_specifier (tag_type, decl,
+                                               /*allow_template_p=*/true);
+      else if (decl == error_mark_node)
+       type = error_mark_node; 
     }
 
   if (!type)
@@ -13415,7 +14221,13 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
     }
 
   if (tag_type != enum_type)
-    cp_parser_check_class_key (tag_type, type);
+    {
+      /* Indicate whether this class was declared as a `class' or as a
+        `struct'.  */
+      if (TREE_CODE (type) == RECORD_TYPE)
+       CLASSTYPE_DECLARED_CLASS (type) = (tag_type == class_type);
+      cp_parser_check_class_key (tag_type, type);
+    }
 
   /* A "<" cannot follow an elaborated type specifier.  If that
      happens, the user was probably trying to form a template-id.  */
@@ -13428,6 +14240,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
 
    enum-specifier:
      enum-head { enumerator-list [opt] }
+     enum-head { enumerator-list , } [C++0x]
 
    enum-head:
      enum-key identifier [opt] enum-base [opt]
@@ -13447,6 +14260,8 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
    GNU Extensions:
      enum-key attributes[opt] identifier [opt] enum-base [opt] 
        { enumerator-list [opt] }attributes[opt]
+     enum-key attributes[opt] identifier [opt] enum-base [opt]
+       { enumerator-list, }attributes[opt] [C++0x]
 
    Returns an ENUM_TYPE representing the enumeration, or NULL_TREE
    if the token stream isn't an enum-specifier after all.  */
@@ -13786,8 +14601,9 @@ cp_parser_enumerator_list (cp_parser* parser, tree type)
       /* If the next token is a `}', there is a trailing comma.  */
       if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
        {
-         if (!in_system_header)
-           pedwarn (input_location, OPT_pedantic, "comma at end of enumerator list");
+         if (cxx_dialect < cxx0x && !in_system_header)
+           pedwarn (input_location, OPT_pedantic,
+                     "comma at end of enumerator list");
          break;
        }
     }
@@ -14087,9 +14903,14 @@ cp_parser_using_declaration (cp_parser* parser,
   tree decl;
   tree identifier;
   tree qscope;
+  int oldcount = errorcount;
+  cp_token *diag_token = NULL;
 
   if (access_declaration_p)
-    cp_parser_parse_tentatively (parser);
+    {
+      diag_token = cp_lexer_peek_token (parser->lexer);
+      cp_parser_parse_tentatively (parser);
+    }
   else
     {
       /* Look for the `using' keyword.  */
@@ -14171,9 +14992,12 @@ cp_parser_using_declaration (cp_parser* parser,
          /* Create the USING_DECL.  */
          decl = do_class_using_decl (parser->scope, identifier);
 
+         if (decl && typename_p)
+           USING_DECL_TYPENAME_P (decl) = 1;
+
          if (check_for_bare_parameter_packs (decl))
             return false;
-          else
+         else
            /* Add it to the list of members in this class.  */
            finish_member_declaration (decl);
        }
@@ -14197,10 +15021,125 @@ cp_parser_using_declaration (cp_parser* parser,
 
   /* Look for the final `;'.  */
   cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
-  
+
+  if (access_declaration_p && errorcount == oldcount)
+    warning_at (diag_token->location, OPT_Wdeprecated,
+               "access declarations are deprecated "
+               "in favour of using-declarations; "
+               "suggestion: add the %<using%> keyword");
+
   return true;
 }
 
+/* Parse an alias-declaration.
+
+   alias-declaration:
+     using identifier attribute-specifier-seq [opt] = type-id  */
+
+static tree
+cp_parser_alias_declaration (cp_parser* parser)
+{
+  tree id, type, decl, pushed_scope = NULL_TREE, attributes;
+  location_t id_location;
+  cp_declarator *declarator;
+  cp_decl_specifier_seq decl_specs;
+  bool member_p;
+  const char *saved_message = NULL;
+
+  /* Look for the `using' keyword.  */
+  cp_parser_require_keyword (parser, RID_USING, RT_USING);
+  id_location = cp_lexer_peek_token (parser->lexer)->location;
+  id = cp_parser_identifier (parser);
+  if (id == error_mark_node)
+    return error_mark_node;
+
+  attributes = cp_parser_attributes_opt (parser);
+  if (attributes == error_mark_node)
+    return error_mark_node;
+
+  cp_parser_require (parser, CPP_EQ, RT_EQ);
+
+  if (cp_parser_error_occurred (parser))
+    return error_mark_node;
+
+  /* Now we are going to parse the type-id of the declaration.  */
+
+  /*
+    [dcl.type]/3 says:
+
+       "A type-specifier-seq shall not define a class or enumeration
+        unless it appears in the type-id of an alias-declaration (7.1.3) that
+        is not the declaration of a template-declaration."
+
+    In other words, if we currently are in an alias template, the
+    type-id should not define a type.
+
+    So let's set parser->type_definition_forbidden_message in that
+    case; cp_parser_check_type_definition (called by
+    cp_parser_class_specifier) will then emit an error if a type is
+    defined in the type-id.  */
+  if (parser->num_template_parameter_lists)
+    {
+      saved_message = parser->type_definition_forbidden_message;
+      parser->type_definition_forbidden_message =
+       G_("types may not be defined in alias template declarations");
+    }
+
+  type = cp_parser_type_id (parser);
+
+  /* Restore the error message if need be.  */
+  if (parser->num_template_parameter_lists)
+    parser->type_definition_forbidden_message = saved_message;
+
+  cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
+
+  if (cp_parser_error_occurred (parser))
+    return error_mark_node;
+
+  /* A typedef-name can also be introduced by an alias-declaration. The
+     identifier following the using keyword becomes a typedef-name. It has
+     the same semantics as if it were introduced by the typedef
+     specifier. In particular, it does not define a new type and it shall
+     not appear in the type-id.  */
+
+  clear_decl_specs (&decl_specs);
+  decl_specs.type = type;
+  decl_specs.attributes = attributes;
+  ++decl_specs.specs[(int) ds_typedef];
+  ++decl_specs.specs[(int) ds_alias];
+
+  declarator = make_id_declarator (NULL_TREE, id, sfk_none);
+  declarator->id_loc = id_location;
+
+  member_p = at_class_scope_p ();
+  if (member_p)
+    decl = grokfield (declarator, &decl_specs, NULL_TREE, false,
+                     NULL_TREE, attributes);
+  else
+    decl = start_decl (declarator, &decl_specs, 0,
+                      attributes, NULL_TREE, &pushed_scope);
+  if (decl == error_mark_node)
+    return decl;
+
+  cp_finish_decl (decl, NULL_TREE, 0, NULL_TREE, 0);
+
+  if (pushed_scope)
+    pop_scope (pushed_scope);
+
+  /* If decl is a template, return its TEMPLATE_DECL so that it gets
+     added into the symbol table; otherwise, return the TYPE_DECL.  */
+  if (DECL_LANG_SPECIFIC (decl)
+      && DECL_TEMPLATE_INFO (decl)
+      && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
+    {
+      decl = DECL_TI_TEMPLATE (decl);
+      if (member_p)
+       check_member_template (decl);
+    }
+
+  return decl;
+}
+
 /* Parse a using-directive.
 
    using-directive:
@@ -14452,6 +15391,11 @@ cp_parser_asm_definition (cp_parser* parser)
    function-definition:
      __extension__ function-definition
 
+   TM Extension:
+
+   function-definition:
+     decl-specifier-seq [opt] declarator function-transaction-block
+
    The DECL_SPECIFIERS apply to this declarator.  Returns a
    representation of the entity declared.  If MEMBER_P is TRUE, then
    this declarator appears in a class scope.  The new DECL created by
@@ -14780,8 +15724,7 @@ cp_parser_init_declarator (cp_parser* parser,
        {
          /* We want to record the extra mangling scope for in-class
             initializers of class members and initializers of static data
-            member templates.  The former is a C++0x feature which isn't
-            implemented yet, and I expect it will involve deferring
+            member templates.  The former involves deferring
             parsing of the initializer until end of class as with default
             arguments.  So right here we only handle the latter.  */
          if (!member_p && processing_template_decl)
@@ -15196,18 +16139,20 @@ cp_parser_direct_declarator (cp_parser* parser,
                                                 &non_constant_p);
              if (!non_constant_p)
                /* OK */;
-             /* Normally, the array bound must be an integral constant
-                expression.  However, as an extension, we allow VLAs
-                in function scopes as long as they aren't part of a
-                parameter declaration.  */
+             else if (error_operand_p (bounds))
+               /* Already gave an error.  */;
              else if (!parser->in_function_body
                       || current_binding_level->kind == sk_function_parms)
                {
+                 /* Normally, the array bound must be an integral constant
+                    expression.  However, as an extension, we allow VLAs
+                    in function scopes as long as they aren't part of a
+                    parameter declaration.  */
                  cp_parser_error (parser,
                                   "array bound is not an integer constant");
                  bounds = error_mark_node;
                }
-             else if (processing_template_decl && !error_operand_p (bounds))
+             else if (processing_template_decl)
                {
                  /* Remember this wasn't a constant-expression.  */
                  bounds = build_nop (TREE_TYPE (bounds), bounds);
@@ -15538,6 +16483,9 @@ cp_parser_ptr_operator (cp_parser* parser,
 
          if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
            error_at (token->location, "%qD is a namespace", parser->scope);
+         else if (TREE_CODE (parser->scope) == ENUMERAL_TYPE)
+           error_at (token->location, "cannot form pointer to member of "
+                     "non-class %q#T", parser->scope);
          else
            {
              /* The type of which the member is a member is given by the
@@ -15682,6 +16630,31 @@ cp_parser_virt_specifier_seq_opt (cp_parser* parser)
   return virt_specifiers;
 }
 
+/* Used by handling of trailing-return-types and NSDMI, in which 'this'
+   is in scope even though it isn't real.  */
+
+static void
+inject_this_parameter (tree ctype, cp_cv_quals quals)
+{
+  tree this_parm;
+
+  if (current_class_ptr)
+    {
+      /* We don't clear this between NSDMIs.  Is it already what we want?  */
+      tree type = TREE_TYPE (TREE_TYPE (current_class_ptr));
+      if (same_type_ignoring_top_level_qualifiers_p (ctype, type)
+         && cp_type_quals (type) == quals)
+       return;
+    }
+
+  this_parm = build_this_parm (ctype, quals);
+  /* Clear this first to avoid shortcut in cp_build_indirect_ref.  */
+  current_class_ptr = NULL_TREE;
+  current_class_ref
+    = cp_build_indirect_ref (this_parm, RO_NULL, tf_warning_or_error);
+  current_class_ptr = this_parm;
+}
+
 /* Parse a late-specified return type, if any.  This is not a separate
    non-terminal, but part of a function declarator, which looks like
 
@@ -15696,7 +16669,7 @@ static tree
 cp_parser_late_return_type_opt (cp_parser* parser, cp_cv_quals quals)
 {
   cp_token *token;
-  tree type;
+  tree type, save_ccp, save_ccr;
 
   /* Peek at the next token.  */
   token = cp_lexer_peek_token (parser->lexer);
@@ -15707,21 +16680,21 @@ cp_parser_late_return_type_opt (cp_parser* parser, cp_cv_quals quals)
   /* Consume the ->.  */
   cp_lexer_consume_token (parser->lexer);
 
+  save_ccp = current_class_ptr;
+  save_ccr = current_class_ref;
   if (quals >= 0)
     {
       /* DR 1207: 'this' is in scope in the trailing return type.  */
-      tree this_parm = build_this_parm (current_class_type, quals);
-      gcc_assert (current_class_ptr == NULL_TREE);
-      current_class_ref
-       = cp_build_indirect_ref (this_parm, RO_NULL, tf_warning_or_error);
-      /* Set this second to avoid shortcut in cp_build_indirect_ref.  */
-      current_class_ptr = this_parm;
+      inject_this_parameter (current_class_type, quals);
     }
 
   type = cp_parser_trailing_type_id (parser);
 
-  if (current_class_type)
-    current_class_ptr = current_class_ref = NULL_TREE;
+  if (quals >= 0)
+    {
+      current_class_ptr = save_ccp;
+      current_class_ref = save_ccr;
+    }
 
   return type;
 }
@@ -16322,162 +17295,18 @@ cp_parser_parameter_declaration (cp_parser *parser,
   /* If the next token is `=', then process a default argument.  */
   if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
     {
-      /* Consume the `='.  */
-      cp_lexer_consume_token (parser->lexer);
-
+      token = cp_lexer_peek_token (parser->lexer);
       /* If we are defining a class, then the tokens that make up the
         default argument must be saved and processed later.  */
       if (!template_parm_p && at_class_scope_p ()
          && TYPE_BEING_DEFINED (current_class_type)
          && !LAMBDA_TYPE_P (current_class_type))
-       {
-         unsigned depth = 0;
-         int maybe_template_id = 0;
-         cp_token *first_token;
-         cp_token *token;
-
-         /* Add tokens until we have processed the entire default
-            argument.  We add the range [first_token, token).  */
-         first_token = cp_lexer_peek_token (parser->lexer);
-         while (true)
-           {
-             bool done = false;
-
-             /* Peek at the next token.  */
-             token = cp_lexer_peek_token (parser->lexer);
-             /* What we do depends on what token we have.  */
-             switch (token->type)
-               {
-                 /* In valid code, a default argument must be
-                    immediately followed by a `,' `)', or `...'.  */
-               case CPP_COMMA:
-                 if (depth == 0 && maybe_template_id)
-                   {
-                     /* If we've seen a '<', we might be in a
-                        template-argument-list.  Until Core issue 325 is
-                        resolved, we don't know how this situation ought
-                        to be handled, so try to DTRT.  We check whether
-                        what comes after the comma is a valid parameter
-                        declaration list.  If it is, then the comma ends
-                        the default argument; otherwise the default
-                        argument continues.  */
-                     bool error = false;
-                     tree t;
-
-                     /* Set ITALP so cp_parser_parameter_declaration_list
-                        doesn't decide to commit to this parse.  */
-                     bool saved_italp = parser->in_template_argument_list_p;
-                     parser->in_template_argument_list_p = true;
-
-                     cp_parser_parse_tentatively (parser);
-                     cp_lexer_consume_token (parser->lexer);
-                     begin_scope (sk_function_parms, NULL_TREE);
-                     cp_parser_parameter_declaration_list (parser, &error);
-                     for (t = current_binding_level->names; t; t = DECL_CHAIN (t))
-                       pop_binding (DECL_NAME (t), t);
-                     leave_scope ();
-                     if (!cp_parser_error_occurred (parser) && !error)
-                       done = true;
-                     cp_parser_abort_tentative_parse (parser);
-
-                     parser->in_template_argument_list_p = saved_italp;
-                     break;
-                   }
-               case CPP_CLOSE_PAREN:
-               case CPP_ELLIPSIS:
-                 /* If we run into a non-nested `;', `}', or `]',
-                    then the code is invalid -- but the default
-                    argument is certainly over.  */
-               case CPP_SEMICOLON:
-               case CPP_CLOSE_BRACE:
-               case CPP_CLOSE_SQUARE:
-                 if (depth == 0)
-                   done = true;
-                 /* Update DEPTH, if necessary.  */
-                 else if (token->type == CPP_CLOSE_PAREN
-                          || token->type == CPP_CLOSE_BRACE
-                          || token->type == CPP_CLOSE_SQUARE)
-                   --depth;
-                 break;
-
-               case CPP_OPEN_PAREN:
-               case CPP_OPEN_SQUARE:
-               case CPP_OPEN_BRACE:
-                 ++depth;
-                 break;
-
-               case CPP_LESS:
-                 if (depth == 0)
-                   /* This might be the comparison operator, or it might
-                      start a template argument list.  */
-                   ++maybe_template_id;
-                 break;
-
-                case CPP_RSHIFT:
-                  if (cxx_dialect == cxx98)
-                    break;
-                  /* Fall through for C++0x, which treats the `>>'
-                     operator like two `>' tokens in certain
-                     cases.  */
-
-               case CPP_GREATER:
-                 if (depth == 0)
-                   {
-                     /* This might be an operator, or it might close a
-                        template argument list.  But if a previous '<'
-                        started a template argument list, this will have
-                        closed it, so we can't be in one anymore.  */
-                     maybe_template_id -= 1 + (token->type == CPP_RSHIFT);
-                     if (maybe_template_id < 0)
-                       maybe_template_id = 0;
-                   }
-                 break;
-
-                 /* If we run out of tokens, issue an error message.  */
-               case CPP_EOF:
-               case CPP_PRAGMA_EOL:
-                 error_at (token->location, "file ends in default argument");
-                 done = true;
-                 break;
-
-               case CPP_NAME:
-               case CPP_SCOPE:
-                 /* In these cases, we should look for template-ids.
-                    For example, if the default argument is
-                    `X<int, double>()', we need to do name lookup to
-                    figure out whether or not `X' is a template; if
-                    so, the `,' does not end the default argument.
-
-                    That is not yet done.  */
-                 break;
-
-               default:
-                 break;
-               }
-
-             /* If we've reached the end, stop.  */
-             if (done)
-               break;
-
-             /* Add the token to the token block.  */
-             token = cp_lexer_consume_token (parser->lexer);
-           }
-
-         /* Create a DEFAULT_ARG to represent the unparsed default
-            argument.  */
-         default_argument = make_node (DEFAULT_ARG);
-         DEFARG_TOKENS (default_argument)
-           = cp_token_cache_new (first_token, token);
-         DEFARG_INSTANTIATIONS (default_argument) = NULL;
-       }
+       default_argument = cp_parser_cache_defarg (parser, /*nsdmi=*/false);
       /* Outside of a class definition, we can just parse the
         assignment-expression.  */
       else
-       {
-         token = cp_lexer_peek_token (parser->lexer);
-         default_argument 
-           = cp_parser_default_argument (parser, template_parm_p);
-       }
+       default_argument
+         = cp_parser_default_argument (parser, template_parm_p);
 
       if (!parser->default_arg_ok_p)
        {
@@ -16502,17 +17331,20 @@ cp_parser_parameter_declaration (cp_parser *parser,
          
          if (id_declarator && id_declarator->kind == cdk_id)
            error_at (declarator_token_start->location,
-                     template_parm_p 
-                     ? "template parameter pack %qD"
-                     " cannot have a default argument"
-                     : "parameter pack %qD cannot have a default argument",
+                     template_parm_p
+                     ? G_("template parameter pack %qD "
+                          "cannot have a default argument")
+                     : G_("parameter pack %qD cannot have "
+                          "a default argument"),
                      id_declarator->u.id.unqualified_name);
          else
            error_at (declarator_token_start->location,
-                     template_parm_p 
-                     ? "template parameter pack cannot have a default argument"
-                     : "parameter pack cannot have a default argument");
-         
+                     template_parm_p
+                     ? G_("template parameter pack cannot have "
+                          "a default argument")
+                     : G_("parameter pack cannot have a "
+                          "default argument"));
+
          default_argument = NULL_TREE;
        }
     }
@@ -16534,6 +17366,7 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
   tree default_argument = NULL_TREE;
   bool saved_greater_than_is_operator_p;
   bool saved_local_variables_forbidden_p;
+  bool non_constant_p, is_direct_init;
 
   /* Make sure that PARSER->GREATER_THAN_IS_OPERATOR_P is
      set correctly.  */
@@ -16547,7 +17380,9 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
   if (template_parm_p)
     push_deferring_access_checks (dk_no_deferred);
   default_argument
-    = cp_parser_assignment_expression (parser, /*cast_p=*/false, NULL);
+    = cp_parser_initializer (parser, &is_direct_init, &non_constant_p);
+  if (BRACE_ENCLOSED_INITIALIZER_P (default_argument))
+    maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
   if (template_parm_p)
     pop_deferring_access_checks ();
   parser->greater_than_is_operator_p = saved_greater_than_is_operator_p;
@@ -16593,11 +17428,8 @@ cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser)
      cp_parser_function_body changed its state.  */
   if (check_body_p)
     {
-      list = body;
-      if (TREE_CODE (list) == BIND_EXPR)
-       list = BIND_EXPR_BODY (list);
-      if (TREE_CODE (list) == STATEMENT_LIST
-         && STATEMENT_LIST_TAIL (list) != NULL)
+      list = cur_stmt_list;
+      if (STATEMENT_LIST_TAIL (list))
        last = STATEMENT_LIST_TAIL (list)->stmt;
     }
   /* Parse the function-body.  */
@@ -16824,10 +17656,18 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p)
               && !c_dialect_objc ()
               && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
        {
+         /* In C++11, [ could start a lambda-introducer.  */
+         bool non_const = false;
+
+         cp_parser_parse_tentatively (parser);
          cp_lexer_consume_token (parser->lexer);
-         designator = cp_parser_constant_expression (parser, false, NULL);
+         designator = cp_parser_constant_expression (parser, true, &non_const);
          cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
          cp_parser_require (parser, CPP_EQ, RT_EQ);
+         if (!cp_parser_parse_definitely (parser))
+           designator = NULL_TREE;
+         else if (non_const)
+           require_potential_rvalue_constant_expression (designator);
        }
       else
        designator = NULL_TREE;
@@ -17003,6 +17843,8 @@ cp_parser_class_name (cp_parser *parser,
        decl = TYPE_NAME (decl);
     }
 
+  decl = strip_using_decl (decl);
+
   /* Check to see that it is really the name of a class.  */
   if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
       && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
@@ -17060,16 +17902,13 @@ cp_parser_class_specifier_1 (cp_parser* parser)
   bool saved_in_unbraced_linkage_specification_p;
   tree old_scope = NULL_TREE;
   tree scope = NULL_TREE;
-  tree bases;
   cp_token *closing_brace;
 
   push_deferring_access_checks (dk_no_deferred);
 
   /* Parse the class-head.  */
   type = cp_parser_class_head (parser,
-                              &nested_name_specifier_p,
-                              &attributes,
-                              &bases);
+                              &nested_name_specifier_p);
   /* If the class-head was a semantic disaster, skip the entire body
      of the class.  */
   if (!type)
@@ -17086,18 +17925,6 @@ cp_parser_class_specifier_1 (cp_parser* parser)
       return error_mark_node;
     }
 
-  /* Process the base classes. If they're invalid, skip the 
-     entire class body.  */
-  if (!xref_basetypes (type, bases))
-    {
-      /* Consuming the closing brace yields better error messages
-         later on.  */
-      if (cp_parser_skip_to_closing_brace (parser))
-       cp_lexer_consume_token (parser->lexer);
-      pop_deferring_access_checks ();
-      return error_mark_node;
-    }
-
   /* Issue an error message if type-definitions are forbidden here.  */
   cp_parser_check_type_definition (parser);
   /* Remember that we are defining one more class.  */
@@ -17127,7 +17954,7 @@ cp_parser_class_specifier_1 (cp_parser* parser)
       scope = CP_DECL_CONTEXT (TYPE_MAIN_DECL (type));
       old_scope = push_inner_scope (scope);
     }
-  type = begin_class_definition (type, attributes);
+  type = begin_class_definition (type);
 
   if (type == error_mark_node)
     /* If the type is erroneous, skip the entire body of the class.  */
@@ -17261,11 +18088,12 @@ cp_parser_class_specifier_1 (cp_parser* parser)
      there is no need to delay the parsing of `A::B::f'.  */
   if (--parser->num_classes_being_defined == 0)
     {
-      tree fn;
+      tree decl;
       tree class_type = NULL_TREE;
       tree pushed_scope = NULL_TREE;
       unsigned ix;
       cp_default_arg_entry *e;
+      tree save_ccp, save_ccr;
 
       /* In a first pass, parse default arguments to the functions.
         Then, in a second pass, parse the bodies of the functions.
@@ -17280,7 +18108,7 @@ cp_parser_class_specifier_1 (cp_parser* parser)
       FOR_EACH_VEC_ELT (cp_default_arg_entry, unparsed_funs_with_default_args,
                        ix, e)
        {
-         fn = e->decl;
+         decl = e->decl;
          /* If there are default arguments that have not yet been processed,
             take care of them now.  */
          if (class_type != e->class_type)
@@ -17291,18 +18119,36 @@ cp_parser_class_specifier_1 (cp_parser* parser)
              pushed_scope = push_scope (class_type);
            }
          /* Make sure that any template parameters are in scope.  */
-         maybe_begin_member_template_processing (fn);
+         maybe_begin_member_template_processing (decl);
          /* Parse the default argument expressions.  */
-         cp_parser_late_parsing_default_args (parser, fn);
+         cp_parser_late_parsing_default_args (parser, decl);
          /* Remove any template parameters from the symbol table.  */
          maybe_end_member_template_processing ();
        }
+      VEC_truncate (cp_default_arg_entry, unparsed_funs_with_default_args, 0);
+      /* Now parse any NSDMIs.  */
+      save_ccp = current_class_ptr;
+      save_ccr = current_class_ref;
+      FOR_EACH_VEC_ELT (tree, unparsed_nsdmis, ix, decl)
+       {
+         if (class_type != DECL_CONTEXT (decl))
+           {
+             if (pushed_scope)
+               pop_scope (pushed_scope);
+             class_type = DECL_CONTEXT (decl);
+             pushed_scope = push_scope (class_type);
+           }
+         inject_this_parameter (class_type, TYPE_UNQUALIFIED);
+         cp_parser_late_parsing_nsdmi (parser, decl);
+       }
+      VEC_truncate (tree, unparsed_nsdmis, 0);
+      current_class_ptr = save_ccp;
+      current_class_ref = save_ccr;
       if (pushed_scope)
        pop_scope (pushed_scope);
-      VEC_truncate (cp_default_arg_entry, unparsed_funs_with_default_args, 0);
       /* Now parse the body of the functions.  */
-      FOR_EACH_VEC_ELT (tree, unparsed_funs_with_definitions, ix, fn)
-       cp_parser_late_parsing_for_member (parser, fn);
+      FOR_EACH_VEC_ELT (tree, unparsed_funs_with_definitions, ix, decl)
+       cp_parser_late_parsing_for_member (parser, decl);
       VEC_truncate (tree, unparsed_funs_with_definitions, 0);
     }
 
@@ -17364,15 +18210,14 @@ cp_parser_class_specifier (cp_parser* parser)
 
 static tree
 cp_parser_class_head (cp_parser* parser,
-                     bool* nested_name_specifier_p,
-                     tree *attributes_p,
-                     tree *bases)
+                     bool* nested_name_specifier_p)
 {
   tree nested_name_specifier;
   enum tag_types class_key;
   tree id = NULL_TREE;
   tree type = NULL_TREE;
   tree attributes;
+  tree bases;
   cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
   bool template_id_p = false;
   bool qualified_p = false;
@@ -17389,8 +18234,6 @@ cp_parser_class_head (cp_parser* parser,
   num_templates = 0;
   parser->colon_corrects_to_scope_p = false;
 
-  *bases = NULL_TREE;
-
   /* Look for the class-key.  */
   class_key = cp_parser_class_key (parser);
   if (class_key == none_type)
@@ -17520,8 +18363,8 @@ cp_parser_class_head (cp_parser* parser,
     {
       cp_parser_check_for_invalid_template_id (parser, id,
                                                type_start_token->location);
-      virt_specifiers = cp_parser_virt_specifier_seq_opt (parser);
     }
+  virt_specifiers = cp_parser_virt_specifier_seq_opt (parser);
 
   /* If it's not a `:' or a `{' then we can't really be looking at a
      class-head, since a class-head only appears as part of a
@@ -17733,6 +18576,14 @@ cp_parser_class_head (cp_parser* parser,
   else if (type == error_mark_node)
     type = NULL_TREE;
 
+  if (type)
+    {
+      /* Apply attributes now, before any use of the class as a template
+        argument in its base list.  */
+      cplus_decl_attributes (&type, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
+      fixup_attribute_variants (type);
+    }
+
   /* We will have entered the scope containing the class; the names of
      base classes should be looked up in that context.  For example:
 
@@ -17743,7 +18594,15 @@ cp_parser_class_head (cp_parser* parser,
 
   /* Get the list of base-classes, if there is one.  */
   if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
-    *bases = cp_parser_base_clause (parser);
+    bases = cp_parser_base_clause (parser);
+  else
+    bases = NULL_TREE;
+
+  /* If we're really defining a class, process the base classes.
+     If they're invalid, fail.  */
+  if (type && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)
+      && !xref_basetypes (type, bases))
+    type = NULL_TREE;
 
  done:
   /* Leave the scope given by the nested-name-specifier.  We will
@@ -17759,7 +18618,6 @@ cp_parser_class_head (cp_parser* parser,
 
   if (type)
     DECL_SOURCE_LOCATION (TYPE_NAME (type)) = type_start_token->location;
-  *attributes_p = attributes;
   if (type && (virt_specifiers & VIRT_SPEC_FINAL))
     CLASSTYPE_FINAL (type) = 1;
  out:
@@ -17855,6 +18713,7 @@ cp_parser_member_specification_opt (cp_parser* parser)
      :: [opt] nested-name-specifier template [opt] unqualified-id ;
      using-declaration
      template-declaration
+     alias-declaration
 
    member-declarator-list:
      member-declarator
@@ -17922,10 +18781,25 @@ cp_parser_member_declaration (cp_parser* parser)
   /* Check for a using-declaration.  */
   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_USING))
     {
-      /* Parse the using-declaration.  */
-      cp_parser_using_declaration (parser,
-                                  /*access_declaration_p=*/false);
-      return;
+      if (cxx_dialect < cxx0x)
+       {
+         /* Parse the using-declaration.  */
+         cp_parser_using_declaration (parser,
+                                      /*access_declaration_p=*/false);
+         return;
+       }
+      else
+       {
+         tree decl;
+         cp_parser_parse_tentatively (parser);
+         decl = cp_parser_alias_declaration (parser);
+         if (cp_parser_parse_definitely (parser))
+           finish_member_declaration (decl);
+         else
+           cp_parser_using_declaration (parser,
+                                        /*access_declaration_p=*/false);
+         return;
+       }
     }
 
   /* Check for @defs.  */
@@ -17954,7 +18828,7 @@ cp_parser_member_declaration (cp_parser* parser)
   parser->colon_corrects_to_scope_p = false;
 
   if (cp_parser_using_declaration (parser, /*access_declaration=*/true))
-    goto out;
+      goto out;
 
   /* Parse the decl-specifier-seq.  */
   decl_spec_token_start = cp_lexer_peek_token (parser->lexer);
@@ -18181,12 +19055,38 @@ cp_parser_member_declaration (cp_parser* parser)
                     constant-initializer.  When we call `grokfield', it will
                     perform more stringent semantics checks.  */
                  initializer_token_start = cp_lexer_peek_token (parser->lexer);
-                 if (function_declarator_p (declarator))
+                 if (function_declarator_p (declarator)
+                     || (decl_specifiers.type
+                         && TREE_CODE (decl_specifiers.type) == TYPE_DECL
+                         && (TREE_CODE (TREE_TYPE (decl_specifiers.type))
+                             == FUNCTION_TYPE)))
                    initializer = cp_parser_pure_specifier (parser);
+                 else if (decl_specifiers.storage_class != sc_static)
+                   initializer = cp_parser_save_nsdmi (parser);
+                 else if (cxx_dialect >= cxx0x)
+                   {
+                     bool nonconst;
+                     /* Don't require a constant rvalue in C++11, since we
+                        might want a reference constant.  We'll enforce
+                        constancy later.  */
+                     cp_lexer_consume_token (parser->lexer);
+                     /* Parse the initializer.  */
+                     initializer = cp_parser_initializer_clause (parser,
+                                                                 &nonconst);
+                   }
                  else
                    /* Parse the initializer.  */
                    initializer = cp_parser_constant_initializer (parser);
                }
+             else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)
+                      && !function_declarator_p (declarator))
+               {
+                 bool x;
+                 if (decl_specifiers.storage_class != sc_static)
+                   initializer = cp_parser_save_nsdmi (parser);
+                 else
+                   initializer = cp_parser_initializer (parser, &x, &x);
+               }
              /* Otherwise, there is no initializer.  */
              else
                initializer = NULL_TREE;
@@ -18204,7 +19104,7 @@ cp_parser_member_declaration (cp_parser* parser)
                     possible that this fact is an oversight in the
                     standard, since a pure function may be defined
                     outside of the class-specifier.  */
-                 if (initializer)
+                 if (initializer && initializer_token_start)
                    error_at (initializer_token_start->location,
                              "pure-specifier on function-definition");
                  decl = cp_parser_save_member_function_body (parser,
@@ -18271,6 +19171,11 @@ cp_parser_member_declaration (cp_parser* parser)
 
              if (TREE_CODE (decl) == FUNCTION_DECL)
                cp_parser_save_default_args (parser, decl);
+             else if (TREE_CODE (decl) == FIELD_DECL
+                      && !DECL_C_BIT_FIELD (decl)
+                      && DECL_INITIAL (decl))
+               /* Add DECL to the queue of NSDMI to be parsed later.  */
+               VEC_safe_push (tree, gc, unparsed_nsdmis, decl);
            }
 
          if (assume_semicolon)
@@ -18587,19 +19492,25 @@ cp_parser_base_specifier (cp_parser* parser)
 
 /* Exception handling [gram.exception] */
 
-/* Parse an (optional) exception-specification.
+/* Parse an (optional) noexcept-specification.
 
-   exception-specification:
-     throw ( type-id-list [opt] )
+   noexcept-specification:
+     noexcept ( constant-expression ) [opt]
 
-   Returns a TREE_LIST representing the exception-specification.  The
-   TREE_VALUE of each node is a type.  */
+   If no noexcept-specification is present, returns NULL_TREE.
+   Otherwise, if REQUIRE_CONSTEXPR is false, then either parse and return any
+   expression if parentheses follow noexcept, or return BOOLEAN_TRUE_NODE if
+   there are no parentheses.  CONSUMED_EXPR will be set accordingly.
+   Otherwise, returns a noexcept specification unless RETURN_COND is true,
+   in which case a boolean condition is returned instead.  */
 
 static tree
-cp_parser_exception_specification_opt (cp_parser* parser)
+cp_parser_noexcept_specification_opt (cp_parser* parser,
+                                     bool require_constexpr,
+                                     bool* consumed_expr,
+                                     bool return_cond)
 {
   cp_token *token;
-  tree type_id_list;
   const char *saved_message;
 
   /* Peek at the next token.  */
@@ -18615,23 +19526,67 @@ cp_parser_exception_specification_opt (cp_parser* parser)
        {
          cp_lexer_consume_token (parser->lexer);
 
-         /* Types may not be defined in an exception-specification.  */
-         saved_message = parser->type_definition_forbidden_message;
-         parser->type_definition_forbidden_message
-           = G_("types may not be defined in an exception-specification");
+         if (require_constexpr)
+           {
+             /* Types may not be defined in an exception-specification.  */
+             saved_message = parser->type_definition_forbidden_message;
+             parser->type_definition_forbidden_message
+             = G_("types may not be defined in an exception-specification");
 
-         expr = cp_parser_constant_expression (parser, false, NULL);
+             expr = cp_parser_constant_expression (parser, false, NULL);
 
-         /* Restore the saved message.  */
-         parser->type_definition_forbidden_message = saved_message;
+             /* Restore the saved message.  */
+             parser->type_definition_forbidden_message = saved_message;
+           }
+         else
+           {
+             expr = cp_parser_expression (parser, false, NULL);
+             *consumed_expr = true;
+           }
 
          cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
        }
       else
-       expr = boolean_true_node;
+       {
+         expr = boolean_true_node;
+         if (!require_constexpr)
+           *consumed_expr = false;
+       }
 
-      return build_noexcept_spec (expr, tf_warning_or_error);
+      /* We cannot build a noexcept-spec right away because this will check
+        that expr is a constexpr.  */
+      if (!return_cond)
+       return build_noexcept_spec (expr, tf_warning_or_error);
+      else
+       return expr;
     }
+  else
+    return NULL_TREE;
+}
+
+/* Parse an (optional) exception-specification.
+
+   exception-specification:
+     throw ( type-id-list [opt] )
+
+   Returns a TREE_LIST representing the exception-specification.  The
+   TREE_VALUE of each node is a type.  */
+
+static tree
+cp_parser_exception_specification_opt (cp_parser* parser)
+{
+  cp_token *token;
+  tree type_id_list;
+  const char *saved_message;
+
+  /* Peek at the next token.  */
+  token = cp_lexer_peek_token (parser->lexer);
+
+  /* Is it a noexcept-specification?  */
+  type_id_list = cp_parser_noexcept_specification_opt(parser, true, NULL,
+                                                     false);
+  if (type_id_list != NULL_TREE)
+    return type_id_list;
 
   /* If it's not `throw', then there's no exception-specification.  */
   if (!cp_parser_is_keyword (token, RID_THROW))
@@ -19513,7 +20468,8 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
        object_decl = lookup_member (object_type,
                                     name,
                                     /*protect=*/0,
-                                    tag_type != none_type);
+                                    tag_type != none_type,
+                                    tf_warning_or_error);
       /* Look it up in the enclosing context, too.  */
       decl = lookup_name_real (name, tag_type != none_type,
                               /*nonclass=*/0,
@@ -19572,6 +20528,8 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
   if (DECL_P (decl))
     check_accessibility_of_qualified_id (decl, object_type, parser->scope);
 
+  maybe_record_typedef_use (decl);
+
   return decl;
 }
 
@@ -20074,12 +21032,19 @@ cp_parser_function_definition_after_declarator (cp_parser* parser,
 
   start_lambda_scope (current_function_decl);
 
-  /* If the next token is `try', then we are looking at a
-     function-try-block.  */
-  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
+  /* If the next token is `try', `__transaction_atomic', or
+     `__transaction_relaxed`, then we are looking at either function-try-block
+     or function-transaction-block.  Note that all of these include the
+     function-body.  */
+  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRANSACTION_ATOMIC))
+    ctor_initializer_p = cp_parser_function_transaction (parser,
+       RID_TRANSACTION_ATOMIC);
+  else if (cp_lexer_next_token_is_keyword (parser->lexer,
+      RID_TRANSACTION_RELAXED))
+    ctor_initializer_p = cp_parser_function_transaction (parser,
+       RID_TRANSACTION_RELAXED);
+  else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
     ctor_initializer_p = cp_parser_function_try_block (parser);
-  /* A function-try-block includes the function-body, so we only do
-     this next part if we're not processing a function-try-block.  */
   else
     ctor_initializer_p
       = cp_parser_ctor_initializer_opt_and_function_body (parser);
@@ -20165,7 +21130,6 @@ cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p)
     {
       /* Parse the template parameters.  */
       parameter_list = cp_parser_template_parameter_list (parser);
-      fixup_template_parms ();
     }
 
   /* Get the deferred access checks from the parameter list.  These
@@ -20183,6 +21147,9 @@ cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p)
   if (cp_lexer_next_token_is_keyword (parser->lexer,
                                      RID_TEMPLATE))
     cp_parser_template_declaration_after_export (parser, member_p);
+  else if (cxx_dialect >= cxx0x
+          && cp_lexer_next_token_is_keyword (parser->lexer, RID_USING))
+    decl = cp_parser_alias_declaration (parser);
   else
     {
       /* There are no access checks when parsing a template, as we do not
@@ -20217,6 +21184,33 @@ cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p)
   /* Finish up.  */
   finish_template_decl (parameter_list);
 
+  /* Check the template arguments for a literal operator template.  */
+  if (decl
+      && (TREE_CODE (decl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (decl))
+      && UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool ok = true;
+      if (parameter_list == NULL_TREE)
+       ok = false;
+      else
+       {
+         int num_parms = TREE_VEC_LENGTH (parameter_list);
+         if (num_parms != 1)
+           ok = false;
+         else
+           {
+             tree parm_list = TREE_VEC_ELT (parameter_list, 0);
+             tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
+             if (TREE_TYPE (parm) != char_type_node
+                 || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+               ok = false;
+           }
+       }
+      if (!ok)
+       error ("literal operator template %qD has invalid parameter list."
+              "  Expected non-type template argument pack <char...>",
+              decl);
+    }
   /* Register member declarations.  */
   if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
     finish_member_declaration (decl);
@@ -20407,6 +21401,9 @@ cp_parser_functional_cast (cp_parser* parser, tree type)
   tree cast;
   bool nonconst_p;
 
+  if (!type)
+    type = error_mark_node;
+
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
     {
       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
@@ -20516,8 +21513,17 @@ cp_parser_save_member_function_body (cp_parser* parser,
   return fn;
 }
 
+/* Save the tokens that make up the in-class initializer for a non-static
+   data member.  Returns a DEFAULT_ARG.  */
+
+static tree
+cp_parser_save_nsdmi (cp_parser* parser)
+{
+  return cp_parser_cache_defarg (parser, /*nsdmi=*/true);
+}
+
 /* Parse a template-argument-list, as well as the trailing ">" (but
-   not the opening ">").  See cp_parser_template_argument_list for the
+   not the opening "<").  See cp_parser_template_argument_list for the
    return value.  */
 
 static tree
@@ -20721,6 +21727,86 @@ cp_parser_save_default_args (cp_parser* parser, tree decl)
       }
 }
 
+/* DEFAULT_ARG contains the saved tokens for the initializer of DECL,
+   which is either a FIELD_DECL or PARM_DECL.  Parse it and return
+   the result.  For a PARM_DECL, PARMTYPE is the corresponding type
+   from the parameter-type-list.  */
+
+static tree
+cp_parser_late_parse_one_default_arg (cp_parser *parser, tree decl,
+                                     tree default_arg, tree parmtype)
+{
+  cp_token_cache *tokens;
+  tree parsed_arg;
+  bool dummy;
+
+  if (default_arg == error_mark_node)
+    return error_mark_node;
+
+  /* Push the saved tokens for the default argument onto the parser's
+     lexer stack.  */
+  tokens = DEFARG_TOKENS (default_arg);
+  cp_parser_push_lexer_for_tokens (parser, tokens);
+
+  start_lambda_scope (decl);
+
+  /* Parse the default argument.  */
+  parsed_arg = cp_parser_initializer (parser, &dummy, &dummy);
+  if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg))
+    maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
+
+  finish_lambda_scope ();
+
+  if (!processing_template_decl)
+    {
+      /* In a non-template class, check conversions now.  In a template,
+        we'll wait and instantiate these as needed.  */
+      if (TREE_CODE (decl) == PARM_DECL)
+       parsed_arg = check_default_argument (parmtype, parsed_arg);
+      else
+       {
+         int flags = LOOKUP_IMPLICIT;
+         if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg)
+             && CONSTRUCTOR_IS_DIRECT_INIT (parsed_arg))
+           flags = LOOKUP_NORMAL;
+         parsed_arg = digest_init_flags (TREE_TYPE (decl), parsed_arg, flags);
+       }
+    }
+
+  /* If the token stream has not been completely used up, then
+     there was extra junk after the end of the default
+     argument.  */
+  if (!cp_lexer_next_token_is (parser->lexer, CPP_EOF))
+    {
+      if (TREE_CODE (decl) == PARM_DECL)
+       cp_parser_error (parser, "expected %<,%>");
+      else
+       cp_parser_error (parser, "expected %<;%>");
+    }
+
+  /* Revert to the main lexer.  */
+  cp_parser_pop_lexer (parser);
+
+  return parsed_arg;
+}
+
+/* FIELD is a non-static data member with an initializer which we saved for
+   later; parse it now.  */
+
+static void
+cp_parser_late_parsing_nsdmi (cp_parser *parser, tree field)
+{
+  tree def;
+
+  push_unparsed_function_queues (parser);
+  def = cp_parser_late_parse_one_default_arg (parser, field,
+                                             DECL_INITIAL (field),
+                                             NULL_TREE);
+  pop_unparsed_function_queues (parser);
+
+  DECL_INITIAL (field) = def;
+}
+
 /* FN is a FUNCTION_DECL which may contains a parameter with an
    unparsed DEFAULT_ARG.  Parse the default args now.  This function
    assumes that the current scope is the scope in which the default
@@ -20751,7 +21837,6 @@ cp_parser_late_parsing_default_args (cp_parser *parser, tree fn)
        parm = TREE_CHAIN (parm),
         parmdecl = DECL_CHAIN (parmdecl))
     {
-      cp_token_cache *tokens;
       tree default_arg = TREE_PURPOSE (parm);
       tree parsed_arg;
       VEC(tree,gc) *insts;
@@ -20766,41 +21851,21 @@ cp_parser_late_parsing_default_args (cp_parser *parser, tree fn)
           already declared with default arguments.  */
        continue;
 
-       /* Push the saved tokens for the default argument onto the parser's
-         lexer stack.  */
-      tokens = DEFARG_TOKENS (default_arg);
-      cp_parser_push_lexer_for_tokens (parser, tokens);
-
-      start_lambda_scope (parmdecl);
-
-      /* Parse the assignment-expression.  */
-      parsed_arg = cp_parser_assignment_expression (parser, /*cast_p=*/false, NULL);
+      parsed_arg
+       = cp_parser_late_parse_one_default_arg (parser, parmdecl,
+                                               default_arg,
+                                               TREE_VALUE (parm));
       if (parsed_arg == error_mark_node)
        {
-         cp_parser_pop_lexer (parser);
          continue;
        }
 
-      if (!processing_template_decl)
-       parsed_arg = check_default_argument (TREE_VALUE (parm), parsed_arg);
-
       TREE_PURPOSE (parm) = parsed_arg;
 
       /* Update any instantiations we've already created.  */
       for (insts = DEFARG_INSTANTIATIONS (default_arg), ix = 0;
           VEC_iterate (tree, insts, ix, copy); ix++)
        TREE_PURPOSE (copy) = parsed_arg;
-
-      finish_lambda_scope ();
-
-      /* If the token stream has not been completely used up, then
-        there was extra junk after the end of the default
-        argument.  */
-      if (!cp_lexer_next_token_is (parser->lexer, CPP_EOF))
-       cp_parser_error (parser, "expected %<,%>");
-
-      /* Revert to the main lexer.  */
-      cp_parser_pop_lexer (parser);
     }
 
   pop_defarg_context ();
@@ -20997,15 +22062,14 @@ cp_parser_set_storage_class (cp_parser *parser,
     decl_specs->conflicting_specifiers_p = true;
 }
 
-/* Update the DECL_SPECS to reflect the TYPE_SPEC.  If USER_DEFINED_P
-   is true, the type is a user-defined type; otherwise it is a
-   built-in type specified by a keyword.  */
+/* Update the DECL_SPECS to reflect the TYPE_SPEC.  If TYPE_DEFINITION_P
+   is true, the type is a class or enum definition.  */
 
 static void
 cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs,
                              tree type_spec,
                              location_t location,
-                             bool user_defined_p)
+                             bool type_definition_p)
 {
   decl_specs->any_specifiers_p = true;
 
@@ -21015,7 +22079,7 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs,
      declarations so that G++ can work with system headers that are not
      C++-safe.  */
   if (decl_specs->specs[(int) ds_typedef]
-      && !user_defined_p
+      && !type_definition_p
       && (type_spec == boolean_type_node
          || type_spec == char16_type_node
          || type_spec == char32_type_node
@@ -21030,7 +22094,7 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs,
       if (!decl_specs->type)
        {
          decl_specs->type = type_spec;
-         decl_specs->user_defined_type_p = false;
+         decl_specs->type_definition_p = false;
          decl_specs->type_location = location;
        }
     }
@@ -21039,7 +22103,7 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs,
   else
     {
       decl_specs->type = type_spec;
-      decl_specs->user_defined_type_p = user_defined_p;
+      decl_specs->type_definition_p = type_definition_p;
       decl_specs->redefined_builtin_type = NULL_TREE;
       decl_specs->type_location = location;
     }
@@ -21126,6 +22190,12 @@ cp_parser_required_error (cp_parser *parser,
       case RT_AT_THROW:
        cp_parser_error (parser, "expected %<@throw%>");
        return;
+      case RT_TRANSACTION_ATOMIC:
+       cp_parser_error (parser, "expected %<__transaction_atomic%>");
+       return;
+      case RT_TRANSACTION_RELAXED:
+       cp_parser_error (parser, "expected %<__transaction_relaxed%>");
+       return;
       default:
        break;
     }
@@ -21356,6 +22426,10 @@ cp_parser_token_starts_function_definition_p (cp_token* token)
          || token->type == CPP_COLON
          /* A function-try-block begins with `try'.  */
          || token->keyword == RID_TRY
+         /* A function-transaction-block begins with `__transaction_atomic'
+            or `__transaction_relaxed'.  */
+         || token->keyword == RID_TRANSACTION_ATOMIC
+         || token->keyword == RID_TRANSACTION_RELAXED
          /* The named return value extension begins with `return'.  */
          || token->keyword == RID_RETURN);
 }
@@ -21437,11 +22511,17 @@ cp_parser_token_is_class_key (cp_token* token)
 static void
 cp_parser_check_class_key (enum tag_types class_key, tree type)
 {
+  if (type == error_mark_node)
+    return;
   if ((TREE_CODE (type) == UNION_TYPE) != (class_key == union_type))
-    permerror (input_location, "%qs tag used in naming %q#T",
-           class_key == union_type ? "union"
-            : class_key == record_type ? "struct" : "class",
-            type);
+    {
+      permerror (input_location, "%qs tag used in naming %q#T",
+                class_key == union_type ? "union"
+                : class_key == record_type ? "struct" : "class",
+                type);
+      inform (DECL_SOURCE_LOCATION (TYPE_NAME (type)),
+             "%q#T was previously declared here", type);
+    }
 }
 
 /* Issue an error message if DECL is redeclared with different
@@ -21576,6 +22656,178 @@ cp_parser_cache_group (cp_parser *parser,
     }
 }
 
+/* Like above, for caching a default argument or NSDMI.  Both of these are
+   terminated by a non-nested comma, but it can be unclear whether or not a
+   comma is nested in a template argument list unless we do more parsing.
+   In order to handle this ambiguity, when we encounter a ',' after a '<'
+   we try to parse what follows as a parameter-declaration-list (in the
+   case of a default argument) or a member-declarator (in the case of an
+   NSDMI).  If that succeeds, then we stop caching.  */
+
+static tree
+cp_parser_cache_defarg (cp_parser *parser, bool nsdmi)
+{
+  unsigned depth = 0;
+  int maybe_template_id = 0;
+  cp_token *first_token;
+  cp_token *token;
+  tree default_argument;
+
+  /* Add tokens until we have processed the entire default
+     argument.  We add the range [first_token, token).  */
+  first_token = cp_lexer_peek_token (parser->lexer);
+  if (first_token->type == CPP_OPEN_BRACE)
+    {
+      /* For list-initialization, this is straightforward.  */
+      cp_parser_cache_group (parser, CPP_CLOSE_BRACE, /*depth=*/0);
+      token = cp_lexer_peek_token (parser->lexer);
+    }
+  else while (true)
+    {
+      bool done = false;
+
+      /* Peek at the next token.  */
+      token = cp_lexer_peek_token (parser->lexer);
+      /* What we do depends on what token we have.  */
+      switch (token->type)
+       {
+         /* In valid code, a default argument must be
+            immediately followed by a `,' `)', or `...'.  */
+       case CPP_COMMA:
+         if (depth == 0 && maybe_template_id)
+           {
+             /* If we've seen a '<', we might be in a
+                template-argument-list.  Until Core issue 325 is
+                resolved, we don't know how this situation ought
+                to be handled, so try to DTRT.  We check whether
+                what comes after the comma is a valid parameter
+                declaration list.  If it is, then the comma ends
+                the default argument; otherwise the default
+                argument continues.  */
+             bool error = false;
+             tree t;
+
+             /* Set ITALP so cp_parser_parameter_declaration_list
+                doesn't decide to commit to this parse.  */
+             bool saved_italp = parser->in_template_argument_list_p;
+             parser->in_template_argument_list_p = true;
+
+             cp_parser_parse_tentatively (parser);
+             cp_lexer_consume_token (parser->lexer);
+
+             if (nsdmi)
+               {
+                 int ctor_dtor_or_conv_p;
+                 cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
+                                       &ctor_dtor_or_conv_p,
+                                       /*parenthesized_p=*/NULL,
+                                       /*member_p=*/true);
+               }
+             else
+               {
+                 begin_scope (sk_function_parms, NULL_TREE);
+                 cp_parser_parameter_declaration_list (parser, &error);
+                 for (t = current_binding_level->names; t; t = DECL_CHAIN (t))
+                   pop_binding (DECL_NAME (t), t);
+                 leave_scope ();
+               }
+             if (!cp_parser_error_occurred (parser) && !error)
+               done = true;
+             cp_parser_abort_tentative_parse (parser);
+
+             parser->in_template_argument_list_p = saved_italp;
+             break;
+           }
+       case CPP_CLOSE_PAREN:
+       case CPP_ELLIPSIS:
+         /* If we run into a non-nested `;', `}', or `]',
+            then the code is invalid -- but the default
+            argument is certainly over.  */
+       case CPP_SEMICOLON:
+       case CPP_CLOSE_BRACE:
+       case CPP_CLOSE_SQUARE:
+         if (depth == 0)
+           done = true;
+         /* Update DEPTH, if necessary.  */
+         else if (token->type == CPP_CLOSE_PAREN
+                  || token->type == CPP_CLOSE_BRACE
+                  || token->type == CPP_CLOSE_SQUARE)
+           --depth;
+         break;
+
+       case CPP_OPEN_PAREN:
+       case CPP_OPEN_SQUARE:
+       case CPP_OPEN_BRACE:
+         ++depth;
+         break;
+
+       case CPP_LESS:
+         if (depth == 0)
+           /* This might be the comparison operator, or it might
+              start a template argument list.  */
+           ++maybe_template_id;
+         break;
+
+       case CPP_RSHIFT:
+         if (cxx_dialect == cxx98)
+           break;
+         /* Fall through for C++0x, which treats the `>>'
+            operator like two `>' tokens in certain
+            cases.  */
+
+       case CPP_GREATER:
+         if (depth == 0)
+           {
+             /* This might be an operator, or it might close a
+                template argument list.  But if a previous '<'
+                started a template argument list, this will have
+                closed it, so we can't be in one anymore.  */
+             maybe_template_id -= 1 + (token->type == CPP_RSHIFT);
+             if (maybe_template_id < 0)
+               maybe_template_id = 0;
+           }
+         break;
+
+         /* If we run out of tokens, issue an error message.  */
+       case CPP_EOF:
+       case CPP_PRAGMA_EOL:
+         error_at (token->location, "file ends in default argument");
+         done = true;
+         break;
+
+       case CPP_NAME:
+       case CPP_SCOPE:
+         /* In these cases, we should look for template-ids.
+            For example, if the default argument is
+            `X<int, double>()', we need to do name lookup to
+            figure out whether or not `X' is a template; if
+            so, the `,' does not end the default argument.
+
+            That is not yet done.  */
+         break;
+
+       default:
+         break;
+       }
+
+      /* If we've reached the end, stop.  */
+      if (done)
+       break;
+
+      /* Add the token to the token block.  */
+      token = cp_lexer_consume_token (parser->lexer);
+    }
+
+  /* Create a DEFAULT_ARG to represent the unparsed default
+     argument.  */
+  default_argument = make_node (DEFAULT_ARG);
+  DEFARG_TOKENS (default_argument)
+    = cp_token_cache_new (first_token, token);
+  DEFARG_INSTANTIATIONS (default_argument) = NULL;
+
+  return default_argument;
+}
+
 /* Begin parsing tentatively.  We always save tokens while parsing
    tentatively so that if the tentative parsing fails we can restore the
    tokens.  */
@@ -22439,7 +23691,8 @@ cp_parser_objc_interstitial_code (cp_parser* parser)
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+        (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
@@ -25186,11 +26439,11 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
        {
          /* If decl is an iterator, preserve the operator on decl
             until finish_omp_for.  */
-         if (decl
-             && ((type_dependent_expression_p (decl)
-                  && !POINTER_TYPE_P (TREE_TYPE (decl)))
-                 || CLASS_TYPE_P (TREE_TYPE (decl))))
-           incr = cp_parser_omp_for_incr (parser, decl);
+         if (real_decl
+             && ((processing_template_decl
+                  && !POINTER_TYPE_P (TREE_TYPE (real_decl)))
+                 || CLASS_TYPE_P (TREE_TYPE (real_decl))))
+           incr = cp_parser_omp_for_incr (parser, real_decl);
          else
            incr = cp_parser_expression (parser, false, NULL);
        }
@@ -25669,6 +26922,291 @@ cp_parser_omp_construct (cp_parser *parser, cp_token *pragma_tok)
     SET_EXPR_LOCATION (stmt, pragma_tok->location);
 }
 \f
+/* Transactional Memory parsing routines.  */
+
+/* Parse a transaction attribute.
+
+   txn-attribute:
+       attribute
+       [ [ identifier ] ]
+
+   ??? Simplify this when C++0x bracket attributes are
+   implemented properly.  */
+
+static tree
+cp_parser_txn_attribute_opt (cp_parser *parser)
+{
+  cp_token *token;
+  tree attr_name, attr = NULL;
+
+  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_ATTRIBUTE))
+    return cp_parser_attributes_opt (parser);
+
+  if (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_SQUARE))
+    return NULL_TREE;
+  cp_lexer_consume_token (parser->lexer);
+  if (!cp_parser_require (parser, CPP_OPEN_SQUARE, RT_OPEN_SQUARE))
+    goto error1;
+
+  token = cp_lexer_peek_token (parser->lexer);
+  if (token->type == CPP_NAME || token->type == CPP_KEYWORD)
+    {
+      token = cp_lexer_consume_token (parser->lexer);
+
+      attr_name = (token->type == CPP_KEYWORD
+                  /* For keywords, use the canonical spelling,
+                     not the parsed identifier.  */
+                  ? ridpointers[(int) token->keyword]
+                  : token->u.value);
+      attr = build_tree_list (attr_name, NULL_TREE);
+    }
+  else
+    cp_parser_error (parser, "expected identifier");
+
+  cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
+ error1:
+  cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
+  return attr;
+}
+
+/* Parse a __transaction_atomic or __transaction_relaxed statement.
+
+   transaction-statement:
+     __transaction_atomic txn-attribute[opt] txn-noexcept-spec[opt]
+       compound-statement
+     __transaction_relaxed txn-noexcept-spec[opt] compound-statement
+*/
+
+static tree
+cp_parser_transaction (cp_parser *parser, enum rid keyword)
+{
+  unsigned char old_in = parser->in_transaction;
+  unsigned char this_in = 1, new_in;
+  cp_token *token;
+  tree stmt, attrs, noex;
+
+  gcc_assert (keyword == RID_TRANSACTION_ATOMIC
+      || keyword == RID_TRANSACTION_RELAXED);
+  token = cp_parser_require_keyword (parser, keyword,
+      (keyword == RID_TRANSACTION_ATOMIC ? RT_TRANSACTION_ATOMIC
+         : RT_TRANSACTION_RELAXED));
+  gcc_assert (token != NULL);
+
+  if (keyword == RID_TRANSACTION_RELAXED)
+    this_in |= TM_STMT_ATTR_RELAXED;
+  else
+    {
+      attrs = cp_parser_txn_attribute_opt (parser);
+      if (attrs)
+       this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
+    }
+
+  /* Parse a noexcept specification.  */
+  noex = cp_parser_noexcept_specification_opt (parser, true, NULL, true);
+
+  /* Keep track if we're in the lexical scope of an outer transaction.  */
+  new_in = this_in | (old_in & TM_STMT_ATTR_OUTER);
+
+  stmt = begin_transaction_stmt (token->location, NULL, this_in);
+
+  parser->in_transaction = new_in;
+  cp_parser_compound_statement (parser, NULL, false, false);
+  parser->in_transaction = old_in;
+
+  finish_transaction_stmt (stmt, NULL, this_in, noex);
+
+  return stmt;
+}
+
+/* Parse a __transaction_atomic or __transaction_relaxed expression.
+
+   transaction-expression:
+     __transaction_atomic txn-noexcept-spec[opt] ( expression )
+     __transaction_relaxed txn-noexcept-spec[opt] ( expression )
+*/
+
+static tree
+cp_parser_transaction_expression (cp_parser *parser, enum rid keyword)
+{
+  unsigned char old_in = parser->in_transaction;
+  unsigned char this_in = 1;
+  cp_token *token;
+  tree expr, noex;
+  bool noex_expr;
+
+  gcc_assert (keyword == RID_TRANSACTION_ATOMIC
+      || keyword == RID_TRANSACTION_RELAXED);
+
+  if (!flag_tm)
+    error (keyword == RID_TRANSACTION_RELAXED
+          ? G_("%<__transaction_relaxed%> without transactional memory "
+               "support enabled")
+          : G_("%<__transaction_atomic%> without transactional memory "
+               "support enabled"));
+
+  token = cp_parser_require_keyword (parser, keyword,
+      (keyword == RID_TRANSACTION_ATOMIC ? RT_TRANSACTION_ATOMIC
+         : RT_TRANSACTION_RELAXED));
+  gcc_assert (token != NULL);
+
+  if (keyword == RID_TRANSACTION_RELAXED)
+    this_in |= TM_STMT_ATTR_RELAXED;
+
+  /* Set this early.  This might mean that we allow transaction_cancel in
+     an expression that we find out later actually has to be a constexpr.
+     However, we expect that cxx_constant_value will be able to deal with
+     this; also, if the noexcept has no constexpr, then what we parse next
+     really is a transaction's body.  */
+  parser->in_transaction = this_in;
+
+  /* Parse a noexcept specification.  */
+  noex = cp_parser_noexcept_specification_opt (parser, false, &noex_expr,
+                                              true);
+
+  if (!noex || !noex_expr
+      || cp_lexer_peek_token (parser->lexer)->type == CPP_OPEN_PAREN)
+    {
+      cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+
+      expr = cp_parser_expression (parser, /*cast_p=*/false, NULL);
+      finish_parenthesized_expr (expr);
+
+      cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+    }
+  else
+    {
+      /* The only expression that is available got parsed for the noexcept
+         already.  noexcept is true then.  */
+      expr = noex;
+      noex = boolean_true_node;
+    }
+
+  expr = build_transaction_expr (token->location, expr, this_in, noex);
+  parser->in_transaction = old_in;
+
+  if (cp_parser_non_integral_constant_expression (parser, NIC_TRANSACTION))
+    return error_mark_node;
+
+  return (flag_tm ? expr : error_mark_node);
+}
+
+/* Parse a function-transaction-block.
+
+   function-transaction-block:
+     __transaction_atomic txn-attribute[opt] ctor-initializer[opt]
+        function-body
+     __transaction_atomic txn-attribute[opt] function-try-block
+     __transaction_relaxed ctor-initializer[opt] function-body
+     __transaction_relaxed function-try-block
+*/
+
+static bool
+cp_parser_function_transaction (cp_parser *parser, enum rid keyword)
+{
+  unsigned char old_in = parser->in_transaction;
+  unsigned char new_in = 1;
+  tree compound_stmt, stmt, attrs;
+  bool ctor_initializer_p;
+  cp_token *token;
+
+  gcc_assert (keyword == RID_TRANSACTION_ATOMIC
+      || keyword == RID_TRANSACTION_RELAXED);
+  token = cp_parser_require_keyword (parser, keyword,
+      (keyword == RID_TRANSACTION_ATOMIC ? RT_TRANSACTION_ATOMIC
+         : RT_TRANSACTION_RELAXED));
+  gcc_assert (token != NULL);
+
+  if (keyword == RID_TRANSACTION_RELAXED)
+    new_in |= TM_STMT_ATTR_RELAXED;
+  else
+    {
+      attrs = cp_parser_txn_attribute_opt (parser);
+      if (attrs)
+       new_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER);
+    }
+
+  stmt = begin_transaction_stmt (token->location, &compound_stmt, new_in);
+
+  parser->in_transaction = new_in;
+
+  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
+    ctor_initializer_p = cp_parser_function_try_block (parser);
+  else
+    ctor_initializer_p
+      = cp_parser_ctor_initializer_opt_and_function_body (parser);
+
+  parser->in_transaction = old_in;
+
+  finish_transaction_stmt (stmt, compound_stmt, new_in, NULL_TREE);
+
+  return ctor_initializer_p;
+}
+
+/* Parse a __transaction_cancel statement.
+
+   cancel-statement:
+     __transaction_cancel txn-attribute[opt] ;
+     __transaction_cancel txn-attribute[opt] throw-expression ;
+
+   ??? Cancel and throw is not yet implemented.  */
+
+static tree
+cp_parser_transaction_cancel (cp_parser *parser)
+{
+  cp_token *token;
+  bool is_outer = false;
+  tree stmt, attrs;
+
+  token = cp_parser_require_keyword (parser, RID_TRANSACTION_CANCEL,
+                                    RT_TRANSACTION_CANCEL);
+  gcc_assert (token != NULL);
+
+  attrs = cp_parser_txn_attribute_opt (parser);
+  if (attrs)
+    is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0);
+
+  /* ??? Parse cancel-and-throw here.  */
+
+  cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
+
+  if (!flag_tm)
+    {
+      error_at (token->location, "%<__transaction_cancel%> without "
+               "transactional memory support enabled");
+      return error_mark_node;
+    }
+  else if (parser->in_transaction & TM_STMT_ATTR_RELAXED)
+    {
+      error_at (token->location, "%<__transaction_cancel%> within a "
+               "%<__transaction_relaxed%>");
+      return error_mark_node;
+    }
+  else if (is_outer)
+    {
+      if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0
+         && !is_tm_may_cancel_outer (current_function_decl))
+       {
+         error_at (token->location, "outer %<__transaction_cancel%> not "
+                   "within outer %<__transaction_atomic%>");
+         error_at (token->location,
+                   "  or a %<transaction_may_cancel_outer%> function");
+         return error_mark_node;
+       }
+    }
+  else if (parser->in_transaction == 0)
+    {
+      error_at (token->location, "%<__transaction_cancel%> not within "
+               "%<__transaction_atomic%>");
+      return error_mark_node;
+    }
+
+  stmt = build_tm_abort_call (token->location, is_outer);
+  add_stmt (stmt);
+  finish_stmt ();
+
+  return stmt;
+}
+\f
 /* The parser.  */
 
 static GTY (()) cp_parser *the_parser;