diff mbox

[C++] PR 53158

Message ID 4FAA6138.30201@oracle.com
State New
Headers show

Commit Message

Paolo Carlini May 9, 2012, 12:21 p.m. UTC
Hi again,

On 05/08/2012 03:00 PM, Jason Merrill wrote:
> On 05/07/2012 11:28 PM, Paolo Carlini wrote:
>> error: could not convert ‘b.main()::<lambda()>()’ from ‘void’ to ‘bool’
>
> It wouldn't say "operator()"?
>
> I think I'd leave that alone; it is somewhat more informative (about 
> what b() expands to) and we're moving toward replacing %qE with caret 
> anyway.
>
> The patch to ocp_convert is OK.
As you may have noticed, the patchlet is still unapplied (I'm attaching 
below what I have tested and ready to get in per your approval).

Is unapplied because I was really nervous due to the wrong location 
(thus caret) of the error call, at the end of the whole condition. Now, 
I'm wondering, shall we consistently use error_at (location_of (expr), 
... for the error messages produced by the *convert* functions? The 
below quick fix makes me *much* more happy, the caret points to the 
closed round brace of the b() call. Can I trust all the exprs to come 
with an embedded location *at least* as accurate as input_location, 
normally better? In case I can do a pass through all of cvt.c etc and 
repost a largish patch...

Thanks!

Paolo.

////////////////

Index: cvt.c
===================================================================
--- cvt.c	(revision 187290)
+++ cvt.c	(working copy)
@@ -743,6 +743,14 @@ ocp_convert (tree type, tree expr, int convtype, i
 	}
       if (code == BOOLEAN_TYPE)
 	{
+	  if (TREE_CODE (intype) == VOID_TYPE)
+	    {
+	      error_at (location_of (expr),
+			"could not convert %qE from %<void%> to %<bool%>",
+			expr);
+	      return error_mark_node;
+	    }
+
 	  /* We can't implicitly convert a scoped enum to bool, so convert
 	     to the underlying type first.  */
 	  if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))

Comments

Jason Merrill May 9, 2012, 12:59 p.m. UTC | #1
On 05/09/2012 08:21 AM, Paolo Carlini wrote:
> Is unapplied because I was really nervous due to the wrong location
> (thus caret) of the error call, at the end of the whole condition. Now,
> I'm wondering, shall we consistently use error_at (location_of (expr),
> ... for the error messages produced by the *convert* functions?

Sure.  Note that as an alternative to error_at (location_of (expr) you 
can just use %q+E; the + means "use the location of this argument".

> The
> below quick fix makes me *much* more happy, the caret points to the
> closed round brace of the b() call. Can I trust all the exprs to come
> with an embedded location *at least* as accurate as input_location,
> normally better?

I would think so, yes.  If an expression doesn't have a location, 
location_of/%q+E will just use input_location.

Jason
Manuel López-Ibáñez May 9, 2012, 1:04 p.m. UTC | #2
On 9 May 2012 14:59, Jason Merrill <jason@redhat.com> wrote:
> On 05/09/2012 08:21 AM, Paolo Carlini wrote:
>>
>> Is unapplied because I was really nervous due to the wrong location
>> (thus caret) of the error call, at the end of the whole condition. Now,
>> I'm wondering, shall we consistently use error_at (location_of (expr),
>> ... for the error messages produced by the *convert* functions?
>
>
> Sure.  Note that as an alternative to error_at (location_of (expr) you can
> just use %q+E; the + means "use the location of this argument".

This far less clear than error_at(location, "whatever"). And it
requires the diagnostics machinery to know about input_location. I
removed %H precisely for those reasons. Please, let's stop using "+"
in diagnostics and always use explicit locations.

Cheers,

Manuel.
Jason Merrill May 9, 2012, 1:21 p.m. UTC | #3
On 05/09/2012 09:04 AM, Manuel López-Ibáñez wrote:
> This far less clear than error_at(location, "whatever"). And it
> requires the diagnostics machinery to know about input_location. I
> removed %H precisely for those reasons. Please, let's stop using "+"
> in diagnostics and always use explicit locations.

OK.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/cpp0x/lambda/lambda-err2.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-err2.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-err2.C	(revision 0)
@@ -0,0 +1,12 @@ 
+// PR c++/53158
+// { dg-do compile { target c++11 } }
+
+int main()
+{
+  auto a = []() { return true; };
+  auto b = []() { return a(); };  // { dg-error "'a' is not captured" }
+  int c, d;
+  while (b() && c < d) // { dg-error "could not convert" }
+    {
+    }
+}
Index: cp/cvt.c
===================================================================
--- cp/cvt.c	(revision 187280)
+++ cp/cvt.c	(working copy)
@@ -743,6 +743,12 @@  ocp_convert (tree type, tree expr, int convtype, i
 	}
       if (code == BOOLEAN_TYPE)
 	{
+	  if (TREE_CODE (intype) == VOID_TYPE)
+	    {
+	      error ("could not convert %qE from %<void%> to %<bool%>", expr);
+	      return error_mark_node;
+	    }
+
 	  /* We can't implicitly convert a scoped enum to bool, so convert
 	     to the underlying type first.  */
 	  if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))