Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 186103) +++ gcc/doc/invoke.texi (working copy) @@ -2863,15 +2863,14 @@ honor these options. However it is expe the remaining front ends would be able to digest them correctly. @table @gcctabopt @item -fmessage-length=@var{n} @opindex fmessage-length -Try to format error messages so that they fit on lines of about @var{n} -characters. The default is 72 characters for @command{g++} and 0 for the rest of -the front ends supported by GCC@. If @var{n} is zero, then no -line-wrapping will be done; each error message will appear on a single -line. +Try to format error messages so that they fit on lines of about +@var{n} characters. If @var{n} is zero, then no line-wrapping will be +done; each error message will appear on a single line. This is the +default for all front ends. @opindex fdiagnostics-show-location @item -fdiagnostics-show-location=once Only meaningful in line-wrapping mode. Instructs the diagnostic messages reporter to emit @emph{once} source location information; that is, in Index: gcc/c-family/c-opts.c =================================================================== --- gcc/c-family/c-opts.c (revision 186103) +++ gcc/c-family/c-opts.c (working copy) @@ -157,27 +157,16 @@ c_common_option_lang_mask (void) static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX}; return lang_flags[c_language]; } -/* Common diagnostics initialization. */ +/* Default settings of diagnostics for C-family. */ void -c_common_initialize_diagnostics (diagnostic_context *context) +c_common_diagnostics_defaults (diagnostic_context *context) { - /* This is conditionalized only because that is the way the front - ends used to do it. Maybe this should be unconditional? */ - if (c_dialect_cxx ()) - { - /* By default wrap lines at 80 characters. Is getenv - ("COLUMNS") preferable? */ - diagnostic_line_cutoff (context) = 80; - /* By default, emit location information once for every - diagnostic message. */ - diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE; - } - context->opt_permissive = OPT_fpermissive; + pp_set_line_maximum_length (context->printer, 0); } /* Whether options from all C-family languages should be accepted quietly. */ static bool accept_all_c_family_options = false; Index: gcc/c-family/c-common.h =================================================================== --- gcc/c-family/c-common.h (revision 186103) +++ gcc/c-family/c-common.h (working copy) @@ -814,11 +814,11 @@ extern void set_compound_literal_name (t extern tree build_va_arg (location_t, tree, tree); extern const unsigned int c_family_lang_mask; extern unsigned int c_common_option_lang_mask (void); -extern void c_common_initialize_diagnostics (diagnostic_context *); +extern void c_common_diagnostics_defaults (diagnostic_context *); extern bool c_common_complain_wrong_lang_p (const struct cl_option *); extern void c_common_init_options_struct (struct gcc_options *); extern void c_common_init_options (unsigned int, struct cl_decoded_option *); extern bool c_common_post_options (const char **); extern bool c_common_init (void); Index: gcc/pretty-print.h =================================================================== --- gcc/pretty-print.h (revision 186103) +++ gcc/pretty-print.h (working copy) @@ -350,6 +350,21 @@ pp_set_verbatim_wrapping_ (pretty_printe extern const char *identifier_to_locale (const char *); extern void *(*identifier_to_locale_alloc) (size_t); extern void (*identifier_to_locale_free) (void *); +/* Return the value of the getenv("COLUMNS") as an integer. If the + value is not set to a positive integer, then return 0. */ +static inline int +getenv_columns (void) +{ + const char * s = getenv ("COLUMNS"); + if (s != NULL) { + int n = atoi (s); + if (n > 0) + return n; + } + return 0; +} + + #endif /* GCC_PRETTY_PRINT_H */ Index: gcc/cp/error.c =================================================================== --- gcc/cp/error.c (revision 186103) +++ gcc/cp/error.c (working copy) @@ -100,17 +100,37 @@ static void cp_diagnostic_finalizer (dia static void cp_print_error_function (diagnostic_context *, diagnostic_info *); static bool cp_printer (pretty_printer *, text_info *, const char *, int, bool, bool, bool); +/* Construct a C++-aware pretty-printer for CONTEXT. It is assumed + that CONTEXT->printer is an already constructed basic pretty_printer. */ void -init_error (void) +cxx_initialize_diagnostics (diagnostic_context *context) { - diagnostic_starter (global_dc) = cp_diagnostic_starter; - diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer; - diagnostic_format_decoder (global_dc) = cp_printer; + pretty_printer *base; + cxx_pretty_printer *pp; + c_common_diagnostics_defaults (context); + + base = context->printer; + pp = XNEW (cxx_pretty_printer); + memcpy (pp_base (pp), base, sizeof (pretty_printer)); + /* It is safe to free this object because it was previously malloc()'d. */ + free (base); + pp_cxx_pretty_printer_init (pp); + context->printer = (pretty_printer *) pp; + + diagnostic_starter (context) = cp_diagnostic_starter; + diagnostic_finalizer (context) = cp_diagnostic_finalizer; + diagnostic_format_decoder (context) = cp_printer; + + /* cxx_pp is the C++ front-end-specific global pretty printer: this + is where we dump C++ ASTs as strings. It is mostly used only by + the various tree -> string functions that are occasionally + called from the debugger or by the front-end for things like + __PRETTY_FUNCTION__. It is NOT for diagnostic purposes. */ pp_construct (pp_base (cxx_pp), NULL, 0); pp_cxx_pretty_printer_init (cxx_pp); } /* Dump a scope, if deemed necessary. */ Index: gcc/cp/cxx-pretty-print.c =================================================================== --- gcc/cp/cxx-pretty-print.c (revision 186103) +++ gcc/cp/cxx-pretty-print.c (working copy) @@ -2424,12 +2424,10 @@ typedef c_pretty_print_fn pp_fun; void pp_cxx_pretty_printer_init (cxx_pretty_printer *pp) { pp_c_pretty_printer_init (pp_c_base (pp)); - pp_set_line_maximum_length (pp, 0); - pp->c_base.declaration = (pp_fun) pp_cxx_declaration; pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq; pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier; pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq; pp->c_base.declarator = (pp_fun) pp_cxx_declarator; Index: gcc/cp/cp-objcp-common.c =================================================================== --- gcc/cp/cp-objcp-common.c (revision 186103) +++ gcc/cp/cp-objcp-common.c (working copy) @@ -125,30 +125,10 @@ cp_var_mod_type_p (tree type, tree fn) /* All other types are not variably modified. */ return false; } -/* Construct a C++-aware pretty-printer for CONTEXT. It is assumed - that CONTEXT->printer is an already constructed basic pretty_printer. */ -void -cxx_initialize_diagnostics (diagnostic_context *context) -{ - pretty_printer *base; - cxx_pretty_printer *pp; - - c_common_initialize_diagnostics (context); - - base = context->printer; - pp = XNEW (cxx_pretty_printer); - memcpy (pp_base (pp), base, sizeof (pretty_printer)); - pp_cxx_pretty_printer_init (pp); - context->printer = (pretty_printer *) pp; - - /* It is safe to free this object because it was previously malloc()'d. */ - free (base); -} - /* This compares two types for equivalence ("compatible" in C-based languages). This routine should only return 1 if it is sure. It should not be used in contexts where erroneously returning 0 causes problems. */ int Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 186103) +++ gcc/cp/cp-tree.h (working copy) @@ -5143,11 +5143,10 @@ extern void note_vague_linkage_fn (tree extern tree build_artificial_parm (tree, tree); extern bool possibly_inlined_p (tree); extern int parm_index (tree); /* in error.c */ -extern void init_error (void); extern const char *type_as_string (tree, int); extern const char *type_as_string_translate (tree, int); extern const char *decl_as_string (tree, int); extern const char *decl_as_string_translate (tree, int); extern const char *expr_as_string (tree, int); Index: gcc/cp/lex.c =================================================================== --- gcc/cp/lex.c (revision 186103) +++ gcc/cp/lex.c (working copy) @@ -241,11 +241,10 @@ cxx_init (void) init_reswords (); init_tree (); init_cp_semantics (); init_operators (); init_method (); - init_error (); current_function_decl = NULL; class_type_node = ridpointers[(int) RID_CLASS]; Index: gcc/c-objc-common.c =================================================================== --- gcc/c-objc-common.c (revision 186103) +++ gcc/c-objc-common.c (working copy) @@ -58,20 +58,11 @@ c_warn_unused_global_decl (const_tree de /* Initialization common to C and Objective-C front ends. */ bool c_objc_common_init (void) { c_init_decl_processing (); - - if (c_common_init () == false) - return false; - - /* These were not defined in the Objective-C front end, but I'm - putting them here anyway. The diagnostic format decoder might - want an enhanced ObjC implementation. */ - diagnostic_format_decoder (global_dc) = &c_tree_printer; - - return true; + return c_common_init (); } /* Called during diagnostic message formatting process to print a source-level entity onto BUFFER. The meaning of the format specifiers is as follows: @@ -185,20 +176,24 @@ void c_initialize_diagnostics (diagnostic_context *context) { pretty_printer *base; c_pretty_printer *pp; - c_common_initialize_diagnostics (context); + c_common_diagnostics_defaults (context); base = context->printer; pp = XNEW (c_pretty_printer); memcpy (pp_base (pp), base, sizeof (pretty_printer)); + /* It is safe to free this object because it was previously XNEW()'d. */ + XDELETE (base); pp_c_pretty_printer_init (pp); context->printer = (pretty_printer *) pp; - /* It is safe to free this object because it was previously XNEW()'d. */ - XDELETE (base); + /* These were not defined in the Objective-C front end, but I'm + putting them here anyway. The diagnostic format decoder might + want an enhanced ObjC implementation. */ + diagnostic_format_decoder (context) = &c_tree_printer; } int c_types_compatible_p (tree x, tree y) {