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]

Re: [C/C++] Do not pretty-print expressions with caret diagnostics for wrong function call


On Sat, Apr 21, 2012 at 04:06:17PM +0200, Manuel López-Ibáñez wrote:
> This patch avoids pretty-printing expressions when the caret is
> enabled for the error given when calling as a function something that
> is not a function.
> 
> This fixes (when caret is enabled) the bugs described in PR35441 and
> also shown here http://clang.llvm.org/diagnostics.html (No Pretty
> Printing of Expressions in Diagnostics).
> 
> Bootstrapped/regression tested.
> 
> OK?
> 
> 2012-04-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>
> 
> 	PR 35441

This should be PR c/35441

> 	* c-typeck.c (inform_declaration): New.
> 	(build_function_call_vec):  Do not pretty-print
> 	expressions when caret is enabled.
> 	(convert_arguments): Use inform_declaration.
> 	* cp/typeck.c (cp_build_function_call_vec): Do not pretty-print
> 	expressions when caret is enabled.
> 	* testsuite/c-c++-common/pr35441.C: New.

+         if (!flag_diagnostics_show_caret)                                                                                                        
+           error_at (input_location,                                                                                                              
+                     "%qE cannot be used as a function", original);                                                                               
+         else if (DECL_P (original))                                                                                                              
+           error_at (input_location,                                                                                                              
+                     "%qD cannot be used as a function", original);                                                                               
+         else                                                                                                                                     
+           error_at (input_location,                                                                                                              
+                     "expression cannot be used as a function");                                                                                  

Before we start to add many similar tests, I wonder if we shouldn't
test not just that caret diagnostics is on, but that it will be actually
printed for the specific locus.  The source could come up from
stdin, or the file no longer available, etc.  So, shouldn't
this be guarded instead on some predicate that takes locus_t as an
argument (input_location in this case), say can_emit_caret_diagnostics_p,
which would return false right away for !flag_diagnostics_show_caret,
otherwise would try to grab the source line (and cache it) and return true
only if it succeeded?  Then error_at after it if returned true would just
use the cached line, so it wouldn't read things twice.

There have been requests to (at least optionally) limit caret diagnostics
to certain number of carets and then stop emitting them if there are too
many, because with caret the output is most often 3 times as long, such
predicate could take that into account too if it is added.

	Jakub


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