This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR c++/21686: Broken quotation in error message


On mainline and the 4.0 branch we get the error message

  PR21686.cc: In constructor 'foo()::A::A()':
  PR21686.cc:4: error: use of %<auto%> variable from containing function
  PR21686.cc:3: error:   'int i' declared here

for the code snippet

  void foo()
  {
      int i;
      struct A { A() { i; } };
  }

Note the broken quotation of "auto". This is due to the following code
in cp/semantics.c:

  error ("use of %s from containing function",
	 (TREE_CODE (decl) == VAR_DECL
	  ? "%<auto%> variable" : "parameter"));

The quotation with %< %> just doesn't work in strings substituted by %s.
The attached patch fixes the quotation by not using substitution.
The error message then reads as expected:

  PR21686.cc: In constructor 'foo()::A::A()':
  PR21686.cc:4: error: use of 'auto' variable from containing function
  PR21686.cc:3: error:   'int i' declared here

Bootstrapped and regtested on i686-pc-linux-gnu.
OK for 4.0 branch and mainline?
Should I wait for the unslushing of mainline, although this is a regression?

Regards,
Volker


2005-05-23  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/21686
	* semantics.c (finish_id_expression): Fix quoting in error message.

==============================================================================
--- gcc/gcc/cp/semantics.c	2005-05-23 00:36:50.000000000 +0200
+++ gcc/gcc/cp/semantics.c	2005-05-23 00:29:39.000000000 +0200
@@ -2749,9 +2749,9 @@ finish_id_expression (tree id_expression
 	      if (context != NULL_TREE && context != current_function_decl
 		  && ! TREE_STATIC (decl))
 		{
-		  error ("use of %s from containing function",
-			 (TREE_CODE (decl) == VAR_DECL
-			  ? "%<auto%> variable" : "parameter"));
+		  error (TREE_CODE (decl) == VAR_DECL
+			 ? "use of %<auto%> variable from containing function"
+			 : "use of parameter from containing function");
 		  cp_error_at ("  %q#D declared here", decl);
 		  return error_mark_node;
 		}
==============================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]